This commit is contained in:
ahmadbilalkhalid 2019-08-28 16:42:50 +05:00
commit e57772f19e
8 changed files with 301 additions and 119 deletions

View file

@ -4,10 +4,12 @@ from dataclasses import dataclass
from abc import ABC
from enum import Enum
class ResultType(Enum):
success = 0
failure = 1
def clone(repo):
command = f"git clone {repo}"
try:
@ -16,14 +18,16 @@ def clone(repo):
return False
else:
return True
def clone_common():
return clone("https://code.ungleich.ch/ungleich-public/ucloud_common")
def clone_etcd_wrapper():
return clone("https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
class Result(object):
def __init__(self, _result, _type: ResultType, _op=""):
self._type = _type
@ -31,8 +35,7 @@ class Result(object):
self._op = _op
if self._type == ResultType.failure:
print(self._op, "failed")
def add(self, operation, **kwargs):
if self._type == ResultType.success:
r = operation(**kwargs)
@ -42,11 +45,11 @@ class Result(object):
else:
print("Dependency not satisfied")
exit(-1)
def __repr__(self):
return f"{self._type}, {self._result}"
class Operation(ABC):
pass
@ -58,10 +61,11 @@ class GitOperation(object):
try:
output = subprocess.check_output(command.split(), cwd=path)
except subprocess.CalledProcessError as e:
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
else:
return Result(output, ResultType.success)
class PipenvOperation(object):
@staticmethod
def install(path=".", package_name=None):
@ -72,7 +76,7 @@ class PipenvOperation(object):
try:
output = subprocess.check_output(command.split(), cwd=path)
except subprocess.CalledProcessError as e:
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
else:
return Result(output, ResultType.success)
@ -98,6 +102,7 @@ def get_distro_name():
distro_name = content[start:end]
return distro_name
class PackageManagementOperation(object):
@staticmethod
def install(package_name):
@ -107,7 +112,7 @@ class PackageManagementOperation(object):
command = f"apk add {package_name}"
else:
assert "Unknown Distro"
subprocess.check_output(command.split())
except Exception as e:
print(e)