ucloud-setup/app/helper.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-09-07 08:10:28 +00:00
import subprocess as sp
2019-09-11 19:16:34 +00:00
import json
2019-09-12 08:20:28 +00:00
import os
2019-08-28 11:42:50 +00:00
2019-09-12 08:20:28 +00:00
def install_available(project_path):
2019-09-13 19:37:56 +00:00
try:
os.remove(os.path.join(project_path, "Pipfile.lock"))
except Exception:
pass
2019-09-12 08:20:28 +00:00
if get_distro_name() == "alpine":
2019-09-14 06:56:07 +00:00
sp.check_output(['pipenv','--site-packages', '--three'], cwd=project_path)
2019-09-13 19:41:55 +00:00
sp.check_output(['pipenv', 'lock'], cwd=project_path)
2019-09-12 08:20:28 +00:00
with open(os.path.join(project_path, "Pipfile.lock")) as f:
content = json.load(f)
for package in content["default"].keys():
try:
2019-09-12 08:28:09 +00:00
sp.check_output(["apk", "add", f"py3-{package}"], stderr=sp.DEVNULL)
2019-09-12 08:20:28 +00:00
except Exception:
pass
2019-09-07 08:10:28 +00:00
def clone_common(path='.'):
sp.check_output(['git', 'clone',
2019-09-08 16:00:53 +00:00
f'https://code.ungleich.ch/ungleich-public/ucloud_common'], cwd=path)
2019-08-27 08:31:22 +00:00
2019-08-28 11:42:50 +00:00
2019-09-07 08:10:28 +00:00
def clone_etcd_wrapper(path='.'):
sp.check_output(['git', 'clone',
2019-09-08 16:00:53 +00:00
f'https://code.ungleich.ch/ahmedbilal/etcd3_wrapper'], cwd=path)
2019-08-27 08:31:22 +00:00
2019-08-28 11:42:50 +00:00
2019-08-28 07:13:05 +00:00
def get_distro_name():
distro_name = None
with open("/etc/os-release") as f:
content = f.read()
start = content.find("ID=") + 3
end = content.find("\n", start)
distro_name = content[start:end]
2019-09-11 19:16:34 +00:00
return distro_name