-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
51 lines (36 loc) · 1.27 KB
/
utils.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
51
#!/usr/bin/env python
import os
import re
from PIL import Image
from animation import Animation
# utils.py for misc utils
def load_files(used_dir, overrides, dest_dict, path):
for item in os.listdir(used_dir):
filename = item.split(".gif")[0]
attrs = overrides.get(filename, {})
dest_dict[filename] = gif_loader(path + item, filename, attrs)
def gif_loader(file, filename, attrs):
# loads a gif into the array for storage
arr = []
try:
with Image.open(file, "r") as gif:
try:
while True:
arr.append(gif.copy().convert("RGB"))
gif.seek(len(arr))
except EOFError:
return Animation(filename, arr, attrs)
except Exception as e:
print(str(e))
def get_host_ip():
return re.search(re.compile(r"(?<=inet )(.*)(?=\/)", re.M),
os.popen("ip addr show usb0").read()).groups()[0]
def command_shutdown():
print("Shutdown commanded")
os.system("sudo shutdown -h 00:10 &")
def command_shutdown_cancel():
print("Shutdown canceled")
os.system("sudo shutdown -c &")
def command_restart():
print("Restart commanded")
os.system("sudo shutdown -r &")