-
Notifications
You must be signed in to change notification settings - Fork 2
/
basics.py
executable file
·52 lines (43 loc) · 1.29 KB
/
basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import datetime
import time
import re
import subprocess
from subprocess import PIPE
from subprocess import STDOUT
class Uci:
def __init__(self):
pass
def get(self, section, option):
proc = subprocess.Popen(["uci", "get", "bluebox.%s.%s" % (section, option)], stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
proc.wait()
if proc.returncode:
ret = None
else:
ret = re.sub("\n$","", proc.stdout.read())
return ret
class Exec:
def __init__(self):
pass
def execlp(self, bin, args=[], wait=True):
proc = subprocess.Popen(([bin]+args), stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
#print "Executing",[bin]+args
if wait:
proc.wait()
if proc.returncode:
ret = None
else:
ret = proc.stdout.read()
return ret
else:
return None
class Clock:
def getIsoTime(self):
return datetime.datetime.isoformat(datetime.datetime.now().replace(microsecond=0))
def getTimestamp(self):
return int(time.time())
def getMicroTimestamp(self):
return time.time()
# -------------------------------------------------
class Log:
def __init__(self):
pass