Exemplo n.º 1
0
    def test_create_dir_with_name_of_existing_file_throws_oserror(self):
        conflicting_file = self.parent / "test"
        conflicting_file.touch()
        dir_path = self.parent / "test"

        with pytest.raises(OSError):
            path.get_or_create_dir(str(dir_path))
Exemplo n.º 2
0
    def get_config_dir(cls, config):
        """Get or create configuration directory for the extension.

        :param config: the Mopidy config object
        :return: string
        """
        assert cls.ext_name is not None
        config_dir_path = bytes(os.path.join(config["core"]["config_dir"], cls.ext_name))
        path.get_or_create_dir(config_dir_path)
        return config_dir_path
Exemplo n.º 3
0
    def get_config_dir(cls, config):
        """Get or create configuration directory for the extension.

        :param config: the Mopidy config object
        :return: pathlib.Path
        """
        assert cls.ext_name is not None
        config_dir_path = (path.expand_path(config["core"]["config_dir"]) /
                           cls.ext_name)
        path.get_or_create_dir(config_dir_path)
        return config_dir_path
Exemplo n.º 4
0
    def get_data_dir(self, config):
        """Get or create data directory for the extension.

        :param config: the Mopidy config object
        :returns: string
        """
        assert self.ext_name is not None
        data_dir_path = bytes(
            os.path.join(config['core']['data_dir'], self.ext_name))
        path.get_or_create_dir(data_dir_path)
        return data_dir_path
Exemplo n.º 5
0
    def get_config_dir(cls, config):
        """Get or create configuration directory for the extension.

        :param config: the Mopidy config object
        :return: string
        """
        assert cls.ext_name is not None
        config_dir_path = bytes(os.path.join(config['core']['config_dir'],
                                             cls.ext_name))
        path.get_or_create_dir(config_dir_path)
        return config_dir_path
Exemplo n.º 6
0
    def get_cache_dir(cls, config):
        """Get or create cache directory for the extension.

        Use this directory to cache data that can safely be thrown away.

        :param config: the Mopidy config object
        :return: string
        """
        assert cls.ext_name is not None
        cache_dir_path = bytes(os.path.join(config["core"]["cache_dir"], cls.ext_name))
        path.get_or_create_dir(cache_dir_path)
        return cache_dir_path
Exemplo n.º 7
0
    def get_data_dir(cls, config):
        """Get or create data directory for the extension.

        Use this directory to store data that should be persistent.

        :param config: the Mopidy config object
        :returns: string
        """
        data_dir_path = bytes(
            os.path.join(config['core']['data_dir'], 'local-images'))
        get_or_create_dir(data_dir_path)
        return data_dir_path
Exemplo n.º 8
0
def check_dirs_and_files(config):
    if not os.path.isdir(config['local']['media_dir']):
        logger.warning(
            'Local media dir %s does not exist.' %
            config['local']['media_dir'])

    try:
        path.get_or_create_dir(config['local']['data_dir'])
    except EnvironmentError as error:
        logger.warning(
            'Could not create local data dir: %s',
            encoding.locale_decode(error))
Exemplo n.º 9
0
    def get_data_dir(cls, config):
        """Get or create data directory for the extension.

        Use this directory to store data that should be persistent.

        :param config: the Mopidy config object
        :returns: string
        """
        assert cls.ext_name is not None
        data_dir_path = bytes(os.path.join(config["core"]["data_dir"], cls.ext_name))
        path.get_or_create_dir(data_dir_path)
        return data_dir_path
Exemplo n.º 10
0
    def get_data_dir(cls, config):
        """Get or create data directory for the extension.

        Use this directory to store data that should be persistent.

        :param config: the Mopidy config object
        :returns: string
        """
        assert cls.ext_name is not None
        data_dir_path = bytes(os.path.join(config['core']['data_dir'],
                                           cls.ext_name))
        path.get_or_create_dir(data_dir_path)
        return data_dir_path
