From 7911d0f0a3f9a13b5adb843c41052f403681761a Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 30 Aug 2003 02:33:28 +0000 Subject: [PATCH] Moved kernel over to Http as per the wishes of the kernel.org folx0rs. --- plugins/FunCommands.py | 25 ++----------------------- plugins/Http.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 18959186c..a4794f107 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -447,7 +447,7 @@ class FunCommands(callbacks.Privmsg): """ (user, system, childUser, childSystem, elapsed) = os.times() timeRunning = time.time() - world.startedAt - threads = threading.activeCount() + activeThreads = threading.activeCount() response ='I have taken %s seconds of user time and %s seconds of '\ 'system time, for a total of %s seconds of CPU time. My '\ 'children have taken %s seconds of user time and %s seconds'\ @@ -460,7 +460,7 @@ class FunCommands(callbacks.Privmsg): (user+system+childUser+childSystem)/timeRunning, world.threadsSpawned, world.threadsSpawned == 1 and 'thread' or 'threads', - threads, world.commandsProcessed, + activeThreads, world.commandsProcessed, world.commandProcessed == 1 and 'command' or 'commands') irc.reply(msg, response) @@ -774,27 +774,6 @@ class FunCommands(callbacks.Privmsg): irc.error(msg, 'Host not found.') dns = privmsgs.thread(dns) - def kernel(self, irc, msg, args): - """takes no arguments""" - try: - conn = telnetlib.Telnet('kernel.org', 79) - conn.write('\n') - text = conn.read_all() - except socket.error, e: - irc.error(msg, e.args[1]) - return - stable = 'unkown' - beta = 'unknown' - for line in text.splitlines(): - (name, version) = line.split(':') - if 'latest stable' in name: - stable = version.strip() - elif 'latest beta' in name: - beta = version.strip() - irc.reply(msg, 'The latest stable kernel is %s; ' \ - 'the latest beta kernel is %s.' % (stable, beta)) - kernel = privmsgs.thread(kernel) - Class = FunCommands diff --git a/plugins/Http.py b/plugins/Http.py index f93bd5eb6..aa55660b8 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -473,6 +473,25 @@ class Http(callbacks.Privmsg): language = random.sample(babelfish.available_languages, 1)[0] irc.reply(msg, language) + def kernel(self, irc, msg, args): + """takes no arguments + + Returns information about the current version of the Linux kernel. + """ + try: + fd = urllib2.urlopen('http://www.kernel.org/kdist/finger_banner') + except urllib2.URLError: + irc.error(msg, 'Couldn\'t connect to kernel.org.') + return + for line in fd: + (name, version) = line.split(':') + if 'latest stable' in name: + stable = version.strip() + elif 'latest beta' in name: + beta = version.strip() + irc.reply(msg, 'The latest stable kernel is %s; ' \ + 'the latest beta kernel is %s.' % (stable, beta)) + Class = Http # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: