diff --git a/src/etc/default.kiwi.yml b/src/default.kiwi.yml similarity index 89% rename from src/etc/default.kiwi.yml rename to src/default.kiwi.yml index ec93e07..f3bd13b 100644 --- a/src/etc/default.kiwi.yml +++ b/src/default.kiwi.yml @@ -1,4 +1,4 @@ -version: 0.1 +version: suffix: project: .project diff --git a/src/kiwi-config.py b/src/kiwi-config.py old mode 100644 new mode 100755 index 5fae606..1f38814 --- a/src/kiwi-config.py +++ b/src/kiwi-config.py @@ -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 diff --git a/src/kiwi/config.py b/src/kiwi/config.py index abff981..07f0e69 100644 --- a/src/kiwi/config.py +++ b/src/kiwi/config.py @@ -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 ") diff --git a/version-tag b/src/version-tag similarity index 100% rename from version-tag rename to src/version-tag