def __init__(self, config, debug, packs):
self.debug = debug
if self.debug:
print('using encoding {}'.format(sys.stdout.encoding))
self.config_path = Path(config).resolve()
self.packs = packs
self.cache_dir = appdirs.AppDirs(
appname='voodoo', appauthor='nikky').user_cache_dir
# parse config
config_dir = self.config_path.parent
self.global_config = {}
config_suffix = self.config_path.suffix
if config_suffix == '.yaml':
config_dir.mkdir(parents=True, exist_ok=True)
output = io.StringIO()
default_config = pkg_resources.resource_string(__name__, 'data/default.yaml').decode()
output.write(default_config)
output.write('\n# END DEFAULTS\n\n# BEGIN CONFIG\n\n')
with open(self.config_path) as infile:
output.write(infile.read())
self.config_str = output.getvalue()
output.close()
self.global_config = yaml.safe_load(self.config_str)
if self.debug:
print(yaml.dump(self.global_config))
self.config_path = config_dir
temp_path = self.global_config.get('temp_path')
if temp_path:
temp_path = Path(self.config_path, temp_path)
temp_path.mkdir(parents=True, exist_ok=True)
temp_path = Path(temp_path, 'generated_config.yaml')
with open(temp_path, 'w') as outfile:
outfile.write(self.config_str)
else:
print('requires yaml config file')
exit(-1)
# auth_file = args.auth or config.get('authentication', None)
# auth = config.get('authentication', {})
# if args.username_github and args.password_github:
# auth_github = {'username': args.username, 'password': args.password}
# auth['github'] = auth_github
评论列表
文章目录