forked from piejanssens/premiumizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
68 lines (58 loc) · 2.63 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ConfigParser
import os
import subprocess
import sys
import time
runningdir = os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0]
def restart():
time.sleep(4)
execfile(os.path.join(runningdir, 'premiumizer.py'), globals(), globals())
def update():
del sys.argv[1:]
time.sleep(2)
subprocess.call(['git', '-C', os.path.join(runningdir, 'nzbtomedia'), 'pull'])
subprocess.call(['git', '-C', runningdir, 'pull'])
prem_config = ConfigParser.RawConfigParser()
default_config = ConfigParser.RawConfigParser()
prem_config.read(os.path.join(runningdir, 'settings.cfg'))
default_config.read(os.path.join(runningdir, 'settings.cfg.tpl'))
prem_config.set('update', 'updated', '1')
with open(os.path.join(runningdir, 'settings.cfg'), 'w') as configfile:
prem_config.write(configfile)
if prem_config.getfloat('update', 'req_version') < default_config.getfloat('update', 'req_version'):
import pip
pip.main(['install', '-r', os.path.join(runningdir, 'requirements.txt')])
prem_config.set('update', 'req_version', (default_config.getfloat('update', 'req_version')))
with open(os.path.join(runningdir, 'settings.cfg'), 'w') as configfile:
prem_config.write(configfile)
if prem_config.getfloat('update', 'config_version') < default_config.getfloat('update', 'config_version'):
import shutil
shutil.copy(os.path.join(runningdir, 'settings.cfg'), os.path.join(runningdir, 'settings.cfg.old2'))
shutil.copy(os.path.join(runningdir, 'settings.cfg.tpl'), os.path.join(runningdir, 'settings.cfg'))
prem_config.read(os.path.join(runningdir, 'settings.cfg.old2'))
default_config.read(os.path.join(runningdir, 'settings.cfg'))
for section in prem_config.sections():
if section in default_config.sections() and section != 'update':
for key in prem_config.options(section):
if key in default_config.options(section):
default_config.set(section, key, (prem_config.get(section, key)))
with open(os.path.join(runningdir, 'settings.cfg'), 'w') as configfile:
default_config.write(configfile)
if os_arg == '--windows':
pass
else:
time.sleep(3)
execfile(os.path.join(runningdir, 'premiumizer.py'), globals(), globals())
if len(sys.argv) == 3:
option_arg = sys.argv[1]
os_arg = sys.argv[2]
if os_arg == '--windows':
rootdir = runningdir[:-12]
else:
os_arg = ''
if option_arg == '--restart':
restart()
elif option_arg == '--update':
update()
else:
sys.exit()