-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
77 lines (59 loc) · 2.68 KB
/
__main__.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
import argparse
import logging
from logging import StreamHandler
from logging.handlers import SysLogHandler
from sys import stdout
from config_file import ConfigFile
from copy_config_files import CopyConfigFiles
from install_as_service import write_init_d_script
from safe_shutdown import SafeShutdown
from switch_display import SwitchDisplay
from util import swap_config
hdmi = ConfigFile('/boot/config_hdmi.txt')
lcd = ConfigFile('/boot/config_lcd.txt')
current = ConfigFile('/boot/config.txt')
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)-8s %(name)-12s %(message)s',
handlers=[
SysLogHandler(address='/dev/log'),
StreamHandler(stdout),
])
# TODO add audio fix https://github.com/RetroFlag/GPiCase2-Script/blob/main/recalbox_install_gpi2.sh#L10
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--setup', help='Installs this script as self starting service.', action='store_true')
parser.add_argument('--set_lcd', help='Swaps the config to use the LCD display, may be used with --reboot.',
action='store_true')
parser.add_argument('--set_hdmi', help='Swaps the config to use the HDMI out, may be used with --reboot.',
action='store_true')
parser.add_argument('--reboot', help='Reboots after config switch.', action='store_true')
parser.add_argument('--wait_for_changes', help='Starts in listening mode and wait for power or display events.',
action='store_true')
parser.add_argument('--create_config_files',
help='Creates new display config files.',
action='store_true')
parser.add_argument('--force', help='Force config files overwrite.', action='store_true')
args = parser.parse_args()
if args.setup:
write_init_d_script()
return
if args.set_lcd:
swap_config(lcd, current, args.reboot)
return
if args.set_hdmi:
swap_config(hdmi, current, args.reboot)
return
if args.create_config_files:
copy = CopyConfigFiles(config_hdmi=hdmi, config_lcd=lcd, config_current=current)
copy.ensure_config_files_exists(args.force)
return
if args.wait_for_changes:
copy = CopyConfigFiles(config_hdmi=hdmi, config_lcd=lcd, config_current=current)
copy.ensure_config_files_exists()
shutdown = SafeShutdown()
switch_display = SwitchDisplay(config_hdmi=hdmi, config_lcd=lcd, config_current=current, reboot=args.reboot)
switch_display.start()
return
parser.print_help()
if __name__ == "__main__":
main()