1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-25 18:42:59 +00:00

Crude init function

This commit is contained in:
Jörn-Michael Miehe 2020-08-04 20:24:19 +02:00
parent b4e9e94f2c
commit 6067c30edd
4 changed files with 55 additions and 10 deletions

View file

@ -1,4 +1,4 @@
version: 0.1
version:
suffix:
project: .project

17
src/kiwi-config.py Normal file → Executable file
View file

@ -1,17 +1,26 @@
#!/usr/bin/env python3
import argparse
from kiwi import *
from kiwi.config import *
def main():
parser = argparse.ArgumentParser(description='kiwi-config')
parser.add_argument('cmd', metavar='command', type=str, help='subcommand to execute')
subs = parser.add_subparsers()
subs.required = True
subs.dest = 'command'
subs.add_parser('init', help="Create new kiwi-config instance")
subs.add_parser('add', help="Add a project to kiwi-config")
# parser.add_argument('cmd', metavar='command', type=str, help='subcommand to execute')
args = parser.parse_args()
print(args.cmd)
print(args.command)
cf = config.Config.default()
cf = Config.default()
cf.init()
pass

View file

@ -1,15 +1,51 @@
import os
import yaml
class Config:
# version, suffix_project, suffix_down, docker_net, docker_cidr, target_root = None
__content = None
def __init__(self, filename):
import yaml
with open(filename, 'r') as stream:
try:
print(yaml.safe_load(stream))
self.__content = yaml.safe_load(stream)
print(self.__content)
except yaml.YAMLError as exc:
print(exc)
@classmethod
def default(cls):
return cls("./etc/default.kiwi.yml")
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 ")