]> diplodocus.org Git - flac-archive/blobdiff - fa-flacd
Commit a bunch of state sitting around in the old bzr checkout!
[flac-archive] / fa-flacd
index 8166b945b2845101bc9cd4e0ad8b0a9e0f1f2159..5716223f8c5b360c4e5fa58e1760fca23fd69fae 100755 (executable)
--- a/fa-flacd
+++ b/fa-flacd
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/python2
 
 """
 =head1 NAME
@@ -85,19 +85,12 @@ from errno import EEXIST, ENOENT
 from glob import glob
 from optparse import OptionParser
 
-from flac_archive.tags import Tags
+import org.diplodocus.jobs
+from org.diplodocus.structures import ListDictDict
+from org.diplodocus.util import die, flatten, nothing
+from org.diplodocus.util import catch_EnvironmentError as c
 
-def c(f, *args):
-    try:
-        return f(*args)
-    except EnvironmentError, error:
-        error.msg = '%s.%s(%s): ' % (f.__module__, f.__name__,
-                                     ', '.join(map(str, args)))
-        raise
-
-def die(e, *args):
-    sys.stderr.write(''.join(args))
-    sys.exit(e)
+from flac_archive.tags import Tags
 
 def spew(*args):
     if verbose:
@@ -165,7 +158,12 @@ def flac(dir, tracknum, tags):
         run_flac('wav', 'cue', '/'.join(['..', artist, outfile]), tags.all())
         files = ['%s/%s.flac' % (artist, outfile)]
 
-        c(os.unlink, 'cue')
+        try:
+            c(os.unlink, 'cue')
+        except EnvironmentError, error:
+            if error.errno != ENOENT:
+                raise error
+
         outlog = '/'.join(['..', artist, outfile + '.log'])
         c(os.rename, 'log', outlog)
     else:
@@ -290,8 +288,11 @@ def flacloop(maxjobs):
                     return 1
             return lamb
 
-    while True:
-        status = getjob(lambda *a,**k: None)()
+    def notify_start(pid, jobs):
+        # make this print '2 jobs; start 378 for Artist/01 Title.flac'
+        spew('%d jobs; start %d for %s\n' % (len(jobs), pid, dir[0]))
+
+    def notify_finish(pid, status, jobs):
         spew('%d jobs; %d finished (' % (len(jobs), pid))
         if os.WIFEXITED(status):
             spew('exited with status ', str(os.WEXITSTATUS(status)))
@@ -301,6 +302,12 @@ def flacloop(maxjobs):
             spew('stopped with signal ', str(os.WSTOPSIG(status)))
         spew(')\n')
 
+    # Never returns (see getjob comment).
+    org.diplodocus.jobs.run(maxjobs=maxjobs, debug=debug,
+                            get_job=getjob,
+                            notify_start=notify_start,
+                            notify_finish=notify_finish)
+
 def main(argv):
     # Control the exit code for any uncaught exceptions.
     try: