def get_remote_lib(self, lib): lib_root = os.path.dirname(lib.path) remote_libs = os.path.join(lib_root, b"remotes") path = os.path.join(remote_libs, b"joined.db") if not os.path.isfile(path): raise OSError return library.Library(path)
def setUp(self): self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) self.lib = library.Library(':memory:', self.libdir) self.lib.path_formats = { 'default': 'one', 'comp': 'two', 'singleton': 'three', } self.srcpath = os.path.join(self.libdir, 'srcfile.mp3') shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath) self.i = library.Item.from_path(self.srcpath) self.i.comp = False trackinfo = TrackInfo('one', 'trackid', 'some artist', 'artistid', 1) self.info = AlbumInfo( artist='some artist', album='some album', tracks=[trackinfo], va=False, album_id='albumid', artist_id='artistid', albumtype='soundtrack', )
def setUp(self): super(ImportApplyTest, self).setUp() self.libdir = os.path.join(self.temp_dir, 'testlibdir') os.mkdir(self.libdir) self.libpath = os.path.join(self.temp_dir, 'testlib.blb') self.lib = library.Library(self.libpath, self.libdir) self.lib.path_formats = [ ('default', 'one'), ('singleton:true', 'three'), ('comp:true', 'two'), ] self.session = _common.import_session(self.lib) self.srcdir = os.path.join(self.temp_dir, 'testsrcdir') os.mkdir(self.srcdir) os.mkdir(os.path.join(self.srcdir, 'testalbum')) self.srcpath = os.path.join(self.srcdir, 'testalbum', 'srcfile.mp3') shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath) self.i = library.Item.from_path(self.srcpath) self.i.comp = False trackinfo = TrackInfo('one', 'trackid', 'some artist', 'artistid', 1) self.info = AlbumInfo( artist='some artist', album='some album', tracks=[trackinfo], va=False, album_id='albumid', artist_id='artistid', albumtype='soundtrack', )
def setUp(self): self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) self.lib = library.Library(':memory:', self.libdir) self.lib.path_formats = { 'default': 'one', 'comp': 'two', 'singleton': 'three', } self.srcpath = os.path.join(self.libdir, 'srcfile.mp3') shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath) self.i = library.Item.from_path(self.srcpath) self.i.comp = False trackinfo = { 'title': 'one', 'artist': 'some artist', 'track': 1, 'length': 1, 'id': 'trackid' } self.info = { 'artist': 'some artist', 'album': 'some album', 'tracks': [trackinfo], 'va': False, 'album_id': 'albumid', 'artist_id': 'artistid', 'albumtype': 'soundtrack', }
def setUp(self): super(UpdateTest, self).setUp() self.io.install() self.libdir = os.path.join(self.temp_dir, b'testlibdir') # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) item_path = os.path.join(_common.RSRC, b'full.mp3') item_path_two = os.path.join(_common.RSRC, b'full.flac') self.i = library.Item.from_path(item_path) self.i2 = library.Item.from_path(item_path_two) self.lib.add(self.i) self.lib.add(self.i2) self.i.move(operation=MoveOperation.COPY) self.i2.move(operation=MoveOperation.COPY) self.album = self.lib.add_album([self.i, self.i2]) # Album art. artfile = os.path.join(self.temp_dir, b'testart.jpg') _common.touch(artfile) self.album.set_art(artfile) self.album.store() os.remove(artfile)
def get_remote_lib(self, lib): lib_root = os.path.dirname(lib.path) remote_libs = lib_root + "/remotes" path = remote_libs + "/joined.db" if not os.path.isfile(path): raise IOError return library.Library(path)
def _raw_main(args, lib=None): """A helper function for `main` without top-level exception handling. """ subcommand, suboptions, subargs = _configure(args) if lib is None: # Open library file. dbpath = config['library'].as_filename() try: lib = library.Library( dbpath, config['directory'].as_filename(), get_path_formats(), get_replacements(), ) except sqlite3.OperationalError: raise UserError(u"database file {0} could not be opened".format( util.displayable_path(dbpath))) plugins.send("library_opened", lib=lib) log.debug(u'data directory: {0}\n' u'library database: {1}\n' u'library directory: {2}'.format( util.displayable_path(config.config_dir()), util.displayable_path(lib.path), util.displayable_path(lib.directory), )) # Configure the MusicBrainz API. mb.configure() # Invoke the subcommand. subcommand.func(lib, suboptions, subargs) plugins.send('cli_exit', lib=lib)
def setUp(self): self.setup_beets() self.lib = library.Library(':memory:') self.item = _common.item() self.item.path = 'xxx/yyy' self.lib.add(self.item) self.lib.add_album([self.item])
def setUp(self): self.lib = library.Library(':memory:', path_formats=[ ('default', 'albums/$album/$title'), ('singleton:true', 'tracks/$artist/$title'), ]) self.lib.add(_common.item()) self.lib.add_album([_common.item()]) self.tree = vfs.libtree(self.lib)
def setUp(self): self.io = _common.DummyIO() self.io.install() self.lib = library.Library(':memory:') i = _common.item() self.lib.add(i) self.lib.add_album([i])
def setUp(self): super(ListTest, self).setUp() self.io.install() self.lib = library.Library(':memory:') i = _common.item() i.path = 'xxx/yyy' self.lib.add(i) self.lib.add_album([i]) self.item = i
def setUp(self): self.lib = library.Library(':memory:', path_formats={ 'default': 'albums/$album/$title', 'singleton': 'tracks/$artist/$title', }) self.lib.add(_common.item()) self.lib.add_album([_common.item()]) self.lib.save() self.tree = vfs.libtree(self.lib)
def setUp(self): self.io = _common.DummyIO() self.io.install() self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3')) self.lib.add(self.i, True)
def setUp(self): self.setup_beets() self.load_plugins('beatport') self.lib = library.Library(':memory:') # Set up 'tracks'. self.response_tracks = self._make_tracks_response() self.tracks = [beatport.BeatportTrack(t) for t in self.response_tracks] # Make alias to be congruent with class `BeatportTest`. self.test_tracks = self.response_tracks
def setUp(self): super(QueryTest, self).setUp() self.libdir = os.path.join(self.temp_dir, 'testlibdir') os.mkdir(self.libdir) # Add a file to the library but don't copy it in yet. self.lib = library.Library(':memory:', self.libdir) # Alternate destination directory. self.otherdir = os.path.join(self.temp_dir, 'testotherdir')
def ipfs_added_albums(self, rlib, tmpname): """ Returns a new library with only albums/items added to ipfs """ tmplib = library.Library(tmpname) for album in rlib.albums(): try: if album.ipfs: self.create_new_album(album, tmplib) except AttributeError: pass return tmplib
def setUp(self): self.io = _common.DummyIO() self.io.install() self.libdb = os.path.join(_common.RSRC, 'testlib.blb') self.lib = library.Library(self.libdb) self.libdir = os.path.join(_common.RSRC, 'testlibdir') self.lib.directory = self.libdir self.lib.path_formats = [('default', os.path.join('$artist', '$album', '$title'))] self.srcdir = os.path.join(_common.RSRC, 'testsrcdir')
def _setup_library(self): self.libdb = os.path.join(self.temp_dir, 'testlib.blb') self.libdir = os.path.join(self.temp_dir, 'testlibdir') os.mkdir(self.libdir) self.lib = library.Library(self.libdb) self.lib.directory = self.libdir self.lib.path_formats = [ ('default', os.path.join('$artist', '$album', '$title')), ('singleton:true', os.path.join('singletons', '$title')), ('comp:true', os.path.join('compilations','$album', '$title')), ]
def setUp(self): super(ModifyTest, self).setUp() self.io.install() self.libdir = os.path.join(self.temp_dir, 'testlibdir') # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3')) self.lib.add(self.i, True) self.album = self.lib.add_album([self.i])
def setUp(self): super(NonAutotaggedImportTest, self).setUp() self.io.install() self.libdb = os.path.join(self.temp_dir, 'testlib.blb') self.lib = library.Library(self.libdb) self.libdir = os.path.join(self.temp_dir, 'testlibdir') self.lib.directory = self.libdir self.lib.path_formats = [('default', os.path.join('$artist', '$album', '$title'))] self.srcdir = os.path.join(self.temp_dir, 'testsrcdir')
def setUp(self): super(RemoveTest, self).setUp() self.io.install() self.libdir = os.path.join(self.temp_dir, 'testlibdir') os.mkdir(self.libdir) # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3')) self.lib.add(self.i) self.i.move(True)
def ipfs_import(self, lib, args): _hash = args[0] if len(args) > 1: lib_name = args[1] else: lib_name = _hash lib_root = os.path.dirname(lib.path) remote_libs = lib_root + "/remotes" if not os.path.exists(remote_libs): try: os.makedirs(remote_libs) except OSError as e: msg = "Could not create {0}. Error: {1}".format(remote_libs, e) self._log.error(msg) return False path = remote_libs + "/" + lib_name + ".db" if not os.path.exists(path): cmd = "ipfs get {0} -o".format(_hash).split() cmd.append(path) try: util.command_output(cmd) except (OSError, subprocess.CalledProcessError): self._log.error("Could not import {0}".format(_hash)) return False # add all albums from remotes into a combined library jpath = remote_libs + "/joined.db" jlib = library.Library(jpath) nlib = library.Library(path) for album in nlib.albums(): if not self.already_added(album, jlib): new_album = [] for item in album.items(): item.id = None new_album.append(item) added_album = jlib.add_album(new_album) added_album.ipfs = album.ipfs added_album.store()
def ipfs_import(self, lib, args): _hash = args[0] if len(args) > 1: lib_name = args[1] else: lib_name = _hash lib_root = os.path.dirname(lib.path) remote_libs = os.path.join(lib_root, b"remotes") if not os.path.exists(remote_libs): try: os.makedirs(remote_libs) except OSError as e: msg = f"Could not create {remote_libs}. Error: {e}" self._log.error(msg) return False path = os.path.join(remote_libs, lib_name.encode() + b".db") if not os.path.exists(path): cmd = f"ipfs get {_hash} -o".split() cmd.append(path) try: util.command_output(cmd) except (OSError, subprocess.CalledProcessError): self._log.error(f"Could not import {_hash}") return False # add all albums from remotes into a combined library jpath = os.path.join(remote_libs, b"joined.db") jlib = library.Library(jpath) nlib = library.Library(path) for album in nlib.albums(): if not self.already_added(album, jlib): new_album = [] for item in album.items(): item.id = None new_album.append(item) added_album = jlib.add_album(new_album) added_album.ipfs = album.ipfs added_album.store()
def setUp(self): super(RemoveTest, self).setUp() self.io.install() self.libdir = os.path.join(self.temp_dir, b'testlibdir') os.mkdir(self.libdir) # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) item_path = os.path.join(_common.RSRC, b'full.mp3') self.i = library.Item.from_path(item_path) self.lib.add(self.i) self.i.move(operation=MoveOperation.COPY)
def _reopen_lib(lib): """Because of limitations in SQLite, a given Library is bound to the thread in which it was created. This function reopens Library objects so that they can be used from separate threads. """ if isinstance(lib, library.Library): return library.Library( lib.path, lib.directory, lib.path_formats, lib.art_filename, ) else: return lib
def setUp(self): self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) self.dbpath = os.path.join(_common.RSRC, 'templib.blb') self.lib = library.Library(self.dbpath, self.libdir) self.lib.path_formats = { 'default': '$artist/$title', } self.config = _common.iconfig(self.lib, write=False, copy=False) self.srcpath = os.path.join(self.libdir, 'srcfile.mp3') shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath) self.i = library.Item.from_path(self.srcpath) self.i.comp = False
def setUp(self): self.dbpath = os.path.join(_common.RSRC, 'templib.blb') self.lib = library.Library(self.dbpath) self.config = _common.iconfig(self.lib, write=False, copy=False) # Make an "album" that has a homogenous artist. (Modified by # individual tests.) i1 = _common.item() i2 = _common.item() i3 = _common.item() i1.title = 'first item' i2.title = 'second item' i3.title = 'third item' i1.comp = i2.comp = i3.comp = False i1.albumartist = i2.albumartist = i3.albumartist = '' self.items = [i1, i2, i3]
def setUp(self): self.io = _common.DummyIO() self.io.install() self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) # Copy a file into the library. self.lib = library.Library(':memory:', self.libdir) self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3')) self.lib.add(self.i, True) self.album = self.lib.add_album([self.i]) # Album art. artfile = os.path.join(_common.RSRC, 'testart.jpg') _common.touch(artfile) self.album.set_art(artfile) os.remove(artfile)
def setUp(self): self.io = _common.DummyIO() self.io.install() self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) self.itempath = os.path.join(self.libdir, 'srcfile') shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.itempath) # Add a file to the library but don't copy it in yet. self.lib = library.Library(':memory:', self.libdir) self.i = library.Item.from_path(self.itempath) self.lib.add(self.i, False) self.album = self.lib.add_album([self.i]) # Alternate destination directory. self.otherdir = os.path.join(_common.RSRC, 'testotherdir')
def setUp(self): super(AsIsApplyTest, self).setUp() self.dbpath = os.path.join(self.temp_dir, 'templib.blb') self.lib = library.Library(self.dbpath) self.session = _common.import_session(self.lib) # Make an "album" that has a homogenous artist. (Modified by # individual tests.) i1 = _common.item() i2 = _common.item() i3 = _common.item() i1.title = 'first item' i2.title = 'second item' i3.title = 'third item' i1.comp = i2.comp = i3.comp = False i1.albumartist = i2.albumartist = i3.albumartist = '' self.items = [i1, i2, i3]