add installing pip requirements
This commit is contained in:
32
install.py
32
install.py
@@ -7,11 +7,11 @@
|
||||
|
||||
if bytes == str:
|
||||
raise NotImplementedError('python2 not supported')
|
||||
|
||||
import sys
|
||||
import os
|
||||
import filecmp
|
||||
import shutil
|
||||
import time
|
||||
from subprocess import Popen, PIPE
|
||||
from glob import glob
|
||||
from ipaddress import IPv4Interface
|
||||
@@ -66,22 +66,43 @@ ExecStart = /usr/bin/python3 /home/l_samenv/frappy/bin/secop-server %s
|
||||
[Install]
|
||||
WantedBy = multi-user.target
|
||||
"""
|
||||
pip_requirements = {
|
||||
'l_samenv': [],
|
||||
'root': []
|
||||
}
|
||||
|
||||
|
||||
def frappy(cfg=None, port=None, **kwds):
|
||||
def frappy(cfg=None, port=None, requirements='', **kwds):
|
||||
if not cfg:
|
||||
return None
|
||||
if port:
|
||||
cfg = '-p %s %s' % (port, cfg)
|
||||
pip_requirements['l_samenv'].extend(requirements.split(','))
|
||||
with open('/home/l_samenv/frappy/requirements.txt') as f:
|
||||
pip_requirements['l_samenv'].extend(f.read().split('\n'))
|
||||
return FRAPPY_TEMPLATE % cfg
|
||||
|
||||
|
||||
def router(**opts):
|
||||
if not opts:
|
||||
return None
|
||||
with open('/root/aputools/requirements.txt') as f:
|
||||
pip_requirements['root'].extend(f.read().split('\n'))
|
||||
return ROUTER_TEMPLATE
|
||||
|
||||
|
||||
def pip():
|
||||
for user, requirements in pip_requirements.items():
|
||||
if user == 'root':
|
||||
filename = join('/home', user, 'pip_requirements.txt')
|
||||
pipcmd = 'pip3 install -r %s' % filename
|
||||
else:
|
||||
filename = join('/root', 'pip_requirements.txt')
|
||||
pipcmd = 'sudo --user %s pip3 install --user -r %s' % (user, filename)
|
||||
if write_when_new(filename, '\n'.join(requirements)):
|
||||
unix_cmd(pipcmd)
|
||||
|
||||
|
||||
SERVICES = dict(router=router, frappy=frappy)
|
||||
|
||||
|
||||
@@ -344,12 +365,10 @@ def handle_config():
|
||||
raise
|
||||
return False
|
||||
|
||||
# pip requirements ?
|
||||
|
||||
actions_dict = {}
|
||||
reload_systemd = False
|
||||
for service, template_func in SERVICES.items():
|
||||
sction = service.upper()
|
||||
section = service.upper()
|
||||
if parser.has_section(section):
|
||||
template = template_func(**dict(parser[section]))
|
||||
else:
|
||||
@@ -371,7 +390,7 @@ def handle_config():
|
||||
else:
|
||||
if not active:
|
||||
actions.add('restart')
|
||||
if not enabled:
|
||||
if not enabled
|
||||
actions.add('enable')
|
||||
if write_when_new('/etc/systemd/system/%s.service' % service, template):
|
||||
reload_systemd = True
|
||||
@@ -379,6 +398,7 @@ def handle_config():
|
||||
actions.add('restart')
|
||||
actions_dict[service] = actions
|
||||
|
||||
pip()
|
||||
if reload_systemd:
|
||||
unix_cmd('systemctl daemon-reload')
|
||||
for service in SERVICES:
|
||||
|
||||
Reference in New Issue
Block a user