Remove obsolete album types ("allalbums" and "allimages").
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 4 Mar 2005 20:39:54 +0000 (20:39 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 4 Mar 2005 20:39:54 +0000 (20:39 +0000)
Ticket #91.

src/cmdline/kofoto
src/lib/kofoto/search.py
src/lib/kofoto/shelf.py
src/test/searchtests.py
src/test/shelftests.py

index 3a37d4e..b02136c 100755 (executable)
@@ -161,8 +161,6 @@ def displayHelp():
         "\n"
         "    Type         Description\n"
         "    ------------------------\n"
-        "    allalbums    All albums, sorted by tag.\n"
-        "    allimages    All images, sorted by capture timestamp.\n"
         "    orphans      All albums and images that don't exist in any plain album.\n"
         "    plain        An ordinary container that holds albums and images.\n"
         "    search       An album containing the albums and images that match a search\n"
index 20e8b69..aa466e1 100644 (file)
@@ -187,14 +187,7 @@ class AlbumSearchNode:
 
     def getQuery(self):
         t = self._album.getType()
-        if t == "allalbums":
-            return "select 1 where null" # Return empty result set.
-        elif t == "allimages":
-            return (" select imageid"
-                    " from   image left join attribute"
-                    "            on imageid = objectid and name = 'captured'"
-                    " order by lcvalue, directory, filename")
-        elif t == "orphans":
+        if t == "orphans":
             return (" select imageid"
                     " from   image left join attribute"
                     " on     imageid = objectid and name = 'captured'"
index 70eaa88..871b350 100644 (file)
@@ -107,7 +107,7 @@ schema = """
         tag         VARCHAR(256) NOT NULL,
         -- Whether it is possible to delete the album.
         deletable   INTEGER NOT NULL,
-        -- Album type (plain, orphans, allalbums, ...).
+        -- Album type (plain, orphans or search).
         type        VARCHAR(256) NOT NULL,
 
         UNIQUE      (tag),
@@ -422,8 +422,6 @@ class Shelf:
         self.categorycache = {}
         self.orphanAlbumsCache = None
         self.orphanImagesCache = None
-        self.allAlbumsCache = None
-        self.allImagesCache = None
         self.modified = False
         self.modificationCallbacks = []
         if _DEBUG:
@@ -531,8 +529,6 @@ class Shelf:
         self.objectcache = {}
         self.orphanAlbumsCache = None
         self.orphanImagesCache = None
-        self.allAlbumsCache = None
-        self.allImagesCache = None
 
 
     def getStatistics(self):
@@ -568,7 +564,6 @@ class Shelf:
                 tag,
                 albumtype)
             self._setModified()
-            self.allAlbumsCache = None
             self.orphanAlbumsCache = None
             return self.getAlbum(lastrowid)
         except sql.IntegrityError:
@@ -738,7 +733,6 @@ class Shelf:
             if x in self.objectcache:
                 del self.objectcache[x]
         self._setModified()
-        self.allAlbumsCache = None
         self.orphanAlbumsCache = None
 
 
@@ -788,7 +782,6 @@ class Shelf:
         image = self.getImage(imageid)
         image.importExifTags()
         self._setModified()
-        self.allImagesCache = None
         self.orphanImagesCache = None
         return image
 
@@ -955,7 +948,6 @@ class Shelf:
             if x in self.objectcache:
                 del self.objectcache[x]
         self._setModified()
-        self.allImagesCache = None
         self.orphanImagesCache = None
 
 
@@ -1206,8 +1198,6 @@ class Shelf:
 
     def _albumFactory(self, albumid, tag, albumtype):
         albumtypemap = {
-            "allalbums": AllAlbumsAlbum,
-            "allimages": AllImagesAlbum,
             "orphans": OrphansAlbum,
             "plain": PlainAlbum,
             "search": SearchAlbum,
@@ -1300,26 +1290,6 @@ class Shelf:
         self.orphanImagesCache = images
 
 
-    def _getAllAlbumsCache(self):
-        assert self.inTransaction
-        return self.allAlbumsCache
-
-
-    def _setAllAlbumsCache(self, albums):
-        assert self.inTransaction
-        self.allAlbumsCache = albums
-
-
-    def _getAllImagesCache(self):
-        assert self.inTransaction
-        return self.allImagesCache
-
-
-    def _setAllImagesCache(self, images):
-        assert self.inTransaction
-        self.allImagesCache = images
-
-
 class Category:
     """A Kofoto category."""
 
@@ -2032,85 +2002,6 @@ class MagicAlbum(Album):
         raise UnsettableChildrenError, self.getTag()
 
 
-class AllAlbumsAlbum(MagicAlbum):
-    """An album with all albums, sorted by tag."""
-
-    ##############################
-    # Public methods.
-
-    def getChildren(self):
-        """Get the album's children.
-
-        Returns an iterable returning the albums.
-        """
-        albums = self.shelf._getAllAlbumsCache()
-        if albums != None:
-            for album in albums:
-                yield album
-        else:
-            cursor = self.shelf._getConnection().cursor()
-            cursor.execute(
-                " select   albumid"
-                " from     album"
-                " order by tag")
-            albums = []
-            for (albumid,) in cursor:
-                album = self.shelf.getAlbum(albumid)
-                albums.append(album)
-                yield album
-            self.shelf._setAllAlbumsCache(albums)
-
-
-    def getAlbumChildren(self):
-        """Get the album's album children.
-
-        Returns an iterable returning the albums.
-        """
-        return self.getChildren()
-
-
-class AllImagesAlbum(MagicAlbum):
-    """An album with all images, sorted by capture timestamp."""
-
-    ##############################
-    # Public methods.
-
-    def getChildren(self):
-        """Get the album's children.
-
-        Returns an iterable returning the images.
-        """
-        images = self.shelf._getAllImagesCache()
-        if images != None:
-            for image in images:
-                yield image
-        else:
-            cursor = self.shelf._getConnection().cursor()
-            cursor.execute(
-                " select   imageid, hash, directory, filename, mtime,"
-                "          width, height"
-                " from     image left join attribute"
-                " on       imageid = objectid and name = 'captured'"
-                " order by lcvalue, directory, filename")
-            images = []
-            for (imageid, imghash, directory, filename, mtime, width,
-                 height) in cursor:
-                location = os.path.join(directory, filename)
-                image = self.shelf._imageFactory(
-                    imageid, imghash, location, mtime, width, height)
-                images.append(image)
-                yield image
-            self.shelf._setAllImagesCache(images)
-
-
-    def getAlbumChildren(self):
-        """Get the album's album children.
-
-        Returns an iterable returning the images.
-        """
-        return []
-
-
 class OrphansAlbum(MagicAlbum):
     """An album with all albums and images that are orphans."""
 
index 01e02a8..e04f454 100755 (executable)
@@ -69,8 +69,6 @@ class TestSearch(TestShelfFixture):
             (u"a or b or c or d", [self.images[0], self.images[1]]),
             (ur' ((a and not b) or @gazonk != "hej \"ju\"") and c ', [self.images[1]]),
             (u"/alpha and a", [self.images[0], self.images[1]]),
-            (u"/gamma", []),
-            (u"/delta", self.images),
             (u"/epsilon", []),
             (u"/zeta", [self.images[0], self.images[1]]),
             ]
index da05ea4..ef62737 100755 (executable)
@@ -263,11 +263,7 @@ class TestShelfFixture(unittest.TestCase):
         del children[-1] # The last image becomes orphaned.
         alpha.setChildren(children)
         beta.setChildren(list(beta.getChildren()) + [children[-1]])
-        root.setChildren(list(root.getChildren()) + [
-            alpha,
-            beta,
-            self.shelf.createAlbum(u"gamma", u"allalbums"),
-            self.shelf.createAlbum(u"delta", u"allimages")])
+        root.setChildren(list(root.getChildren()) + [alpha, beta])
         self.shelf.createAlbum(u"epsilon", u"plain") # Orphaned album.
         zeta = self.shelf.createAlbum(u"zeta", u"search")
         zeta.setAttribute(u"query", u"a")
@@ -296,20 +292,18 @@ class TestShelfMethods(TestShelfFixture):
 
     def test_getStatistics(self):
         s = self.shelf.getStatistics()
-        assert s["nalbums"] == 8
+        assert s["nalbums"] == 6
         assert s["nimages"] == 11
 
     def test_createdObjects(self):
         root = self.shelf.getRootAlbum()
         children = list(root.getChildren())
-        assert len(children) == 6
-        orphans, alpha, beta, gamma, delta, zeta = children
+        assert len(children) == 4
+        orphans, alpha, beta, zeta = children
         assert self.shelf.getObject(u"alpha") == alpha
         assert self.shelf.getAlbum(u"beta") == beta
         assert len(list(alpha.getChildren())) == 11
         assert len(list(beta.getChildren())) == 1
-        assert len(list(gamma.getChildren())) == 8
-        assert len(list(delta.getChildren())) == 11
 
     def test_createdAttributes(self):
         image = self.shelf.getImage(
@@ -345,7 +339,7 @@ class TestShelfMethods(TestShelfFixture):
 
     def test_getAllAlbums(self):
         albums = list(self.shelf.getAllAlbums())
-        assert len(albums) == 8
+        assert len(albums) == 6
 
     def test_getAllImages(self):
         images = list(self.shelf.getAllImages())
@@ -731,64 +725,6 @@ class TestImage(TestShelfFixture):
         image = self.shelf.getImage(os.path.join(PICDIR, "arlaharen.png"))
         image.importExifTags() # TODO: Test more.
 
-class TestAllAlbumsAlbum(TestShelfFixture):
-    def test_getType(self):
-        alpha = self.shelf.getAlbum(u"gamma")
-        assert alpha.getType() == "allalbums"
-
-    def test_isMutable(self):
-        alpha = self.shelf.getAlbum(u"gamma")
-        assert not alpha.isMutable()
-
-    def test_getChildren(self):
-        gamma = self.shelf.getAlbum(u"gamma")
-        assert len(list(gamma.getChildren())) == 8
-
-    def test_getAlbumChildren(self):
-        gamma = self.shelf.getAlbum(u"gamma")
-        assert list(gamma.getAlbumChildren()) == list(gamma.getChildren())
-
-    def test_setChildren(self):
-        gamma = self.shelf.getAlbum(u"gamma")
-        try:
-            gamma.setChildren([])
-        except UnsettableChildrenError:
-            pass
-        else:
-            assert False
-
-    def test_isAlbum(self):
-        assert self.shelf.getAlbum(u"gamma").isAlbum()
-
-class TestAllImagesAlbum(TestShelfFixture):
-    def test_getType(self):
-        alpha = self.shelf.getAlbum(u"delta")
-        assert alpha.getType() == "allimages"
-
-    def test_isMutable(self):
-        alpha = self.shelf.getAlbum(u"delta")
-        assert not alpha.isMutable()
-
-    def test_getChildren(self):
-        delta = self.shelf.getAlbum(u"delta")
-        assert len(list(delta.getChildren())) == 11
-
-    def test_getAlbumChildren(self):
-        delta = self.shelf.getAlbum(u"delta")
-        assert list(delta.getAlbumChildren()) == []
-
-    def test_setChildren(self):
-        delta = self.shelf.getAlbum(u"delta")
-        try:
-            delta.setChildren([])
-        except UnsettableChildrenError:
-            pass
-        else:
-            assert False
-
-    def test_isAlbum(self):
-        assert self.shelf.getAlbum(u"delta").isAlbum()
-
 class TestOrphansAlbum(TestShelfFixture):
     def test_getType(self):
         orphans = self.shelf.getAlbum(u"orphans")