def check_old_locations(): dot_mopidy_dir = path.expand_path(b'~/.mopidy') if os.path.isdir(dot_mopidy_dir): logger.warning( 'Old Mopidy dot dir found at %s. Please migrate your config to ' 'the ini-file based config format. See release notes for further ' 'instructions.', dot_mopidy_dir) old_settings_file = path.expand_path(b'$XDG_CONFIG_DIR/mopidy/settings.py') if os.path.isfile(old_settings_file): logger.warning( 'Old Mopidy settings file found at %s. Please migrate your ' 'config to the ini-file based config format. See release notes ' 'for further instructions.', old_settings_file)
def deserialize(self, value): value = value.strip() expanded = path.expand_path(value) validators.validate_required(value, self._required) validators.validate_required(expanded, self._required) if not value or expanded is None: return None return ExpandedPath(value, expanded)
def deserialize(self, value): value = value.strip() expanded = path.expand_path(value) validators.validate_required(value, self._required) validators.validate_required(expanded, self._required) if not value or expanded is None: return None return ExpandedPath(value, expanded)
def __getattr__(self, attr): if not self._is_setting(attr): return current = self.current # bind locally to avoid copying+updates if attr not in current: raise exceptions.SettingsError('Setting "%s" is not set.' % attr) value = current[attr] if isinstance(value, basestring) and len(value) == 0: raise exceptions.SettingsError('Setting "%s" is empty.' % attr) if not value: return value if attr.endswith('_PATH') or attr.endswith('_FILE'): value = path.expand_path(value) return value
def __getattr__(self, attr): if not self._is_setting(attr): return current = self.current # bind locally to avoid copying+updates if attr not in current: raise SettingsError(u'Setting "%s" is not set.' % attr) value = current[attr] if isinstance(value, basestring) and len(value) == 0: raise SettingsError(u'Setting "%s" is empty.' % attr) if not value: return value if attr.endswith('_PATH') or attr.endswith('_FILE'): value = path.expand_path(value) return value
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 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 test_absolute_path(self): self.assertEqual(b'/tmp/foo', path.expand_path(b'/tmp/foo'))
def test_empty_path(self): self.assertEqual(os.path.abspath(b'.'), path.expand_path(b''))
def test_xdg_subsititution_unknown(self): self.assertIsNone(path.expand_path(b'/tmp/$XDG_INVALID_DIR/foo'))
def test_xdg_subsititution(self): self.assertEqual(glib.get_user_data_dir() + b'/foo', path.expand_path(b'$XDG_DATA_DIR/foo'))
def test_abspath(self): self.assertEqual(os.path.abspath(b'./foo'), path.expand_path(b'./foo'))
def test_xdg_subsititution(self): self.assertEqual(glib.get_user_data_dir() + b"/foo", path.expand_path(b"$XDG_DATA_DIR/foo"))
def test_home_dir_expansion(self): self.assertEqual(os.path.expanduser(b"~/foo"), path.expand_path(b"~/foo"))
def test_empty_path(self): self.assertEqual(os.path.abspath(b"."), path.expand_path(b""))
def test_abspath(self): self.assertEqual(os.path.abspath('./foo'), path.expand_path('./foo'))
def test_xdg_subsititution_unknown(self): self.assertEqual( '/tmp/$XDG_INVALID_DIR/foo', path.expand_path('/tmp/$XDG_INVALID_DIR/foo'))
def test_xdg_subsititution_unknown(self): self.assertEqual('/tmp/$XDG_INVALID_DIR/foo', path.expand_path('/tmp/$XDG_INVALID_DIR/foo'))
def test_absolute_path(self): self.assertEqual(b"/tmp/foo", path.expand_path(b"/tmp/foo"))
def test_empty_path(self): self.assertEqual(os.path.abspath(b'.'), path.expand_path(b''))
def test_abspath(self): self.assertEqual(os.path.abspath(b"./foo"), path.expand_path(b"./foo"))
def test_absolute_path(self): self.assertEqual(b'/tmp/foo', path.expand_path(b'/tmp/foo'))
def test_xdg_subsititution_unknown(self): self.assertIsNone(path.expand_path(b"/tmp/$XDG_INVALID_DIR/foo"))
def test_home_dir_expansion(self): self.assertEqual(os.path.expanduser(b'~/foo'), path.expand_path(b'~/foo'))