mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Merge branch 'readability'
This commit is contained in:
commit
8be4aaeff1
@ -109,11 +109,11 @@ class Status(callbacks.Plugin):
|
|||||||
timeElapsed = utils.timeElapsed(elapsed)
|
timeElapsed = utils.timeElapsed(elapsed)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
timeElapsed = _('an indeterminate amount of time')
|
timeElapsed = _('an indeterminate amount of time')
|
||||||
irc.reply(_('I have received %s messages for a total of %s bytes. '
|
irc.reply(format(_('I have received %s messages for a total of %S. '
|
||||||
'I have sent %s messages for a total of %s bytes. '
|
'I have sent %s messages for a total of %S. '
|
||||||
'I have been connected to %s for %s.') %
|
'I have been connected to %s for %s.'),
|
||||||
(self.recvdMsgs, self.recvdBytes,
|
self.recvdMsgs, self.recvdBytes,
|
||||||
self.sentMsgs, self.sentBytes, irc.server, timeElapsed))
|
self.sentMsgs, self.sentBytes, irc.server, timeElapsed))
|
||||||
net = wrap(net)
|
net = wrap(net)
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -160,10 +160,10 @@ class Status(callbacks.Plugin):
|
|||||||
irc.error(_('Unable to run ps command.'), Raise=True)
|
irc.error(_('Unable to run ps command.'), Raise=True)
|
||||||
(out, foo) = inst.communicate()
|
(out, foo) = inst.communicate()
|
||||||
inst.wait()
|
inst.wait()
|
||||||
mem = out.splitlines()[1]
|
mem = int(out.splitlines()[1])
|
||||||
elif sys.platform.startswith('netbsd'):
|
elif sys.platform.startswith('netbsd'):
|
||||||
mem = '%s kB' % os.stat('/proc/%s/mem' % pid)[7]
|
mem = int(os.stat('/proc/%s/mem' % pid)[7])
|
||||||
response += _(' I\'m taking up %s kB of memory.') % mem
|
response += format(_(' I\'m taking up %S of memory.'), mem)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception('Uncaught exception in cpu.memory:')
|
self.log.exception('Uncaught exception in cpu.memory:')
|
||||||
irc.reply(utils.str.normalizeWhitespace(response))
|
irc.reply(utils.str.normalizeWhitespace(response))
|
||||||
|
@ -44,7 +44,8 @@ class StatusTestCase(PluginTestCase):
|
|||||||
self.failIf('None' in m.args[1], 'None in cpu output: %r.' % m)
|
self.failIf('None' in m.args[1], 'None in cpu output: %r.' % m)
|
||||||
for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']:
|
for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']:
|
||||||
if sys.platform.startswith(s):
|
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.')
|
'No memory string on supported platform.')
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.plugins.Status.cpu.get('children')()
|
original = conf.supybot.plugins.Status.cpu.get('children')()
|
||||||
|
@ -154,15 +154,15 @@ class Web(callbacks.PluginRegexp):
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
size = fd.headers['Content-Length']
|
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:
|
except KeyError:
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
s = fd.read(size)
|
s = fd.read(size)
|
||||||
if len(s) != 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:
|
else:
|
||||||
irc.reply(format(_('The server didn\'t tell me how long %u '
|
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))
|
url, size))
|
||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
@ -188,7 +188,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
irc.reply(_('That URL appears to have no HTML title.'))
|
irc.reply(_('That URL appears to have no HTML title.'))
|
||||||
else:
|
else:
|
||||||
irc.reply(format(_('That URL appears to have no HTML title '
|
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'])
|
title = wrap(title, ['httpUrl'])
|
||||||
|
|
||||||
_netcraftre = re.compile(r'td align="left">\s+<a[^>]+>(.*?)<a href',
|
_netcraftre = re.compile(r'td align="left">\s+<a[^>]+>(.*?)<a href',
|
||||||
|
@ -363,7 +363,7 @@ def timestamp(t):
|
|||||||
t = time.time()
|
t = time.time()
|
||||||
return time.ctime(t)
|
return time.ctime(t)
|
||||||
|
|
||||||
_formatRe = re.compile('%((?:\d+)?\.\d+f|[bfhiLnpqrstuv%])')
|
_formatRe = re.compile('%((?:\d+)?\.\d+f|[bfhiLnpqrsStuv%])')
|
||||||
def format(s, *args, **kwargs):
|
def format(s, *args, **kwargs):
|
||||||
"""w00t.
|
"""w00t.
|
||||||
|
|
||||||
@ -378,6 +378,7 @@ def format(s, *args, **kwargs):
|
|||||||
p: pluralize (takes a string)
|
p: pluralize (takes a string)
|
||||||
q: quoted (takes a string)
|
q: quoted (takes a string)
|
||||||
n: nItems (takes a 2-tuple of (n, item) or a 3-tuple of (n, between, item))
|
n: nItems (takes a 2-tuple of (n, item) or a 3-tuple of (n, between, item))
|
||||||
|
S: returns a human-readable size (takes an int)
|
||||||
t: time, formatted (takes an int)
|
t: time, formatted (takes an int)
|
||||||
u: url, wrapped in braces (this should be configurable at some point)
|
u: url, wrapped in braces (this should be configurable at some point)
|
||||||
v: void : takes one or many arguments, but doesn't display it
|
v: void : takes one or many arguments, but doesn't display it
|
||||||
@ -428,6 +429,15 @@ def format(s, *args, **kwargs):
|
|||||||
return nItems(t[0], t[2], between=t[1])
|
return nItems(t[0], t[2], between=t[1])
|
||||||
else:
|
else:
|
||||||
raise ValueError, 'Invalid value for %%n in format: %s' % t
|
raise ValueError, 'Invalid value for %%n in format: %s' % t
|
||||||
|
elif char == 'S':
|
||||||
|
t = args.pop()
|
||||||
|
if not isinstance(t, (int, long)):
|
||||||
|
raise ValueError, 'Invalid value for %%S in format: %s' % t
|
||||||
|
for suffix in ['B','KB','MB','GB','TB']:
|
||||||
|
if t < 1024:
|
||||||
|
return "%i%s" % (t, suffix)
|
||||||
|
t /= 1024
|
||||||
|
|
||||||
elif char == 't':
|
elif char == 't':
|
||||||
return timestamp(args.pop())
|
return timestamp(args.pop())
|
||||||
elif char == 'u':
|
elif char == 'u':
|
||||||
|
Loading…
Reference in New Issue
Block a user