def create_initial_config_file(args, extensions_data): """Initialize whatever the last config file is with defaults""" config_file = args.config_files[-1] if os.path.exists(path.expand_path(config_file)): return try: default = config_lib.format_initial(extensions_data) path.get_or_create_file(config_file, mkdir=False, content=default) logger.info("Initialized %s with default config", config_file) except IOError as error: logger.warning("Unable to initialize %s with default config: %s", config_file, encoding.locale_decode(error))
def create_initial_config_file(args, extensions_data): """Initialize whatever the last config file is with defaults""" config_file = args.config_files[-1] if os.path.exists(path.expand_path(config_file)): return try: default = config_lib.format_initial(extensions_data) path.get_or_create_file(config_file, mkdir=False, content=default) logger.info('Initialized %s with default config', config_file) except IOError as error: logger.warning('Unable to initialize %s with default config: %s', config_file, encoding.locale_decode(error))
def create_file_structures_and_config(args, extensions): path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy') path.get_or_create_dir(b'$XDG_CONFIG_DIR/mopidy') # Initialize whatever the last config file is with defaults config_file = args.config_files[-1] if os.path.exists(path.expand_path(config_file)): return try: default = config_lib.format_initial(extensions) path.get_or_create_file(config_file, mkdir=False, content=default) logger.info('Initialized %s with default config', config_file) except IOError as e: logger.warning('Unable to initialize %s with default config: %s', config_file, e)
def create_file_structures_and_config(args, extensions): path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy') path.get_or_create_dir(b'$XDG_CONFIG_DIR/mopidy') # Initialize whatever the last config file is with defaults config_file = args.config_files[-1] if os.path.exists(path.expand_path(config_file)): return try: default = config_lib.format_initial(extensions) path.get_or_create_file(config_file, mkdir=False, content=default) logger.info('Initialized %s with default config', config_file) except IOError as error: logger.warning('Unable to initialize %s with default config: %s', config_file, encoding.locale_decode(error))
def test_format_initial(): extension = ext.Extension() extension.ext_name = 'foo' extension.get_default_config = lambda: None extensions_data = [ ext.ExtensionData( extension=extension, entry_point=None, config_schema=None, config_defaults=None, command=None, ), ] result = config.format_initial(extensions_data) assert '# For further information' in result assert '[foo]\n' in result
def create_initial_config_file(args, extensions_data): """Initialize whatever the last config file is with defaults""" config_file = path.expand_path(args.config_files[-1]) if config_file.exists(): return try: default = config_lib.format_initial(extensions_data) path.get_or_create_file( config_file, mkdir=False, content=default.encode(errors="surrogateescape"), ) logger.info(f"Initialized {config_file.as_uri()} with default config") except OSError as exc: logger.warning( f"Unable to initialize {config_file.as_uri()} with default config: {exc}" )