Beispiel #1
0
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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
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))
Beispiel #7
0
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)
Beispiel #8
0
 def test_absolute_path(self):
     self.assertEqual(b'/tmp/foo', path.expand_path(b'/tmp/foo'))
Beispiel #9
0
 def test_empty_path(self):
     self.assertEqual(os.path.abspath(b'.'), path.expand_path(b''))
Beispiel #10
0
 def test_xdg_subsititution_unknown(self):
     self.assertIsNone(path.expand_path(b'/tmp/$XDG_INVALID_DIR/foo'))
Beispiel #11
0
 def test_xdg_subsititution(self):
     self.assertEqual(glib.get_user_data_dir() + b'/foo',
                      path.expand_path(b'$XDG_DATA_DIR/foo'))
Beispiel #12
0
 def test_abspath(self):
     self.assertEqual(os.path.abspath(b'./foo'), path.expand_path(b'./foo'))
Beispiel #13
0
 def test_xdg_subsititution(self):
     self.assertEqual(glib.get_user_data_dir() + b"/foo", path.expand_path(b"$XDG_DATA_DIR/foo"))
Beispiel #14
0
 def test_home_dir_expansion(self):
     self.assertEqual(os.path.expanduser(b"~/foo"), path.expand_path(b"~/foo"))
Beispiel #15
0
 def test_empty_path(self):
     self.assertEqual(os.path.abspath(b"."), path.expand_path(b""))
Beispiel #16
0
 def test_abspath(self):
     self.assertEqual(os.path.abspath('./foo'), path.expand_path('./foo'))
Beispiel #17
0
 def test_xdg_subsititution_unknown(self):
     self.assertEqual(
         '/tmp/$XDG_INVALID_DIR/foo',
         path.expand_path('/tmp/$XDG_INVALID_DIR/foo'))
Beispiel #18
0
 def test_xdg_subsititution_unknown(self):
     self.assertEqual('/tmp/$XDG_INVALID_DIR/foo',
                      path.expand_path('/tmp/$XDG_INVALID_DIR/foo'))
Beispiel #19
0
 def test_absolute_path(self):
     self.assertEqual(b"/tmp/foo", path.expand_path(b"/tmp/foo"))
Beispiel #20
0
 def test_empty_path(self):
     self.assertEqual(os.path.abspath(b'.'), path.expand_path(b''))
Beispiel #21
0
 def test_abspath(self):
     self.assertEqual(os.path.abspath(b"./foo"), path.expand_path(b"./foo"))
Beispiel #22
0
 def test_absolute_path(self):
     self.assertEqual(b'/tmp/foo', path.expand_path(b'/tmp/foo'))
Beispiel #23
0
 def test_xdg_subsititution_unknown(self):
     self.assertIsNone(path.expand_path(b"/tmp/$XDG_INVALID_DIR/foo"))
Beispiel #24
0
 def test_home_dir_expansion(self):
     self.assertEqual(os.path.expanduser(b'~/foo'),
                      path.expand_path(b'~/foo'))