From a49009c53cc728081d12505681427a8c6d0270e0 Mon Sep 17 00:00:00 2001 From: neersighted Date: Fri, 30 Mar 2012 09:03:34 -0700 Subject: [PATCH] added uptime, but id does not work with hours. will fix later --- README.md | 6 +++--- plugins/admin.py | 2 +- plugins/system.py | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0fd541e..14d316d 100755 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ Unzip the resulting file, and continue to read this document. ## Install -Before you can run the bot, you need to install a few Python modules. These are `lXML`, `BeautifulSoup`, `MyGengo`, and `HTTPlib2`. These can be installed with PIP (The Python package manager): +Before you can run the bot, you need to install a few Python modules. These are `lXML`, `BeautifulSoup`, `psutil`, and `HTTPlib2`. These can be installed with PIP (The Python package manager): `sudo pip install lxml` `sudo pip install beautifulsoup` -`sudo pip install mygengo` +`sudo pip install psutil` `sudo pip install httplib2` @@ -93,7 +93,7 @@ They can both be found in [#CloudBot](irc://irc.esper.net/cloudbot "Connect via CloudBot runs on **Python** *2.7.x*. It is developed on **Debian** *Wheezy/Testing* and **Ubuntu** *11.10* with **Python** *2.7.2*. -It **requires Python modules** `lXML`, `BeautifulSoup`, `Enchant`, `MyGengo`, and `HTTPlib2`. +It **requires Python modules** `lXML`, `BeautifulSoup`, `Enchant`, `psutil`, and `HTTPlib2`. The programs `screen` or `daemon` are recomended for the wrapper to run optimaly. diff --git a/plugins/admin.py b/plugins/admin.py index 2b88d12..8b120df 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -28,7 +28,7 @@ def stop(inp, nick=None, conn=None): else: conn.cmd("QUIT", ["Killed by %s." % nick]) time.sleep(5) - subprocess.call(["./cloudbot", "stop"]) + os.execl(["./cloudbot", "stop"]) @hook.command(autohelp=False, adminonly=True) def restart(inp, nick=None, conn=None): diff --git a/plugins/system.py b/plugins/system.py index 0c1ca7e..c45932d 100755 --- a/plugins/system.py +++ b/plugins/system.py @@ -1,9 +1,10 @@ import os import re +import time +import psutil import platform from util import hook - def replace(text, wordDic): rc = re.compile('|'.join(map(re.escape, wordDic))) @@ -24,9 +25,9 @@ def checkProc(checked_stats): def mem(inp): ".mem -- Displays the bot's current memory usage." if os.name == 'posix': - checked_stats = 'Threads VmRSS VmSize VmPeak VmStk' + checked_stats = 'Threads VmRSS VmSize VmPeak VmStk VmData' stats = checkProc(checked_stats) - pretty_names = {'Threads': 'Active Threads', 'VmRSS': 'Real Memory', 'VmSize': 'Allocated Memory', 'VmPeak': 'Peak Allocated Memory', 'VmStk': 'Stack Size'} + pretty_names = {'Threads': 'Active Threads', 'VmRSS': 'Real Memory', 'VmSize': 'Allocated Memory', 'VmPeak': 'Peak Allocated Memory', 'VmStk': 'Stack Size', 'VmData': 'Heap Size'} stats = replace(stats, pretty_names) return stats @@ -40,6 +41,18 @@ def mem(inp): return 'error: operating system not currently supported' +@hook.command("up", autohelp=False) +@hook.command(autohelp=False) +def uptime(inp): + proc = psutil.Process(os.getpid()) + up_time = proc.create_time + up_time = time.time() - up_time + up_time = time.localtime(up_time) + up_time = time.strftime("Uptime: %M:%S", up_time) + return up_time + + + @hook.command("system", autohelp=False) @hook.command(autohelp=False) def sys(inp):