diff --git a/plugins/Unix/config.py b/plugins/Unix/config.py index 2b618327c..d08dcdf8e 100644 --- a/plugins/Unix/config.py +++ b/plugins/Unix/config.py @@ -95,4 +95,14 @@ conf.registerGlobalValue(Unix.ping, 'command', registry.String(utils.findBinaryInPath('ping') or '', """Determines what 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: diff --git a/plugins/Unix/plugin.py b/plugins/Unix/plugin.py index d8e953b9f..21e22b1ea 100644 --- a/plugins/Unix/plugin.py +++ b/plugins/Unix/plugin.py @@ -313,6 +313,62 @@ class Unix(callbacks.Plugin): 't':'positiveInt','W':'positiveInt'}), 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): """ Calls any command available on the system, and returns its output. diff --git a/src/version.py b/src/version.py index 94ee64bb4..84ccad0b9 100644 --- a/src/version.py +++ b/src/version.py @@ -1,3 +1,3 @@ """stick the various versioning attributes in here, so we only have to change 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)'