Exemplo n.º 11
0
    def get_cache_dir(cls, config):
        """Get or create cache directory for the extension.

        Use this directory to cache data that can safely be thrown away.

        :param config: the Mopidy config object
        :return: pathlib.Path
        """
        assert cls.ext_name is not None
        cache_dir_path = (path.expand_path(config["core"]["cache_dir"]) /
                          cls.ext_name)
        path.get_or_create_dir(cache_dir_path)
        return cache_dir_path
Exemplo n.º 12
0
    def get_data_dir(cls, config):
        """Get or create data directory for the extension.

        Use this directory to store data that should be persistent.

        :param config: the Mopidy config object
        :returns: pathlib.Path
        """
        assert cls.ext_name is not None
        data_dir_path = (path.expand_path(config["core"]["data_dir"]) /
                         cls.ext_name)
        path.get_or_create_dir(data_dir_path)
        return data_dir_path
Exemplo n.º 13
0
    def __init__(self, config, audio):
        super(M3UBackend, self).__init__()

        self._config = config

        try:
            path.get_or_create_dir(config['m3u']['playlists_dir'])
        except EnvironmentError as error:
            logger.warning('Could not create M3U playlists dir: %s',
                           encoding.locale_decode(error))

        self.playlists = M3UPlaylistsProvider(backend=self)
        self.library = M3ULibraryProvider(backend=self)
Exemplo n.º 14
0
    def get_cache_dir(cls, config):
        """Get or create cache directory for the extension.

        Use this directory to cache data that can safely be thrown away.

        :param config: the Mopidy config object
        :return: string
        """
        assert cls.ext_name is not None
        cache_dir_path = bytes(os.path.join(config['core']['cache_dir'],
                                            cls.ext_name))
        path.get_or_create_dir(cache_dir_path)
        return cache_dir_path
Exemplo n.º 15
0
    def __init__(self, config, audio):
        super(M3UBackend, self).__init__()

        self._config = config

        try:
            path.get_or_create_dir(config['m3u']['playlists_dir'])
        except EnvironmentError as error:
            logger.warning(
                'Could not create M3U playlists dir: %s',
                encoding.locale_decode(error))

        self.playlists = M3UPlaylistsProvider(backend=self)
        self.library = M3ULibraryProvider(backend=self)
Exemplo n.º 16
0
def create_file_structures_and_config(args, extensions_data):
    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_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))
Exemplo n.º 17
0
 def test_creating_dir(self):
     dir_path = os.path.join(self.parent, b'test')
     self.assert_(not os.path.exists(dir_path))
     created = path.get_or_create_dir(dir_path)
     self.assert_(os.path.exists(dir_path))
     self.assert_(os.path.isdir(dir_path))
     self.assertEqual(created, dir_path)
Exemplo n.º 18
0
 def test_creating_dir(self):
     dir_path = os.path.join(self.parent, b'test')
     self.assert_(not os.path.exists(dir_path))
     created = path.get_or_create_dir(dir_path)
     self.assert_(os.path.exists(dir_path))
     self.assert_(os.path.isdir(dir_path))
     self.assertEqual(created, dir_path)
Exemplo n.º 19
0
def create_file_structures_and_config(args, extensions_data):
    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_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))
Exemplo n.º 20
0
    def test_creating_dir(self):
        dir_path = self.parent / "test"
        assert not dir_path.exists()

        created = path.get_or_create_dir(str(dir_path))

        assert dir_path.is_dir()
        assert created == dir_path
Exemplo n.º 21
0
 def test_creating_nested_dirs(self):
     level2_dir = os.path.join(self.parent, b'test')
     level3_dir = os.path.join(self.parent, b'test', b'test')
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(level3_dir))
     created = path.get_or_create_dir(level3_dir)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(level3_dir))
     self.assert_(os.path.isdir(level3_dir))
     self.assertEqual(created, level3_dir)
Exemplo n.º 22
0
 def test_creating_nested_dirs(self):
     level2_dir = os.path.join(self.parent, b'test')
     level3_dir = os.path.join(self.parent, b'test', b'test')
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(level3_dir))
     created = path.get_or_create_dir(level3_dir)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(level3_dir))
     self.assert_(os.path.isdir(level3_dir))
     self.assertEqual(created, level3_dir)
