+ if Config.language != 'en':
+ gettext.translation("music_sampler",
+ localedir=path() + '/locales',
+ languages=[Config.language]).install()
+ if not Config.music_path.endswith("/"):
+ Config.music_path = Config.music_path + "/"
+
+def dump_config():
+ max_size = max(max(map(len, Configs_order)), len('config'))
+ info_print("{:<{}} : {}".format(
+ "config", max_size, Config.yml_file))
+ for item in Config.__dict__:
+ if item in Configs_order:
+ info_print("{:<{}} : {}".format(
+ item, max_size, getattr(Config, item)))
+
+def build_config(args):
+ stream = open(Config.yml_file, "r")
+ try:
+ config = yaml.safe_load(stream)
+ except Exception as e:
+ error_print("Error while loading config file: {}".format(e))
+ config = {}
+ stream.close()
+ if 'config' in config:
+ config = config['config']
+ else:
+ config = {}
+
+ for config_item in Configs_order:
+ if Configs[config_item]['type'] != 'boolean' and \
+ Configs[config_item]['type'] != 'action':
+ t = Configs[config_item]['type'] or str
+ if hasattr(args, config_item):
+ setattr(Config, config_item, getattr(args, config_item))
+ elif config_item in config:
+ setattr(Config, config_item, t(config[config_item]))
+ else:
+ setattr(Config, config_item, Configs[config_item]['default'])
+ elif Configs[config_item]['type'] == 'boolean':
+ if hasattr(args, 'no_' + config_item) or hasattr(args, config_item):
+ setattr(Config, config_item, hasattr(args, config_item))
+ elif config_item in config:
+ setattr(Config, config_item, config[config_item])
+ else:
+ setattr(Config, config_item, Configs[config_item]['default'])
+ else:
+ setattr(Config, config_item, hasattr(args, config_item))