mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 01:24:05 +01:00
Moved logfilesize to Status.
This commit is contained in:
parent
58e40a81bc
commit
a9ab89664c
@ -41,6 +41,7 @@ import os
|
||||
import sys
|
||||
import sets
|
||||
import time
|
||||
import os.path
|
||||
import threading
|
||||
from itertools import islice, ifilter, imap
|
||||
|
||||
@ -215,6 +216,36 @@ class Status(callbacks.Privmsg):
|
||||
"""
|
||||
irc.reply(irc.server)
|
||||
|
||||
def logfile(self, irc, msg, args):
|
||||
"""[<logfile>]
|
||||
|
||||
Returns the size of the various logfiles in use. If given a specific
|
||||
logfile, returns only the size of that logfile.
|
||||
"""
|
||||
filenameArg = privmsgs.getArgs(args, required=0, optional=1)
|
||||
if filenameArg:
|
||||
if not filenameArg.endswith('.log'):
|
||||
irc.error('That filename doesn\'t appear to be a log.')
|
||||
return
|
||||
filenameArg = os.path.basename(filenameArg)
|
||||
ret = []
|
||||
dirname = conf.supybot.directories.log()
|
||||
for (dirname,_,filenames) in os.walk(dirname):
|
||||
if filenameArg:
|
||||
if filenameArg in filenames:
|
||||
filename = os.path.join(dirname, filenameArg)
|
||||
stats = os.stat(filename)
|
||||
ret.append('%s: %s' % (filename, stats.st_size))
|
||||
else:
|
||||
for filename in filenames:
|
||||
stats = os.stat(os.path.join(dirname, filename))
|
||||
ret.append('%s: %s' % (filename, stats.st_size))
|
||||
if ret:
|
||||
ret.sort()
|
||||
irc.reply(utils.commaAndify(ret))
|
||||
else:
|
||||
irc.error('I couldn\'t find any logfiles.')
|
||||
|
||||
|
||||
Class = Status
|
||||
|
||||
|
30
src/Misc.py
30
src/Misc.py
@ -322,36 +322,6 @@ class Misc(callbacks.Privmsg):
|
||||
"""
|
||||
irc.reply('My source is at http://supybot.sf.net/')
|
||||
|
||||
def logfilesize(self, irc, msg, args):
|
||||
"""[<logfile>]
|
||||
|
||||
Returns the size of the various logfiles in use. If given a specific
|
||||
logfile, returns only the size of that logfile.
|
||||
"""
|
||||
filenameArg = privmsgs.getArgs(args, required=0, optional=1)
|
||||
if filenameArg:
|
||||
if not filenameArg.endswith('.log'):
|
||||
irc.error('That filename doesn\'t appear to be a log.')
|
||||
return
|
||||
filenameArg = os.path.basename(filenameArg)
|
||||
ret = []
|
||||
dirname = conf.supybot.directories.log()
|
||||
for (dirname,_,filenames) in os.walk(dirname):
|
||||
if filenameArg:
|
||||
if filenameArg in filenames:
|
||||
filename = os.path.join(dirname, filenameArg)
|
||||
stats = os.stat(filename)
|
||||
ret.append('%s: %s' % (filename, stats.st_size))
|
||||
else:
|
||||
for filename in filenames:
|
||||
stats = os.stat(os.path.join(dirname, filename))
|
||||
ret.append('%s: %s' % (filename, stats.st_size))
|
||||
if ret:
|
||||
ret.sort()
|
||||
irc.reply(utils.commaAndify(ret))
|
||||
else:
|
||||
irc.error('I couldn\'t find any logfiles.')
|
||||
|
||||
def plugin(self, irc, msg, args):
|
||||
"""<command>
|
||||
|
||||
|
@ -123,12 +123,6 @@ class MiscTestCase(ChannelPluginTestCase):
|
||||
def testSource(self):
|
||||
self.assertNotError('source')
|
||||
|
||||
def testLogfilesize(self):
|
||||
self.feedMsg('foo bar baz')
|
||||
self.feedMsg('bar baz quux')
|
||||
self.assertNotError('upkeep')
|
||||
self.assertNotError('logfilesize')
|
||||
|
||||
def testPlugin(self):
|
||||
self.assertResponse('plugin plugin', 'Misc')
|
||||
|
||||
|
@ -37,10 +37,10 @@ import supybot.world as world
|
||||
|
||||
class StatusTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Status',)
|
||||
def testNetstats(self):
|
||||
def testNet(self):
|
||||
self.assertNotError('net')
|
||||
|
||||
def testCpustats(self):
|
||||
def testCpu(self):
|
||||
m = self.assertNotError('status cpu')
|
||||
self.failIf('kB kB' in m.args[1])
|
||||
self.failIf('None' in m.args[1], 'None in cpu output: %r.' % m)
|
||||
@ -48,16 +48,29 @@ class StatusTestCase(PluginTestCase, PluginDocumentation):
|
||||
if sys.platform.startswith(s):
|
||||
self.failUnless('kB' in m.args[1],
|
||||
'No memory string on supported platform.')
|
||||
try:
|
||||
original = conf.supybot.plugins.Status.cpu.get('children')()
|
||||
conf.supybot.plugins.Status.cpu.get('children').setValue(False)
|
||||
self.assertNotRegexp('cpu', 'children')
|
||||
finally:
|
||||
conf.supybot.plugins.Status.cpu.get('children').setValue(original)
|
||||
|
||||
|
||||
def testUptime(self):
|
||||
self.assertNotError('uptime')
|
||||
|
||||
def testCmdstats(self):
|
||||
def testCmd(self):
|
||||
self.assertNotError('cmd')
|
||||
|
||||
def testCommands(self):
|
||||
self.assertNotError('commands')
|
||||
|
||||
def testLogfilesize(self):
|
||||
self.feedMsg('list')
|
||||
self.feedMsg('list Status')
|
||||
self.assertNotError('upkeep')
|
||||
self.assertNotError('logfile')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user