mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Add commands Unix.sysuptime and Unix.sysuname.
This commit is contained in:
parent
cf073bbd73
commit
7de277d052
@ -95,4 +95,14 @@ conf.registerGlobalValue(Unix.ping, 'command',
|
|||||||
registry.String(utils.findBinaryInPath('ping') or '', """Determines what
|
registry.String(utils.findBinaryInPath('ping') or '', """Determines what
|
||||||
command will be called for the ping command."""))
|
command will be called for the ping command."""))
|
||||||
|
|
||||||
|
conf.registerGroup(Unix, 'sysuptime')
|
||||||
|
conf.registerGlobalValue(Unix.sysuptime, 'command',
|
||||||
|
registry.String(utils.findBinaryInPath('uptime') or '', """Determines what
|
||||||
|
command will be called for the uptime command."""))
|
||||||
|
|
||||||
|
conf.registerGroup(Unix, 'sysuname')
|
||||||
|
conf.registerGlobalValue(Unix.sysuname, 'command',
|
||||||
|
registry.String(utils.findBinaryInPath('uname') or '', """Determines what
|
||||||
|
command will be called for the uname command."""))
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -313,6 +313,62 @@ class Unix(callbacks.Plugin):
|
|||||||
't':'positiveInt','W':'positiveInt'}),
|
't':'positiveInt','W':'positiveInt'}),
|
||||||
first('ip', ('matches', _hostExpr, 'Invalid hostname'))]))
|
first('ip', ('matches', _hostExpr, 'Invalid hostname'))]))
|
||||||
|
|
||||||
|
def sysuptime(self, irc, msg, args):
|
||||||
|
"""takes no arguments
|
||||||
|
|
||||||
|
Returns the uptime from the system the bot is runnning on.
|
||||||
|
"""
|
||||||
|
uptimeCmd = self.registryValue('sysuptime.command')
|
||||||
|
if uptimeCmd:
|
||||||
|
args = [uptimeCmd]
|
||||||
|
try:
|
||||||
|
inst = subprocess.Popen(args, close_fds=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
stdin=file(os.devnull))
|
||||||
|
except OSError, e:
|
||||||
|
irc.error('It seems the configured uptime command was '
|
||||||
|
'not available.', Raise=True)
|
||||||
|
(out, err) = inst.communicate()
|
||||||
|
inst.wait()
|
||||||
|
lines = out.splitlines()
|
||||||
|
lines = map(str.rstrip, lines)
|
||||||
|
lines = filter(None, lines)
|
||||||
|
irc.replies(lines, joiner=' ')
|
||||||
|
else:
|
||||||
|
irc.error('The uptime command is not configured. If uptime is '
|
||||||
|
'installed on this system, reconfigure the '
|
||||||
|
'supybot.plugins.Unix.sysuptime.command configuration '
|
||||||
|
'variable appropriately.')
|
||||||
|
|
||||||
|
def sysuname(self, irc, msg, args):
|
||||||
|
"""takes no arguments
|
||||||
|
|
||||||
|
Returns the uname -a from the system the bot is runnning on.
|
||||||
|
"""
|
||||||
|
unameCmd = self.registryValue('sysuname.command')
|
||||||
|
if unameCmd:
|
||||||
|
args = [unameCmd, '-a']
|
||||||
|
try:
|
||||||
|
inst = subprocess.Popen(args, close_fds=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
stdin=file(os.devnull))
|
||||||
|
except OSError, e:
|
||||||
|
irc.error('It seems the configured uptime command was '
|
||||||
|
'not available.', Raise=True)
|
||||||
|
(out, err) = inst.communicate()
|
||||||
|
inst.wait()
|
||||||
|
lines = out.splitlines()
|
||||||
|
lines = map(str.rstrip, lines)
|
||||||
|
lines = filter(None, lines)
|
||||||
|
irc.replies(lines, joiner=' ')
|
||||||
|
else:
|
||||||
|
irc.error('The uname command is not configured. If uname is '
|
||||||
|
'installed on this system, reconfigure the '
|
||||||
|
'supybot.plugins.Unix.sysuname.command configuration '
|
||||||
|
'variable appropriately.')
|
||||||
|
|
||||||
def call(self, irc, msg, args, text):
|
def call(self, irc, msg, args, text):
|
||||||
"""<command to call with any arguments>
|
"""<command to call with any arguments>
|
||||||
Calls any command available on the system, and returns its output.
|
Calls any command available on the system, and returns its output.
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"""stick the various versioning attributes in here, so we only have to change
|
"""stick the various versioning attributes in here, so we only have to change
|
||||||
them once."""
|
them once."""
|
||||||
version = '0.83.4.1+limnoria (2012-04-04T13:55:42+0000)'
|
version = '0.83.4.1+limnoria (2012-04-15T12:02:39+0000)'
|
||||||
|
Loading…
Reference in New Issue
Block a user