-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
94 lines (83 loc) · 3.16 KB
/
app.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
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
import keys, settings, config
import os
import time
def render():
# Draw background image
background = pygame.image.load('resources/background.png').convert()
settings.screen.blit(background, (0, 0))
def handler_normal(key):
if key == keys.RG350_BUTTON_DOWN:
settings.selected += 1
if settings.selected > len(settings.config) - 1:
settings.selected = 0
elif key == keys.RG350_BUTTON_UP:
settings.selected -= 1
if settings.selected < 0:
settings.selected = len(settings.config) - 1
elif key == keys.RG350_BUTTON_A:
settings.config[settings.selected]['enabled'] = not settings.config[settings.selected]['enabled']
# Save changes in config
if settings.status in [0, 4, 5, 6, 7]:
config.save()
elif key == keys.RG350_BUTTON_B:
if settings.n_systems_enabled() > 0:
settings.status = 4
elif key == keys.RG350_BUTTON_X:
if settings.n_backups_available() > 0:
settings.status = 6
def handler_confirm_backup(key):
if key == keys.RG350_BUTTON_A:
settings.status = 5
settings.system = settings.next_backup_system(0)
elif key == keys.RG350_BUTTON_B:
settings.status = 0
def handler_confirm_restore(key):
if key == keys.RG350_BUTTON_A:
settings.status = 7
settings.system = settings.next_restore_system(0)
elif key == keys.RG350_BUTTON_B:
settings.status = 0
def handler_void(key):
pass
handler_mapping = {
0: handler_normal, # 0: NORMAL
1: handler_void, # 1: ERROR Empty config
2: handler_void, # 2: ERROR Wrong config
3: handler_void, # 3: ERROR Destionation Directory not accessible
4: handler_confirm_backup, # 4: NORMAL Confirm backup
5: handler_void, # 5: NORMAL Doing backup
6: handler_confirm_restore, # 6: NORMAL Confirm restore
7: handler_void # 7: NORMAL Doing restore
}
def handle_events(events):
for event in events:
if event.type == pygame.KEYUP:
handler_mapping[settings.status](event.key)
def do_backup(system):
if settings.system < len(settings.config):
backup_file = settings.backup_filename(settings.config[system]['name'])
my_cmd = "tar -czf '%s' %s" % (backup_file, " ".join(settings.config[system]['dirs']))
os.system(my_cmd)
my_cmd = "sync"
os.system(my_cmd)
time.sleep(0.5)
settings.system = settings.next_backup_system(settings.system + 1)
if settings.system < 0:
settings.status = 0
def do_restore(system):
if settings.system < len(settings.config):
backup_file = settings.backup_filename(settings.config[system]['name'])
if os.path.exists(backup_file):
my_cmd = "tar -xzf '%s' -C /" % (backup_file)
os.system(my_cmd)
my_cmd = "sync"
os.system(my_cmd)
time.sleep(0.5)
settings.system = settings.next_restore_system(settings.system + 1)
if settings.system < 0:
settings.status = 0
settings.selected = 0
config.load()