Esempio n. 1
0
 def test_creating_existing_file(self):
     file_path = os.path.join(self.parent, b'test')
     path.get_or_create_file(file_path)
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
Esempio n. 2
0
 def test_creating_existing_file(self):
     file_path = os.path.join(self.parent, b"test")
     path.get_or_create_file(file_path)
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
Esempio n. 3
0
File: core.py Progetto: Amli/mopidy
def setup_settings(interactive):
    get_or_create_folder('~/.mopidy/')
    get_or_create_file('~/.mopidy/settings.py')
    try:
        settings.validate(interactive)
    except SettingsError, e:
        logger.error(e.message)
        sys.exit(1)
Esempio n. 4
0
def setup_settings(interactive):
    path.get_or_create_folder(path.SETTINGS_PATH)
    path.get_or_create_folder(path.DATA_PATH)
    path.get_or_create_file(path.SETTINGS_FILE)
    try:
        settings.validate(interactive)
    except exceptions.SettingsError as ex:
        logger.error(ex.message)
        sys.exit(1)
Esempio n. 5
0
def setup_settings(interactive):
    get_or_create_folder(SETTINGS_PATH)
    get_or_create_folder(DATA_PATH)
    get_or_create_file(SETTINGS_FILE)
    try:
        settings.validate(interactive)
    except SettingsError, e:
        logger.error(e.message)
        sys.exit(1)
Esempio n. 6
0
 def get_or_create_image_file(self, path, data=None):
     what = imghdr.what(path, data)
     if not what:
         raise ValueError('Unknown image type')
     if not data:
         data = open(path).read()
     name = hashlib.md5(data).hexdigest() + '.' + what
     path = os.path.join(self.image_dir, name)
     get_or_create_file(str(path), True, data)
     return uritools.urijoin(self.base_uri, name)
Esempio n. 7
0
 def _get_or_create_image(self, path, data=None):
     what = imghdr.what(path, data)
     if not what:
         raise ValueError('Unknown image type')
     if not data:
         data = open(path).read()
     name = hashlib.md5(data).hexdigest() + '.' + what
     path = os.path.join(self.root, name)
     get_or_create_file(str(path), True, data)
     return self.geturi(name)
Esempio n. 8
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))
Esempio n. 9
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)
Esempio n. 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))
Esempio n. 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))
Esempio n. 12
0
 def test_creating_nested_file(self):
     level2_dir = os.path.join(self.parent, b'test')
     file_path = os.path.join(self.parent, b'test', b'test')
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(file_path))
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
Esempio n. 13
0
 def test_creating_nested_file(self):
     level2_dir = os.path.join(self.parent, b"test")
     file_path = os.path.join(self.parent, b"test", b"test")
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(file_path))
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
Esempio n. 14
0
 def test_create_file_with_name_of_existing_dir_throws_ioerror(self):
     conflicting_dir = os.path.join(self.parent)
     with self.assertRaises(IOError):
         path.get_or_create_file(conflicting_dir)
Esempio n. 15
0
 def test_create_dir_with_unicode_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         file_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_file(file_path)
Esempio n. 16
0
 def test_create_dir_with_unicode_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         file_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_file(file_path)
Esempio n. 17
0
 def test_create_dir_without_mkdir(self):
     file_path = os.path.join(self.parent, b"foo", b"bar")
     with self.assertRaises(IOError):
         path.get_or_create_file(file_path, mkdir=False)
Esempio n. 18
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')
Esempio n. 19
0
 def test_create_file_with_name_of_existing_dir_throws_ioerror(self):
     conflicting_dir = os.path.join(self.parent)
     with self.assertRaises(IOError):
         path.get_or_create_file(conflicting_dir)
Esempio n. 20
0
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
Esempio n. 21
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')
Esempio n. 22
0
 def test_create_dir_with_unicode_content(self):
     file_path = os.path.join(self.parent, b'test')
     created = path.get_or_create_file(file_path, content='foobaræøå')
     with open(created) as fh:
         self.assertEqual(fh.read(), b'foobaræøå')
Esempio n. 23
0
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
Esempio n. 24
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         file_path = unicode(os.path.join(self.parent, b"test"))
         path.get_or_create_file(file_path)
Esempio n. 25
0
 def test_create_dir_with_default_content(self):
     file_path = os.path.join(self.parent, b'test')
     created = path.get_or_create_file(file_path, content=b'foobar')
     with open(created) as fh:
         self.assertEqual(fh.read(), b'foobar')
Esempio n. 26
0
 def test_create_file_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
Esempio n. 27
0
 def test_create_dir_with_unicode(self):
     with self.assertRaises(ValueError):
         file_path = unicode(os.path.join(self.parent, b'test'))
         path.get_or_create_file(file_path)
Esempio n. 28
0
 def test_create_dir_with_default_content(self):
     file_path = os.path.join(self.parent, b"test")
     created = path.get_or_create_file(file_path, content=b"foobar")
     with open(created) as fh:
         self.assertEqual(fh.read(), b"foobar")
Esempio n. 29
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
Esempio n. 30
0
 def test_create_dir_without_mkdir(self):
     file_path = os.path.join(self.parent, b'foo', b'bar')
     with self.assertRaises(IOError):
         path.get_or_create_file(file_path, mkdir=False)
Esempio n. 31
0
File: core.py Progetto: bok/mopidy
 def setup_settings(self):
     get_or_create_folder('~/.mopidy/')
     get_or_create_file('~/.mopidy/settings.py')
     settings.validate()