[SCM] morituri/master: * morituri/common/cache.py: * morituri/rip/debug.py: * morituri/test/test_common_cache.py: Add rip debug resultcache list to list cached results.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:47 UTC 2014


The following commit has been merged in the master branch:
commit 306e6f2ad73936e77bde442890b690ba5e415188
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sun Dec 2 17:27:15 2012 +0000

    	* morituri/common/cache.py:
    	* morituri/rip/debug.py:
    	* morituri/test/test_common_cache.py:
    	  Add rip debug resultcache list to list cached results.

diff --git a/ChangeLog b/ChangeLog
index 277b19d..7768ce1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2012-12-02  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/cache.py:
+	* morituri/rip/debug.py:
+	* morituri/test/test_common_cache.py:
+	  Add rip debug resultcache list to list cached results.
+
+2012-12-02  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/common/cache.py (added):
 	* morituri/test/cache (added):
 	* morituri/test/cache/result (added):
diff --git a/morituri/common/cache.py b/morituri/common/cache.py
index 3e372f4..f0147bf 100644
--- a/morituri/common/cache.py
+++ b/morituri/common/cache.py
@@ -22,6 +22,7 @@
 
 import os
 import os.path
+import glob
 import tempfile
 import shutil
 
@@ -175,3 +176,9 @@ class ResultCache(log.Loggable):
                 cddbdiscid)
 
         return presult
+
+    def getIds(self):
+        paths = glob.glob(os.path.join(self._path, '*.pickle'))
+
+        return [os.path.splitext(os.path.basename(path))[0] for path in paths]
+        
diff --git a/morituri/rip/debug.py b/morituri/rip/debug.py
index ff7dda2..8ae8342 100644
--- a/morituri/rip/debug.py
+++ b/morituri/rip/debug.py
@@ -22,7 +22,36 @@
 
 from morituri.common import logcommand
 
-from morituri.common import task
+from morituri.common import task, cache
+
+
+class RCList(logcommand.LogCommand):
+
+    name = "list"
+    summary = "list cached results"
+
+    def do(self, args):
+        self._cache = cache.ResultCache()
+        results = []
+
+        for i in self._cache.getIds():
+            r = self._cache.getRipResult(i)
+            results.append((r.object.artist, r.object.title, i))
+
+        results.sort()
+
+        for artist, title, cddbid in results:
+            self.stdout.write('%s: %s - %s\n' % (
+                cddbid, artist, title))
+        
+
+
+class ResultCache(logcommand.LogCommand):
+
+    summary = "debug result cache"
+    aliases = ['rc', ]
+
+    subCommandClasses = [RCList, ]
 
 
 class Checksum(logcommand.LogCommand):
@@ -117,4 +146,4 @@ class Debug(logcommand.LogCommand):
 
     summary = "debug internals"
 
-    subCommandClasses = [Checksum, Encode, MusicBrainzNGS]
+    subCommandClasses = [Checksum, Encode, MusicBrainzNGS, ResultCache]
diff --git a/morituri/test/test_common_cache.py b/morituri/test/test_common_cache.py
index 6dfe87d..55460a5 100644
--- a/morituri/test/test_common_cache.py
+++ b/morituri/test/test_common_cache.py
@@ -14,6 +14,10 @@ class ResultCacheTestCase(tcommon.TestCase):
         self.cache = cache.ResultCache(
             os.path.join(os.path.dirname(__file__), 'cache', 'result'))
 
-    def testGet(self):
+    def testGetResult(self):
         result = self.cache.getRipResult('fe105a11')
         self.assertEquals(result.object.title, "The Writing's on the Wall")
+
+    def testGetIds(self):
+        ids = self.cache.getIds()
+        self.assertEquals(ids, ['fe105a11'])

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list