]> git.nbdom.net Git - nb.git/commitdiff
nb.py
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 12 Aug 2015 00:30:12 +0000 (01:30 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 12 Aug 2015 00:30:12 +0000 (01:30 +0100)
lib/python/nb.py
lib/python/nb.pyc

index 285ba0d6ff30755f58c8f30978e2c6fc3718e3d4..4a8990f894491b5a3646d7d2542189b1b3a83a46 100644 (file)
@@ -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])
index 8f360f29f883bef2c54e6109906841698d82a50c..7c3a6805535c1f58450c8d190b7b712f1aabea5d 100644 (file)
Binary files a/lib/python/nb.pyc and b/lib/python/nb.pyc differ