From: Nicolas Boisselier Date: Wed, 12 Aug 2015 00:30:12 +0000 (+0100) Subject: nb.py X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=b07e8be21c7178772568fa94e0c9f863d877b931;p=nb.git nb.py --- diff --git a/lib/python/nb.py b/lib/python/nb.py index 285ba0d6..4a8990f8 100644 --- a/lib/python/nb.py +++ b/lib/python/nb.py @@ -1,8 +1,11 @@ import sys +import os +# Debug message def debug(msg): print >> sys.stderr, msg +# Return first and last line from a file def file_head_tail(fname): with open(fname, 'rb') as fh: first = next(fh) @@ -17,3 +20,40 @@ def file_head_tail(fname): return [first,last] print first print last + + +# Return CPU temperature as a character string +def cpu_temp(): + res = os.popen('vcgencmd measure_temp').readline() + return(res.replace("temp=","").replace("'C\n","")) + +# Return RAM information (unit=kb) in a list +# Index 0: total RAM +# Index 1: used RAM +# Index 2: free RAM +def mem_info(): + p = os.popen('free') + i = 0 + while 1: + i = i + 1 + line = p.readline() + if i==2: + return(line.split()[1:4]) + +# Return % of CPU used by user as a character string +def cpu_use(): + return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())) + +# Return information about disk space as a list (unit included) +# Index 0: total disk space +# Index 1: used disk space +# Index 2: remaining disk space +# Index 3: percentage of disk used +def disk_space(): + p = os.popen("df -h /") + i = 0 + while 1: + i = i +1 + line = p.readline() + if i==2: + return(line.split()[1:5]) diff --git a/lib/python/nb.pyc b/lib/python/nb.pyc index 8f360f29..7c3a6805 100644 Binary files a/lib/python/nb.pyc and b/lib/python/nb.pyc differ