From b07e8be21c7178772568fa94e0c9f863d877b931 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 12 Aug 2015 01:30:12 +0100 Subject: [PATCH] nb.py --- lib/python/nb.py | 40 ++++++++++++++++++++++++++++++++++++++++ lib/python/nb.pyc | Bin 911 -> 1802 bytes 2 files changed, 40 insertions(+) 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 8f360f29f883bef2c54e6109906841698d82a50c..7c3a6805535c1f58450c8d190b7b712f1aabea5d 100644 GIT binary patch literal 1802 zcmcIlTWi!n6h4z=+wS76)ndJ;A~u3`sfeJc2z~JKuxM7Pl)|#z%(l~JvuS2lEAE0= zpY_Q%f02L3AE4hksjWzn`e52Q`DQXXm+yR;^}ipjefae4Wrubz5BG-{Hik*?uP7y2 z-ouKP6(t^h#G*%uFTkfH5D-vO5m2FIOu!f=;{wLnRWq7^Tk``~qoV+M_!x^Ab`r)B zZ72$cMBbC9h~JEOOC#dE9PhMmtsCRJOLS4lQ(5oXwFt{3#?AoM`?;%UtM$~Z*7LV+ zy`N!r1E_+BiC!J7F|h2Jlw`wx$1x7eZ!|A$nbf;;(0(jM5BNZa|jIT0@@6yFgyiUXGRrzmLZC~bqDUY=4ff?(Xc{m z9yNg;JqCXCcnM@YeoWO~~Pcu@?r0IT(; zt71=~+evCNZH2~EXXWe6O*d=zv;^v|3u|3d*wRnG+qJS(zRJPUwsnVX!7=u3Qr%id z^pBWg@l)d}3ER80ly7;Hs#qK3pRyjyAVgi?~K1qhD5@3%e}n zUlckPPoeX)-O>BXEVMl=E$pn54Z;UC8E~T zm_WU|oIp~g`k>Vrg08^H4&DJX6`E~s&G6UWl-@T)Al*W1!{JL|iNrV^;UPW=6rW?an0&u1L4QAaSRdTqfz{Umf1N#mQp#RA|FgN4lSsPZ{CZgbv%jqTgZdk@ z7^SuGIiUDFn+v>#ahM~whHZ(ln=PB;+qi|<0d18Z2QHmTwwaEYe-vUq&f|-0X4$YT i_9GvH_X)gkuh&loseZuPl;BX3Uk$30)ro4YI`I?Mm^r8b delta 293 zcmeC;>u0ZL{>;nuqxn>5G6NJa18D~!E;a=cDL}-?ki)i*)f!vhTq|$T^AcJ9Y0F$~v z5QqiRSj+?@*cc~PSF#0x_-q^huVYjOE7SlvC