From a9ab89664c1d12ff79a4c3ed699dc401053994f7 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 11 Aug 2004 17:04:57 +0000 Subject: [PATCH] Moved logfilesize to Status. --- plugins/Status.py | 31 +++++++++++++++++++++++++++++++ src/Misc.py | 30 ------------------------------ test/test_Misc.py | 6 ------ test/test_Status.py | 19 ++++++++++++++++--- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/plugins/Status.py b/plugins/Status.py index 071cc5388..c93d73cdb 100644 --- a/plugins/Status.py +++ b/plugins/Status.py @@ -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): + """[] + + 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 diff --git a/src/Misc.py b/src/Misc.py index 8a096bbcb..133f0d7c6 100755 --- a/src/Misc.py +++ b/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): - """[] - - 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): """ diff --git a/test/test_Misc.py b/test/test_Misc.py index 7bf283dd7..9ef17bb29 100644 --- a/test/test_Misc.py +++ b/test/test_Misc.py @@ -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') diff --git a/test/test_Status.py b/test/test_Status.py index cb1995c50..1903752d9 100644 --- a/test/test_Status.py +++ b/test/test_Status.py @@ -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: