-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdisplay.py
executable file
·107 lines (91 loc) · 3.32 KB
/
display.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python3
import logging
import getopt
import os
import sys
from bin.Config import Config
from bin.Screens import Display
from bin.Utils import Utils
LOG_LEVEL = logging.WARNING
def print_help():
filename = os.path.basename(__file__)
print (filename + ' [OPTIONS]... -c <config_path>')
print (' ')
print ('-h, --help')
print (' Prints out this help information')
print (' ')
print ('-d, --debug')
print (' Enable debug mode, printing out the process steps to STDOUT. NOTE: This doesnt include i2c display debugging')
print (' ')
print ('-c <config_path>, --config <config_path>')
print (' JSON options file')
print (' example:')
print (' ' + filename + ' -c /path/to/options.json')
print (' ' + filename + ' --config /path/to/options.json')
print (' ')
print ('-s <optional_save_path>, --screenshot <optional_save_path>')
print (' Save a screenshot to the specified location. If no path is specified, .png files are saved to ' + Display.SCREENSHOT_PATH)
print (' example:')
print (' ' + filename + ' -s')
print (' ' + filename + ' --screenshot')
print (' ' + filename + ' -s /path/to/image/store')
print (' ' + filename + ' --screenshot /path/to/image/store')
def start(config, logger):
screens = config.get_enabled_screens()
if not screens:
raise Exception("No screens are available")
config.enable_graceful_exit()
while config.allow_master_render:
for name in screens:
if config.allow_screen_render(name):
logger.info("'" + name + "' is being processed")
try:
screen = config.screen_factory(name)
screen.run()
config.reduce_screen_limit(name)
except Exception as e:
logger.critical("Screen '" + name + "' has an internal error: " + str(e))
continue
def set_logging_level(level):
logging.basicConfig()
main = logging.getLogger(__name__)
if level: main.setLevel(level)
for name in ('Screen', 'Config', 'Display', 'Utils'):
log = logging.getLogger(name)
if level: log.setLevel(level)
return main;
if __name__ == "__main__":
args = sys.argv[1:]
config_path = Utils.current_dir + '/options.json'
screenshot = False
try:
opts, args = getopt.getopt(args,"hdss:c:",["config=", "help", "debug", "screenshot=", "screenshot"])
except getopt.GetoptError:
print_help()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
print_help()
sys.exit()
elif opt in ("-c", "--config"):
config_path = arg
elif opt in ("-d", "--debug"):
LOG_LEVEL = logging.INFO
elif opt in ("-s", "--screenshot"):
if arg:
screenshot = arg
else:
screenshot = True
logger = set_logging_level(LOG_LEVEL)
if config_path:
try:
config = Config(config_path)
if screenshot:
config.add_option('screenshot', screenshot)
except Exception as e:
print(str(e))
sys.exit(2)
else:
logger.critical("No options.json file available.")
sys.exit(2)
start(config, logger)