示例#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))
示例#2
0
文件: ext.py 项目: HaBaLeS/mopidy
    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
示例#3
0
文件: ext.py 项目: zwl1671/mopidy
    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
示例#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
示例#5
0
文件: ext.py 项目: zhanghuabin/mopidy
    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
示例#6
0
文件: ext.py 项目: HaBaLeS/mopidy
    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
示例#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
示例#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))
示例#9
0
文件: ext.py 项目: HaBaLeS/mopidy
    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
示例#10
0
文件: ext.py 项目: zhanghuabin/mopidy
    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
示例#11
0
文件: ext.py 项目: zwl1671/mopidy
    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
示例#12
0
文件: ext.py 项目: zwl1671/mopidy
    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
示例#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)
示例#14
0
文件: ext.py 项目: zhanghuabin/mopidy
    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
示例#15
0
文件: actor.py 项目: bencevans/mopidy
    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)
示例#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))
示例#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)
示例#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)
示例#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))
示例#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
示例#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)
示例#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)
示例#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
示例#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)
示例#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
示例#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
示例#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'])
示例#28
0
文件: actor.py 项目: zwl1671/mopidy
 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
示例#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
示例#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)
示例#31
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
示例#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"])
示例#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)
示例#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)
示例#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)
示例#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)
示例#37
0
 def test_create_dir_with_none(self):
     with pytest.raises(TypeError):
         path.get_or_create_dir(None)
示例#38
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
示例#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"])
示例#40
0
文件: __main__.py 项目: vrs01/mopidy
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'])