Exemplo n.º 23
0
    def test_creating_nested_dirs(self):
        level2_dir = self.parent / "test"
        level3_dir = self.parent / "test" / "test"
        assert not level2_dir.exists()
        assert not level3_dir.exists()

        created = path.get_or_create_dir(str(level3_dir))

        assert level2_dir.is_dir()
        assert level3_dir.is_dir()
        assert created == level3_dir
Exemplo n.º 24
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         dir_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_dir(dir_path)
Exemplo n.º 25
0
 def _get_data_dir(self):
     # get or create data director for core
     data_dir_path = os.path.join(self._config['core']['data_dir'], b'core')
     path.get_or_create_dir(data_dir_path)
     return data_dir_path
Exemplo n.º 26
0
 def _get_data_dir(self):
     # get or create data director for core
     data_dir_path = os.path.join(self._config['core']['data_dir'], b'core')
     path.get_or_create_dir(data_dir_path)
     return data_dir_path
Exemplo n.º 27
0
def create_core_dirs(config):
    path.get_or_create_dir(config['core']['cache_dir'])
    path.get_or_create_dir(config['core']['config_dir'])
    path.get_or_create_dir(config['core']['data_dir'])
Exemplo n.º 28
0
 def _get_data_dir(self):
     # get or create data director for core
     data_dir_path = (path.expand_path(self._config["core"]["data_dir"]) /
                      "core")
     path.get_or_create_dir(data_dir_path)
     return data_dir_path
Exemplo n.º 29
0
    def test_creating_existing_dir(self):
        created = path.get_or_create_dir(str(self.parent))

        assert self.parent.is_dir()
        assert created == self.parent
Exemplo n.º 30
0
 def test_creating_existing_dir(self):
     created = path.get_or_create_dir(self.parent)
     self.assert_(os.path.exists(self.parent))
     self.assert_(os.path.isdir(self.parent))
     self.assertEqual(created, self.parent)
Exemplo n.º 31
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
Exemplo n.º 32
0
def create_core_dirs(config):
    path.get_or_create_dir(config["core"]["cache_dir"])
    path.get_or_create_dir(config["core"]["config_dir"])
    path.get_or_create_dir(config["core"]["data_dir"])
Exemplo n.º 33
0
 def test_create_dir_with_name_of_existing_file_throws_oserror(self):
     conflicting_file = os.path.join(self.parent, b'test')
     open(conflicting_file, 'w').close()
     dir_path = os.path.join(self.parent, b'test')
     with self.assertRaises(OSError):
         path.get_or_create_dir(dir_path)
Exemplo n.º 34
0
 def test_creating_existing_dir(self):
     created = path.get_or_create_dir(self.parent)
     self.assert_(os.path.exists(self.parent))
     self.assert_(os.path.isdir(self.parent))
     self.assertEqual(created, self.parent)
Exemplo n.º 35
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         dir_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_dir(dir_path)
Exemplo n.º 36
0
 def test_create_dir_with_name_of_existing_file_throws_oserror(self):
     conflicting_file = os.path.join(self.parent, b'test')
     open(conflicting_file, 'w').close()
     dir_path = os.path.join(self.parent, b'test')
     with self.assertRaises(OSError):
         path.get_or_create_dir(dir_path)
Exemplo n.º 37
0
 def test_create_dir_with_none(self):
     with pytest.raises(TypeError):
         path.get_or_create_dir(None)
Exemplo n.º 38
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
Exemplo n.º 39
0
def create_core_dirs(config):
    path.get_or_create_dir(config["core"]["cache_dir"])
    path.get_or_create_dir(config["core"]["config_dir"])
    path.get_or_create_dir(config["core"]["data_dir"])
Exemplo n.º 40
0
def create_core_dirs(config):
    path.get_or_create_dir(config['core']['cache_dir'])
    path.get_or_create_dir(config['core']['config_dir'])
    path.get_or_create_dir(config['core']['data_dir'])