Crude init function
This commit is contained in:
parent
b4e9e94f2c
commit
6067c30edd
4 changed files with 55 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
version: 0.1
|
version:
|
||||||
|
|
||||||
suffix:
|
suffix:
|
||||||
project: .project
|
project: .project
|
17
src/kiwi-config.py
Normal file → Executable file
17
src/kiwi-config.py
Normal file → Executable file
|
@ -1,17 +1,26 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from kiwi import *
|
from kiwi.config import *
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='kiwi-config')
|
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()
|
args = parser.parse_args()
|
||||||
print(args.cmd)
|
print(args.command)
|
||||||
|
|
||||||
cf = config.Config.default()
|
cf = Config.default()
|
||||||
|
cf.init()
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,51 @@
|
||||||
class Config:
|
import os
|
||||||
# version, suffix_project, suffix_down, docker_net, docker_cidr, target_root = None
|
|
||||||
|
|
||||||
def __init__(self, filename):
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
__content = None
|
||||||
|
|
||||||
|
def __init__(self, filename):
|
||||||
with open(filename, 'r') as stream:
|
with open(filename, 'r') as stream:
|
||||||
try:
|
try:
|
||||||
print(yaml.safe_load(stream))
|
self.__content = yaml.safe_load(stream)
|
||||||
|
print(self.__content)
|
||||||
|
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default(cls):
|
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 ")
|
||||||
|
|
Loading…
Reference in a new issue