-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (32 loc) · 856 Bytes
/
utils.py
File metadata and controls
38 lines (32 loc) · 856 Bytes
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import json
import random
import subprocess
def getRandom(l):
return l[random.randint(0, len(l)-1)]
def execCmdBackground(cmd):
print(cmd)
os.system('%s &' % cmd)
def execCmd(cmd):
proc = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE)
lines = []
while True:
line = proc.stdout.readline().decode("utf-8").strip("\n")
if len(line) == 0:
break
lines.append(line)
return lines
def getLights(info):
lights = []
for line in execCmd("python {0}".format(info)):
lights.append(json.loads(line.strip("\n")))
return lights
def getStateLight(info, lights=None):
if lights == None:
lights = getLights(info)
for light in lights:
if light["power"] > 0:
return True
return False