예제 #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)
예제 #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)
예제 #3
0
파일: core.py 프로젝트: 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)
예제 #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)
예제 #5
0
파일: __main__.py 프로젝트: xim/mopidy
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)
예제 #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)
예제 #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)
예제 #8
0
파일: actor.py 프로젝트: jeinarsson/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))
예제 #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)
예제 #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
파일: 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))
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #18
0
파일: __main__.py 프로젝트: eisnerd/mopidy
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')
예제 #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)
예제 #20
0
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
예제 #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')
예제 #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æøå')
예제 #23
0
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
예제 #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)
예제 #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')
예제 #26
0
 def test_create_file_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
예제 #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)
예제 #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")
예제 #29
0
 def test_create_dir_with_none(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
예제 #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)
예제 #31
0
파일: core.py 프로젝트: bok/mopidy
 def setup_settings(self):
     get_or_create_folder('~/.mopidy/')
     get_or_create_file('~/.mopidy/settings.py')
     settings.validate()