-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
52 lines (45 loc) · 1.56 KB
/
update.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
import shutil
import configparser
import os
import time
class Updater:
def __init__(self):
self.config = configparser.ConfigParser()
self.path = "/home/pi/application.ini"
self.config.read(self.path)
self.start = self.config['DEFAULT'].getboolean('update')
@staticmethod
def del_directory():
try:
shutil.rmtree('/home/pi/sams_system', ignore_errors=True)
return True
except Exception:
return False
@staticmethod
def clone_directory():
try:
clone = os.system("sudo git clone https://github.com/sams-project/sams-app.git /home/pi/sams_system")
if clone == 0:
# todo: remove in the next version (2.49)
os.system("sudo apt install -y python3-gpiozero") # prepare for RGB LED
return True
else:
return False
except Exception:
return False
def update(self):
try:
if self.start:
if self.del_directory():
cloning = self.clone_directory()
if cloning:
self.config.set("DEFAULT", "update", "0")
with open(self.path, 'w') as configfile:
self.config.write(configfile)
os.system("sudo chown pi:pi -R /home/pi/sams_system")
time.sleep(60)
os.system('sudo reboot')
except Exception:
pass
updater = Updater()
updater.update()