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)
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)
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)
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)
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)
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)
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)
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))
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)
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))
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))
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)
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)
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)
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)
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)
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')
def test_create_file_with_none_filename_throws_value_error(self): with self.assertRaises(ValueError): path.get_or_create_file(None)
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æøå')
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)
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')
def test_create_file_with_none(self): with self.assertRaises(ValueError): path.get_or_create_file(None)
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)
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")
def test_create_dir_with_none(self): with self.assertRaises(ValueError): path.get_or_create_file(None)
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)
def setup_settings(self): get_or_create_folder('~/.mopidy/') get_or_create_file('~/.mopidy/settings.py') settings.validate()