Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_file(self, file, print_info=True):
if print_info:
print("loading config from :", repr(file))
try:
config = anyconfig.load(file, ignore_missing=True)
return config
except ValueError:
print("loading config failed...")
return {}
parser.add_argument('--config_file', default='config/icdar2015.yaml', type=str)
args = parser.parse_args()
return args
if __name__ == '__main__':
import sys
import anyconfig
project = 'crnn.gluon' # 工作项目根目录
sys.path.append(os.getcwd().split(project)[0] + project)
from utils import parse_config
args = init_args()
assert os.path.exists(args.config_file)
config = anyconfig.load(open(args.config_file, 'rb'))
if 'base' in config:
config = parse_config(config)
main(config)
common = ", ".join(sorted(conf.keys() & keys))
if common:
if len(common) > 100:
common = common[:100] + "..."
dups.add("{}: {}".format(str(file2), common))
if dups:
msg = "Duplicate keys found in {0} and:\n- {1}".format(
file1, "\n- ".join(dups)
)
raise ValueError(msg)
for config_file in config_files:
cfg = {
k: v
for k, v in anyconfig.load(config_file).items()
if not k.startswith("_")
}
_check_dups(config_file, cfg)
keys_by_filepath[config_file] = cfg.keys()
config.update(cfg)
return config
def read(self):
"""
Load the configuration files, set connections.
"""
self.config = anyconfig.load(self.paths, ignore_missing=True)
self.es = self.get_es()
self.redis = self.get_redis()
self.rq = self.get_rq()
def load(self, validate=True):
schema_file = os.path.join(sys._MEIPASS, 'schema.yml') \
if hasattr(sys, '_MEIPASS') else self._default_schema_path
try:
self._yaml = anyconfig.load(self.path, ignore_missing=False)
except FileNotFoundError:
panic('ERROR - %s configuration file does not exist' % self.path)
if validate:
validator = Core(source_file=self.path, schema_files=[schema_file])
validator.validate(raise_exception=True)
def sync_data_configuration():
parser = argparse.ArgumentParser(
description="Create services/collections/accounts",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"config", help="YAML file with data configuration")
parser.add_argument(
"-f", "--force-delete", dest="force_deletion",
action="store_true",
help=("force deletion of collections and their content blocks "
"if collection is not defined in configuration file"),
required=False)
args = parser.parse_args()
config = anyconfig.load(args.config, forced_type="yaml")
with app.app_context():
# run as admin with full access
context.account = local_admin
sync_conf_dict_into_db(
app.taxii_server,
config,
force_collection_deletion=args.force_deletion)
def _config_file_callback(ctx, param, value):
"""Config file callback, that replaces command line options with config file
values. If command line options are passed, they override config file values.
"""
ctx.default_map = ctx.default_map or {}
section = ctx.info_name
if value:
config = anyconfig.load(value)[section]
ctx.default_map.update(config)
return value
def _config_file_callback(ctx, param, value):
"""Config file callback, that replaces command line options with config file
values. If command line options are passed, they override config file values.
"""
ctx.default_map = ctx.default_map or {}
section = ctx.info_name
if value:
config = anyconfig.load(value)[section]
ctx.default_map.update(config)
return value