2020-08-04 18:24:19 +00:00
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-04 14:52:30 +00:00
|
|
|
class Config:
|
2020-08-04 18:24:19 +00:00
|
|
|
__content = None
|
2020-08-04 14:52:30 +00:00
|
|
|
|
|
|
|
def __init__(self, filename):
|
|
|
|
with open(filename, 'r') as stream:
|
|
|
|
try:
|
2020-08-04 18:24:19 +00:00
|
|
|
self.__content = yaml.safe_load(stream)
|
|
|
|
print(self.__content)
|
|
|
|
|
2020-08-04 14:52:30 +00:00
|
|
|
except yaml.YAMLError as exc:
|
|
|
|
print(exc)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def default(cls):
|
2020-08-04 18:24:19 +00:00
|
|
|
kiwi_root = os.environ.get('KIWI_ROOT')
|
|
|
|
|
|
|
|
cfg = cls(kiwi_root + "/default.kiwi.yml")
|
|
|
|
with open(kiwi_root + "/version-tag", 'r') as stream:
|
|
|
|
cfg.__content["version"] = stream.read().strip()
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
|
|
|
|
def __user_input(self, path, key, prompt):
|
|
|
|
content = self.__content
|
|
|
|
|
|
|
|
for step in path:
|
|
|
|
content = content[step]
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = input("{} [Default: {}] ".format(prompt, content[key])).strip()
|
|
|
|
except:
|
|
|
|
result = None
|
|
|
|
|
|
|
|
if result:
|
|
|
|
content[key] = result
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
self.__user_input([], "version", "Choose kiwi-config version")
|
|
|
|
|
|
|
|
self.__user_input(["suffix"], "project", "Enter suffix for project directories")
|
|
|
|
self.__user_input(["suffix"], "down", "Enter suffix for disabled projects")
|
|
|
|
|
|
|
|
self.__user_input(["docker"], "net", "Enter ")
|
|
|
|
self.__user_input(["docker"], "cidr", "Enter ")
|
|
|
|
|
|
|
|
self.__user_input(["target"], "root", "Enter ")
|