Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main_config_show(args):
cfg = None
if args.local and args.globalcfg:
raise ValueError(
"You can specify either -l/--local or -g/--global, not both.")
elif args.local:
for fn in config.CONFIG_FILENAMES:
if os.path.isfile(fn):
if cfg is None:
cfg = config.read_config_file(fn)
else:
cfg.merge(config.read_config_file(fn))
elif args.globalcfg:
cfg = config.read_config_file(config.FN_CONFIG)
else:
cfg = config.load_config()
if cfg is None:
if args.local and args.globalcfg:
mode = ' local or global '
elif args.local:
mode = ' local '
elif args.globalcfg:
mode = ' global '
else:
mode = ''
_print_err("Did not find a{}configuration file.".format(mode))
return
for key in args.key:
for kt in key.split('.'):
cfg = cfg.get(kt)
fn_config = None
if args.local and args.globalcfg:
raise ValueError(
"You can specify either -l/--local or -g/--global, not both.")
elif args.local:
for fn_config in config.CONFIG_FILENAMES:
if os.path.isfile(fn_config):
break
elif args.globalcfg:
fn_config = config.FN_CONFIG
else:
raise ValueError(
"You need to specify either -l/--local or -g/--global "
"to specify which configuration to modify.")
try:
cfg = config.read_config_file(fn_config)
except OSError:
cfg = config.get_config(fn_config)
keys = args.key.split('.')
if keys[-1].endswith('password'):
raise RuntimeError(
"Passwords need to be set with `{} config host "
"HOSTNAME -p`!".format(os.path.basename(sys.argv[0])))
else:
if len(args.value) == 0:
raise ValueError("No value argument provided!")
elif len(args.value) == 1:
args.value = args.value[0]
sec = cfg
for key in keys[:-1]:
sec = sec.setdefault(key, dict())
try:
args.storage = DEFAULT_STORAGE
c_args = {
'project': args.project_name,
'signac_version': args.signac_version,
}
if args.workspace:
make_dir(args.workspace)
c_args['workspace_dir'] = args.workspace
if args.storage:
make_dir(args.storage)
c_args['filestorage_dir'] = args.storage
if args.db_host:
c_args['database_host'] = args.db_host
fn_config = os.path.join(args.directory, 'signac.rc')
try:
config = read_config_file(fn_config)
except FileNotFoundError:
config = get_config()
config.update(c_args)
config.verify()
return config
def main_config_show(args):
cfg = None
if args.local and args.globalcfg:
raise ValueError(
"You can specify either -l/--local or -g/--global, not both.")
elif args.local:
for fn in config.CONFIG_FILENAMES:
if os.path.isfile(fn):
if cfg is None:
cfg = config.read_config_file(fn)
else:
cfg.merge(config.read_config_file(fn))
elif args.globalcfg:
cfg = config.read_config_file(config.FN_CONFIG)
else:
cfg = config.load_config()
if cfg is None:
if args.local and args.globalcfg:
mode = ' local or global '
elif args.local:
mode = ' local '
elif args.globalcfg:
mode = ' global '
else:
mode = ''
_print_err("Did not find a{}configuration file.".format(mode))
return
for key in args.key:
def get_config(args, for_writing=False):
try:
if args._global:
config_ = config.read_config_file(USER_GLOBAL)
elif args.config:
config_ = config.read_config_file(args.config)
elif for_writing:
config_ = config.read_config_file(USER_LOCAL)
else:
config_ = config.load_config()
except FileNotFoundError:
pass
return config_