a
This commit is contained in:
parent
0a521eac33
commit
959b530248
4 changed files with 54 additions and 9 deletions
|
|
@ -87,4 +87,30 @@ class FileOperation(object):
|
|||
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
|
||||
else:
|
||||
return Result("", ResultType.success)
|
||||
|
||||
|
||||
|
||||
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]
|
||||
return distro_name
|
||||
|
||||
class PackageManagementOperation(object):
|
||||
@staticmethod
|
||||
def install(package_name):
|
||||
try:
|
||||
distro = get_distro_name()
|
||||
if distro == "alpine":
|
||||
command = f"apk add {package_name}"
|
||||
else:
|
||||
assert "Unknown Distro"
|
||||
|
||||
subprocess.check_output(distro)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
|
||||
else:
|
||||
return Result("", ResultType.success)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue