[SCM] morituri/master: * examples/trm.py: Allow loading and saving fingerprints from a pickle.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:08:50 UTC 2014


The following commit has been merged in the master branch:
commit 5b0bfd442280bba475250d4b51d6ccd28f160005
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Fri May 1 12:30:14 2009 +0000

    	* examples/trm.py:
    	  Allow loading and saving fingerprints from a pickle.

diff --git a/ChangeLog b/ChangeLog
index cc539a4..d75f957 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-05-01  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* examples/trm.py:
+	  Allow loading and saving fingerprints from a pickle.
+
+2009-05-01  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/image/toc.py:
 	* morituri/test/test_image_toc.py:
 	* morituri/test/bloc.toc (added):
diff --git a/examples/trm.py b/examples/trm.py
index fcad93e..e5e7e4a 100644
--- a/examples/trm.py
+++ b/examples/trm.py
@@ -23,6 +23,9 @@
 import os
 import sys
 import optparse
+import tempfile
+import pickle
+import shutil
 
 import gobject
 gobject.threads_init()
@@ -45,6 +48,30 @@ def gtkmain(runner, taskk):
 def climain(runner, taskk):
     runner.run(taskk)
 
+class Listener(object):
+    def __init__(self, path):
+        self.path = path
+        self.trms = {}
+
+    def progressed(self, task, value):
+        pass
+
+    def described(self, task, description):
+        pass
+
+    def started(self, task):
+        pass
+
+    def stopped(self, task):
+        self.trms[task.path] = task.trm
+        print task.path, task.trm
+
+        (fd, path) = tempfile.mkstemp(suffix='.morituri')
+        handle = os.fdopen(fd, 'wb')
+        pickle.dump(self.trms, handle, 2)
+        handle.close()
+        shutil.move(path, self.path)
+
 
 def main(argv):
     parser = optparse.OptionParser()
@@ -57,6 +84,9 @@ def main(argv):
     parser.add_option('-p', '--playlist',
         action="store", dest="playlist",
         help="playlist to analyze files from")
+    parser.add_option('-P', '--pickle',
+        action="store", dest="pickle",
+        help="pickle to store trms to")
 
 
     options, args = parser.parse_args(argv[1:])
@@ -68,9 +98,28 @@ def main(argv):
         paths.extend(open(options.playlist).readlines())
 
     mtask = task.MultiCombinedTask()
+    listener = None
+    trms = {}
+    if options.pickle:
+        listener = Listener(options.pickle)
+        print 'Opening pickle %s' % options.pickle
+        handle = open(options.pickle)
+        try:
+            trms = pickle.load(handle)
+        except Exception, e:
+            sys.stderr.write(
+                "Pickle file '%s' cannot be loaded.\n" % options.pickle)
+            sys.exit(1)
+
+        handle.close()
+
     for path in paths:
         path = path.rstrip()
+        if path in trms.keys():
+            continue
         trmtask = checksum.TRMTask(path)
+        if listener:
+            trmtask.addListener(listener)
         mtask.addTask(trmtask)
     mtask.description = 'Fingerprinting files'
 

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list