From b47c7c92a391fb7368cd28b284146f78dc08f9e4 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 16 Oct 2010 11:37:58 +0200 Subject: [PATCH] Edit Status and Web plugins in order to use %S --- plugins/Status/plugin.py | 16 ++++++++-------- plugins/Status/test.py | 3 ++- plugins/Web/plugin.py | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/Status/plugin.py b/plugins/Status/plugin.py index fccd58336..ec7e34487 100644 --- a/plugins/Status/plugin.py +++ b/plugins/Status/plugin.py @@ -104,11 +104,11 @@ class Status(callbacks.Plugin): timeElapsed = utils.timeElapsed(elapsed) except KeyError: timeElapsed = 'an indeterminate amount of time' - irc.reply('I have received %s messages for a total of %s bytes. ' - 'I have sent %s messages for a total of %s bytes. ' - 'I have been connected to %s for %s.' % - (self.recvdMsgs, self.recvdBytes, - self.sentMsgs, self.sentBytes, irc.server, timeElapsed)) + irc.reply(format('I have received %s messages for a total of %S. ' + 'I have sent %s messages for a total of %S. ' + 'I have been connected to %s for %s.', + self.recvdMsgs, self.recvdBytes, + self.sentMsgs, self.sentBytes, irc.server, timeElapsed)) net = wrap(net) def cpu(self, irc, msg, args): @@ -154,10 +154,10 @@ class Status(callbacks.Plugin): irc.error('Unable to run ps command.', Raise=True) (out, _) = inst.communicate() inst.wait() - mem = out.splitlines()[1] + mem = int(out.splitlines()[1]) elif sys.platform.startswith('netbsd'): - mem = '%s kB' % os.stat('/proc/%s/mem' % pid)[7] - response += ' I\'m taking up %s kB of memory.' % mem + mem = int(os.stat('/proc/%s/mem' % pid)[7]) + response += format(' I\'m taking up %S of memory.', mem) except Exception: self.log.exception('Uncaught exception in cpu.memory:') irc.reply(utils.str.normalizeWhitespace(response)) diff --git a/plugins/Status/test.py b/plugins/Status/test.py index 4843c4145..d6781dfab 100644 --- a/plugins/Status/test.py +++ b/plugins/Status/test.py @@ -44,7 +44,8 @@ class StatusTestCase(PluginTestCase): self.failIf('None' in m.args[1], 'None in cpu output: %r.' % m) for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']: if sys.platform.startswith(s): - self.failUnless('kB' in m.args[1], + self.failUnless('B' in m.args[1] or 'KB' in m.args[1] or + 'MB' in m.args[1], 'No memory string on supported platform.') try: original = conf.supybot.plugins.Status.cpu.get('children')() diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 6a332c792..1ff163b37 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -149,15 +149,15 @@ class Web(callbacks.PluginRegexp): try: try: size = fd.headers['Content-Length'] - irc.reply(format('%u is %i bytes long.', url, size)) + irc.reply(format('%u is %S long.', url, size)) except KeyError: size = conf.supybot.protocols.http.peekSize() s = fd.read(size) if len(s) != size: - irc.reply(format('%u is %i bytes long.', url, len(s))) + irc.reply(format('%u is %S long.', url, len(s))) else: irc.reply(format('The server didn\'t tell me how long %u ' - 'is but it\'s longer than %i bytes.', + 'is but it\'s longer than %S.', url, size)) finally: fd.close() @@ -182,7 +182,7 @@ class Web(callbacks.PluginRegexp): irc.reply('That URL appears to have no HTML title.') else: irc.reply(format('That URL appears to have no HTML title ' - 'within the first %i bytes.', size)) + 'within the first %S.', size)) title = wrap(title, ['httpUrl']) _netcraftre = re.compile(r'td align="left">\s+]+>(.*?)