From 2db7699ed3b5bcbb7dc1f090fb95740b09b39e87 Mon Sep 17 00:00:00 2001 From: wlof Date: Sat, 19 Mar 2011 00:08:19 +0100 Subject: [PATCH 1/5] .. is now inserted at the beginning of sys.path so that local beets files are used instead of installed ones --- test/test_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ui.py b/test/test_ui.py index 0db323b75..7af95d758 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -23,7 +23,7 @@ import textwrap from StringIO import StringIO import logging import _common -sys.path.append('..') +sys.path.insert(0, '..') from beets import library from beets import ui from beets.ui import commands From 7be77a99d9ae013e741a8619692f080341321105 Mon Sep 17 00:00:00 2001 From: wlof Date: Sat, 19 Mar 2011 01:45:35 +0100 Subject: [PATCH 2/5] .. is now inserted at the beginning of sys.path so that local beets files are used instead of installed ones --- test/test_art.py | 2 +- test/test_autotag.py | 2 +- test/test_db.py | 2 +- test/test_files.py | 2 +- test/test_mb.py | 2 +- test/test_mediafile.py | 2 +- test/test_mediafile_basic.py | 2 +- test/test_player.py | 2 +- test/test_query.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/test_art.py b/test/test_art.py index 75a27f7c0..369c5e839 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -17,7 +17,7 @@ import unittest import sys -sys.path.append('..') +sys.path.insert(0, '..') from beets.autotag import art class MockHeaders(object): diff --git a/test/test_autotag.py b/test/test_autotag.py index 90e183073..a3f5e3eee 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -20,7 +20,7 @@ import sys import os import shutil import re -sys.path.append('..') +sys.path.insert(0, '..') from beets import autotag from beets.library import Item diff --git a/test/test_db.py b/test/test_db.py index 1afd67e0a..99d43f473 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -21,7 +21,7 @@ import os import sqlite3 import ntpath import posixpath -sys.path.append('..') +sys.path.insert(0, '..') import beets.library def lib(): return beets.library.Library('rsrc' + os.sep + 'test.blb') diff --git a/test/test_files.py b/test/test_files.py index 311dba671..1742214e9 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -21,7 +21,7 @@ import sys import os import stat from os.path import join -sys.path.append('..') +sys.path.insert(0, '..') import beets.library from test_db import item diff --git a/test/test_mb.py b/test/test_mb.py index 42910d836..2220d32b5 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -21,7 +21,7 @@ import time import musicbrainz2.model import musicbrainz2.webservice as mbws import _common -sys.path.append('..') +sys.path.insert(0, '..') from beets.autotag import mb def nullfun(): pass diff --git a/test/test_mediafile.py b/test/test_mediafile.py index 68a12c46a..d540e88f3 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -16,7 +16,7 @@ """ import unittest, sys, os, shutil, datetime -sys.path.append('..') +sys.path.insert(0, '..') import beets.mediafile class EdgeTest(unittest.TestCase): diff --git a/test/test_mediafile_basic.py b/test/test_mediafile_basic.py index 3aab06131..24948f1a2 100644 --- a/test/test_mediafile_basic.py +++ b/test/test_mediafile_basic.py @@ -17,7 +17,7 @@ layer. """ import unittest, sys, os, shutil, datetime -sys.path.append('..') +sys.path.insert(0, '..') import beets.mediafile diff --git a/test/test_player.py b/test/test_player.py index 4bd95bb78..4586aa804 100644 --- a/test/test_player.py +++ b/test/test_player.py @@ -17,7 +17,7 @@ import unittest import sys -sys.path.append('..') +sys.path.insert(0, '..') from beetsplug import bpd class FauxPathTest(unittest.TestCase): diff --git a/test/test_query.py b/test/test_query.py index e05f6fab7..cd5eb3875 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -16,7 +16,7 @@ """ import unittest, sys, os -sys.path.append('..') +sys.path.insert(0, '..') import beets.library import test_db From c09f6a75ffbd52c2ab850042ea5eeb5b3c6639df Mon Sep 17 00:00:00 2001 From: wlof Date: Sat, 19 Mar 2011 01:47:24 +0100 Subject: [PATCH 3/5] updated db to new format --- test/rsrc/test.blb | Bin 5120 -> 7168 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/r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3neL7Xb)cYb*T!gZ}n+UGL#Y(k`=U2 zCocc5oXpEk70o}{-M&{Ul^kqJsiZ&P2KHXSp;LNP(jbx|^qw&ZC+o-yrjif6V|@fY z7U9@yJ|Z1)3Z~@yi6Ae+p{{%uM0@Mn-h>gj@8|>Yw;_`$M)4h7Z8l7|$UVDW*h2Ga zt@hyd(yRIO!`$l9a74)g+zq@gxFkZ-tgPQM4?cB1qY?5v9TntZ&@4>Ai z#-y1PD?Hk5T4De3=jpFz^VxoTZ~rh=fN=Qu>A@H6tj6Meh(;%ZzU}>n=C$hf(fuVA zCP4oloF0qeR@S3FljKwKHTB_WPLAM^E=jwqxi}DTPogtTL?WIG%{s!o=|ZwxN=lVDibPb*fr6Uv1qLkxusOH?51<+|6Br+`ru4-4KMl_!-2=RU?)E>oFh0d}$C+sxX4(2fge_YyQ%N6(?9`;l(>ZUcGFEmV7unBT_u e;+;Ypzc Date: Sat, 19 Mar 2011 01:48:33 +0100 Subject: [PATCH 4/5] corrected a bug where artist was being used instead of albumartist in albums default queries --- beets/library.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beets/library.py b/beets/library.py index 5afaf9b70..fc7dd1344 100644 --- a/beets/library.py +++ b/beets/library.py @@ -95,9 +95,9 @@ ALBUM_KEYS_ITEM = [f[0] for f in ALBUM_FIELDS if f[2]] # Default search fields for various granularities. ARTIST_DEFAULT_FIELDS = ('artist',) -ALBUM_DEFAULT_FIELDS = ARTIST_DEFAULT_FIELDS + ('album', 'genre') -ITEM_DEFAULT_FIELDS = ALBUM_DEFAULT_FIELDS + \ - ('albumartist', 'title', 'comments') +ALBUM_DEFAULT_FIELDS = ('album', 'albumartist', 'genre') +ITEM_DEFAULT_FIELDS = ARTIST_DEFAULT_FIELDS + ALBUM_DEFAULT_FIELDS + \ + ('title', 'comments') # Logger. log = logging.getLogger('beets') From c2d2914178c63a20be7394485372118b571ea00f Mon Sep 17 00:00:00 2001 From: wlof Date: Sat, 19 Mar 2011 19:48:55 +0100 Subject: [PATCH 5/5] fix for issue 73 (http://code.google.com/p/beets/issues/detail?id=73) --- beets/library.py | 49 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/beets/library.py b/beets/library.py index fc7dd1344..1874d6ab3 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1002,12 +1002,23 @@ class Library(BaseLibrary): self.conn.execute(query, subvars) item._clear_dirty() - def remove(self, item, delete=False): + def _remove(self, item, delete=False): + """Removes this item from the library. If delete, then item's file + is also deleted from disk. + """ self.conn.execute('DELETE FROM items WHERE id=?', (item.id,)) if delete: os.unlink(_syspath(item.path)) - + def remove(self, item, delete=False): + """Removes this item, and the associated album if the removed item + was the last associated item of the album. + """ + album = self.get_album(item) + self._remove(item, delete) + if album and not album.items(): + album._remove(delete) + # Browsing. def artists(self, query=None): @@ -1188,6 +1199,27 @@ class Album(BaseAlbum): ) return ResultIterator(c, self._library) + def _remove(self, delete=False): + """Removes this album from the library. If delete, then album + art is deleted from disk, and the directories are removed + recursively (if empty). + """ + # Delete art and directory if empty. + if delete: + artpath = self.artpath + if artpath: + os.unlink(_syspath(artpath)) + try: + os.removedirs(_syspath(os.path.dirname(artpath))) + except OSError: + pass + + # Remove album from database. + self._library.conn.execute( + 'DELETE FROM albums WHERE id=?', + (self.id,) + ) + def remove(self, delete=False): """Removes this album and all its associated items from the library. If delete, then the items' files are also deleted @@ -1195,19 +1227,10 @@ class Album(BaseAlbum): """ # Remove items. for item in self.items(): - self._library.remove(item, delete) - - # Delete art. - if delete: - artpath = self.artpath - if artpath: - os.unlink(_syspath(artpath)) + self._library._remove(item, delete) # Remove album. - self._library.conn.execute( - 'DELETE FROM albums WHERE id=?', - (self.id,) - ) + self._remove(delete) def move(self, copy=False): """Moves (or copies) all items to their destination. Any