ucloud-setup/app/helper.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-09-07 13:10:28 +05:00
import subprocess as sp
2019-09-12 00:16:34 +05:00
import json
2019-09-12 13:20:28 +05:00
import os
2019-08-28 16:42:50 +05:00
2019-09-12 13:20:28 +05:00
def install_available(project_path):
2019-09-14 00:37:56 +05:00
try:
os.remove(os.path.join(project_path, "Pipfile.lock"))
except Exception:
pass
2019-09-12 13:20:28 +05:00
if get_distro_name() == "alpine":
2019-09-14 11:56:07 +05:00
sp.check_output(['pipenv','--site-packages', '--three'], cwd=project_path)
2019-09-14 00:41:55 +05:00
sp.check_output(['pipenv', 'lock'], cwd=project_path)
2019-09-12 13:20:28 +05: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 13:28:09 +05:00
sp.check_output(["apk", "add", f"py3-{package}"], stderr=sp.DEVNULL)
2019-09-12 13:20:28 +05:00
except Exception:
pass
2019-09-07 13:10:28 +05:00
def clone_common(path='.'):
sp.check_output(['git', 'clone',
2019-09-08 21:00:53 +05:00
f'https://code.ungleich.ch/ungleich-public/ucloud_common'], cwd=path)
2019-08-27 13:31:22 +05:00
2019-08-28 16:42:50 +05:00
2019-09-07 13:10:28 +05:00
def clone_etcd_wrapper(path='.'):
sp.check_output(['git', 'clone',
2019-09-08 21:00:53 +05:00
f'https://code.ungleich.ch/ahmedbilal/etcd3_wrapper'], cwd=path)
2019-08-27 13:31:22 +05:00
2019-08-28 16:42:50 +05:00
2019-08-28 12:13:05 +05: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-12 00:16:34 +05:00
return distro_name