mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
* added new utility, findBinaryInPath which searches the PATH for a specific binary
* removed getSpellBinary, and replaced with findBinaryInPath calls
This commit is contained in:
parent
352207b82a
commit
83c44eecab
@ -52,10 +52,13 @@ import popen2
|
|||||||
|
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
|
import utils
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
def configure(onStart, afterConnect, advanced):
|
||||||
from questions import expect, anything, something, yn
|
from questions import expect, anything, something, yn
|
||||||
cmdLine = getSpellBinary()
|
cmdLine = utils.findBinaryInPath('aspell')
|
||||||
|
if not cmdLine:
|
||||||
|
cmdLine = utils.findBinaryInPath('ispell')
|
||||||
if not cmdLine:
|
if not cmdLine:
|
||||||
print 'NOTE: I couldn\'t find aspell or ispell in your path,'
|
print 'NOTE: I couldn\'t find aspell or ispell in your path,'
|
||||||
print 'so that function of this module will not work. You may'
|
print 'so that function of this module will not work. You may'
|
||||||
@ -72,18 +75,6 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
if yn('Would you like to disable this command?') == 'y':
|
if yn('Would you like to disable this command?') == 'y':
|
||||||
onStart.append('disable progstats')
|
onStart.append('disable progstats')
|
||||||
|
|
||||||
def getSpellBinary():
|
|
||||||
cmdLine = None
|
|
||||||
for dir in os.getenv('PATH').split(':'):
|
|
||||||
for command in ('aspell', 'ispell'):
|
|
||||||
filename = os.path.join(dir, command)
|
|
||||||
if os.path.exists(filename):
|
|
||||||
cmdLine = filename
|
|
||||||
break
|
|
||||||
if cmdLine:
|
|
||||||
break
|
|
||||||
return cmdLine
|
|
||||||
|
|
||||||
def progstats():
|
def progstats():
|
||||||
pw = pwd.getpwuid(os.getuid())
|
pw = pwd.getpwuid(os.getuid())
|
||||||
response = 'Process ID %i running as user "%s" and as group "%s" '\
|
response = 'Process ID %i running as user "%s" and as group "%s" '\
|
||||||
@ -99,7 +90,9 @@ class Unix(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
# Initialize a file descriptor for the spell module.
|
# Initialize a file descriptor for the spell module.
|
||||||
cmdLine = getSpellBinary()
|
cmdLine = utils.findBinaryInPath('aspell')
|
||||||
|
if not cmdLine:
|
||||||
|
cmdLine = utils.findBinaryInPath('ispell')
|
||||||
(self._spellRead, self._spellWrite) = popen2.popen4(cmdLine + ' -a', 0)
|
(self._spellRead, self._spellWrite) = popen2.popen4(cmdLine + ' -a', 0)
|
||||||
# Ignore the banner
|
# Ignore the banner
|
||||||
self._spellRead.readline()
|
self._spellRead.readline()
|
||||||
@ -166,7 +159,8 @@ class Unix(callbacks.Privmsg):
|
|||||||
irc.error(msg, 'Aspell/ispell can\'t handle spaces in words.')
|
irc.error(msg, 'Aspell/ispell can\'t handle spaces in words.')
|
||||||
return
|
return
|
||||||
self._spellWrite.write(word)
|
self._spellWrite.write(word)
|
||||||
self._spellWrite.write('\n') line = self._spellRead.readline()
|
self._spellWrite.write('\n')
|
||||||
|
line = self._spellRead.readline()
|
||||||
# aspell puts extra whitespace, ignore it
|
# aspell puts extra whitespace, ignore it
|
||||||
while line == '\n':
|
while line == '\n':
|
||||||
line = self._spellRead.readline()
|
line = self._spellRead.readline()
|
||||||
|
11
src/utils.py
11
src/utils.py
@ -37,6 +37,7 @@ Simple utility functions.
|
|||||||
|
|
||||||
from fix import *
|
from fix import *
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import sgmllib
|
import sgmllib
|
||||||
@ -248,4 +249,14 @@ def perlReToReplacer(s):
|
|||||||
else:
|
else:
|
||||||
return lambda s: r.sub(replace, s, 1)
|
return lambda s: r.sub(replace, s, 1)
|
||||||
|
|
||||||
|
def findBinaryInPath(s):
|
||||||
|
"""Returns full path of a binary if it's in PATH, otherwise returns None."""
|
||||||
|
cmdLine = None
|
||||||
|
for dir in os.getenv('PATH').split(':'):
|
||||||
|
filename = os.path.join(dir, s)
|
||||||
|
if os.path.exists(filename):
|
||||||
|
cmdLine = filename
|
||||||
|
break
|
||||||
|
return cmdLine
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user