示例#1
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))
    def load(self):
        if not self._index:
            if not os.path.exists(self._data_dir):
                path.get_or_create_dir(self._data_dir)
                self._index = whoosh.index.create_in(self._data_dir, schema)
            else:
                # TODO: this can fail on bad index versions
                self._index = whoosh.index.open_dir(self._data_dir)

        self._index.refresh()
        with self._index.searcher() as searcher:
            return searcher.doc_frequency('type', 'track')
示例#3
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))
示例#4
0
文件: actor.py 项目: CarnosOS/Peridot
    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)
示例#5
0
    def check_dirs_and_files(self):
        if not os.path.isdir(self.config["local"]["media_dir"]):
            logger.warning("Local media dir %s does not exist." % self.config["local"]["media_dir"])

        try:
            path.get_or_create_dir(self.config["local"]["data_dir"])
        except EnvironmentError as error:
            logger.warning("Could not create local data dir: %s", encoding.locale_decode(error))

        # TODO: replace with data dir?
        try:
            path.get_or_create_dir(self.config["local"]["playlists_dir"])
        except EnvironmentError as error:
            logger.warning("Could not create local playlists dir: %s", encoding.locale_decode(error))
示例#6
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)
示例#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)
示例#8
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)
示例#9
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)
示例#10
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))
示例#11
0
    def check_dirs_and_files(self):
        if not os.path.isdir(self.config['local']['media_dir']):
            logger.warning('Local media dir %s does not exist.' %
                           self.config['local']['media_dir'])

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

        try:
            path.get_or_create_file(self.config['local']['tag_cache_file'])
        except EnvironmentError as error:
            logger.warning('Could not create empty tag cache file: %s',
                           encoding.locale_decode(error))
示例#12
0
    def check_dirs_and_files(self):
        if not os.path.isdir(self.config['local']['media_dir']):
            logger.warning('Local media dir %s does not exist.' %
                           self.config['local']['media_dir'])

        try:
            path.get_or_create_dir(self.config['local']['data_dir'])
        except EnvironmentError as error:
            logger.warning('Could not create local data dir: %s',
                           encoding.locale_decode(error))

        # TODO: replace with data dir?
        try:
            path.get_or_create_dir(self.config['local']['playlists_dir'])
        except EnvironmentError as error:
            logger.warning('Could not create local playlists dir: %s',
                           encoding.locale_decode(error))
示例#13
0
文件: actor.py 项目: Halfnhav/mopidy
    def check_dirs_and_files(self):
        if not os.path.isdir(self.config['local']['media_dir']):
            logger.warning('Local media dir %s does not exist.' %
                           self.config['local']['media_dir'])

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

        try:
            path.get_or_create_file(self.config['local']['tag_cache_file'])
        except EnvironmentError as error:
            logger.warning(
                'Could not create empty tag cache file: %s',
                encoding.locale_decode(error))
示例#14
0
 def get_or_create_data_dir(cls, config):
     try:
         data_dir = config['local']['data_dir']
     except KeyError:
         from mopidy.exceptions import ExtensionError
         raise ExtensionError('Mopidy-Local not enabled')
     # FIXME: mopidy.utils.path is undocumented
     from mopidy.utils.path import get_or_create_dir
     return get_or_create_dir(os.path.join(data_dir, b'sqlite'))
示例#15
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)
示例#16
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)
示例#17
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)
示例#18
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
示例#19
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         dir_path = unicode(os.path.join(self.parent, b'test'))
         path.get_or_create_dir(dir_path)
示例#20
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)
示例#21
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)
示例#22
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         dir_path = unicode(os.path.join(self.parent, b"test"))
         path.get_or_create_dir(dir_path)
示例#23
0
def create_file_structures():
    path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy')
    path.get_or_create_file(b'$XDG_CONFIG_DIR/mopidy/mopidy.conf')
示例#24
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)
示例#25
0
def create_file_structures():
    path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy')
    path.get_or_create_file(b'$XDG_CONFIG_DIR/mopidy/mopidy.conf')
示例#26
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_dir(None)
示例#27
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)