remove requirements file when pip install fails
This commit is contained in:
68
install.py
68
install.py
@ -98,30 +98,40 @@ def router(**opts):
|
|||||||
def pip():
|
def pip():
|
||||||
for user, requirements in pip_requirements.items():
|
for user, requirements in pip_requirements.items():
|
||||||
if user == 'root':
|
if user == 'root':
|
||||||
filename = join('/root', 'pip_requirements.txt')
|
tmpname = join('/root', 'pip_requirements.tmp')
|
||||||
pipcmd = 'pip3 install -r %s' % filename
|
pipcmd = 'pip3 install -r %s' % tmpname
|
||||||
else:
|
else:
|
||||||
filename = join('/home', user, 'pip_requirements.txt')
|
tmpname = join('/home', user, 'pip_requirements.tmp')
|
||||||
pipcmd = 'sudo --user %s pip3 install --user -r %s' % (user, filename)
|
pipcmd = 'sudo --user %s pip3 install --user -r %s' % (user, tmpname)
|
||||||
|
filename = tmpname.replace('.tmp', '.txt')
|
||||||
content = ''.join('# --- for %s ---\n%s\n' % kv for kv in requirements.items())
|
content = ''.join('# --- for %s ---\n%s\n' % kv for kv in requirements.items())
|
||||||
if write_when_new(filename, content):
|
if write_when_new(filename, content, True):
|
||||||
unix_cmd(pipcmd)
|
if doit:
|
||||||
|
os.rename(filename, tmpname)
|
||||||
|
if os.system(pipcmd) == 0:
|
||||||
|
os.rename(tmpname, filename)
|
||||||
|
else:
|
||||||
|
os.remove(tmpname)
|
||||||
|
else:
|
||||||
|
print(pipcmd)
|
||||||
|
# unix_cmd(pipcmd, stdout=None)
|
||||||
show.dirty = True
|
show.dirty = True
|
||||||
|
|
||||||
|
|
||||||
SERVICES = dict(router=router, frappy=frappy)
|
SERVICES = dict(router=router, frappy=frappy)
|
||||||
|
|
||||||
|
|
||||||
def unix_cmd(command, always=False):
|
def unix_cmd(command, always=False, stdout=PIPE):
|
||||||
if doit or always:
|
if doit or always:
|
||||||
if not always:
|
if not always:
|
||||||
print('$ %s' % command)
|
print('$ %s' % command)
|
||||||
return Popen(command.split(), stdout=PIPE).communicate()[0].decode()
|
result = Popen(command.split(), stdout=stdout).communicate()[0]
|
||||||
|
return (result or b'').decode()
|
||||||
else:
|
else:
|
||||||
print('> %s' % command)
|
print('> %s' % command)
|
||||||
|
|
||||||
|
|
||||||
def write_when_new(filename, content):
|
def write_when_new(filename, content, ignore_reduction=False):
|
||||||
if content is None:
|
if content is None:
|
||||||
lines = []
|
lines = []
|
||||||
else:
|
else:
|
||||||
@ -135,6 +145,14 @@ def write_when_new(filename, content):
|
|||||||
old = None
|
old = None
|
||||||
if old == content:
|
if old == content:
|
||||||
return False
|
return False
|
||||||
|
if ignore_reduction:
|
||||||
|
content_set = set(v for v in lines if not v.startswith('#'))
|
||||||
|
old_set = set(v for v in (old or '').split('\n') if not v.startswith('#'))
|
||||||
|
content_set -= old_set
|
||||||
|
if content_set:
|
||||||
|
print('missing packages: %s' % (', '.join(content_set - old_set)))
|
||||||
|
else:
|
||||||
|
return False
|
||||||
if doit:
|
if doit:
|
||||||
if lines:
|
if lines:
|
||||||
with open(filename, 'w') as fil:
|
with open(filename, 'w') as fil:
|
||||||
@ -371,7 +389,7 @@ def handle_config():
|
|||||||
raise
|
raise
|
||||||
return False
|
return False
|
||||||
|
|
||||||
actions_dict = {}
|
to_start = {}
|
||||||
reload_systemd = False
|
reload_systemd = False
|
||||||
for service, template_func in SERVICES.items():
|
for service, template_func in SERVICES.items():
|
||||||
section = service.upper()
|
section = service.upper()
|
||||||
@ -387,32 +405,32 @@ def handle_config():
|
|||||||
enabled = True
|
enabled = True
|
||||||
elif line.strip() == 'ActiveState=active':
|
elif line.strip() == 'ActiveState=active':
|
||||||
active = True
|
active = True
|
||||||
actions = set()
|
|
||||||
if template is None:
|
if template is None:
|
||||||
if active:
|
if active:
|
||||||
actions.add('stop')
|
unix_cmd('systemctl stop %s' % service)
|
||||||
elif enabled:
|
show.dirty = True
|
||||||
actions.add('disable')
|
if enabled:
|
||||||
|
unix_cmd('systemctl disable %s' % service)
|
||||||
|
show.dirty = True
|
||||||
else:
|
else:
|
||||||
if not active:
|
|
||||||
actions.add('restart')
|
|
||||||
if not enabled:
|
if not enabled:
|
||||||
actions.add('enable')
|
to_start[service] = 'enable'
|
||||||
|
elif not active:
|
||||||
|
to_start[service] = 'restart'
|
||||||
if write_when_new('/etc/systemd/system/%s.service' % service, template):
|
if write_when_new('/etc/systemd/system/%s.service' % service, template):
|
||||||
show.dirty = True
|
show.dirty = True
|
||||||
reload_systemd = True
|
reload_systemd = True
|
||||||
if 'enable' in actions:
|
if template and to_start.get('service') is None:
|
||||||
actions.add('restart')
|
to_start[service] = 'restart'
|
||||||
actions_dict[service] = actions
|
|
||||||
|
|
||||||
pip()
|
pip()
|
||||||
if reload_systemd:
|
if reload_systemd:
|
||||||
unix_cmd('systemctl daemon-reload')
|
unix_cmd('systemctl daemon-reload')
|
||||||
for service in SERVICES:
|
for service, action in to_start.items():
|
||||||
for action in 'stop', 'restart', 'disable', 'enable':
|
show.dirty = True
|
||||||
if action in actions_dict[service]:
|
if action == 'restart':
|
||||||
show.dirty = True
|
unix_cmd('systemctl restart %s' % service)
|
||||||
unix_cmd('systemctl %s %s' % (action, service))
|
unix_cmd('systemctl enable %s' % service)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
[NETWORK]
|
[NETWORK]
|
||||||
|
; please refer to README.md for help
|
||||||
enp1s0=192.168.127.1/24
|
enp1s0=192.168.127.1/24
|
||||||
enp2s0=192.168.2.1/24
|
enp2s0=192.168.2.1/24
|
||||||
enp3s0=192.168.3.1/24
|
enp3s0=192.168.3.1/24
|
||||||
enp4s0=dhcp
|
enp4s0=dhcp
|
||||||
|
|
||||||
[ROUTER]
|
[ROUTER]
|
||||||
|
; please refer to README.md for help
|
||||||
3000=/dev/ttyUSB0
|
3000=/dev/ttyUSB0
|
||||||
5900=192.168.2.33
|
5900=192.168.2.33
|
||||||
8080=192.168.127.254:80
|
8080=192.168.127.254:80
|
||||||
|
Reference in New Issue
Block a user