packages: pynapi/pynapi.py - handle exceptions

areq areq at pld-linux.org
Sun Feb 28 21:55:25 CET 2010


Author: areq                         Date: Sun Feb 28 20:55:24 2010 GMT
Module: packages                      Tag: HEAD
---- Log message:
- handle exceptions

---- Files affected:
packages/pynapi:
   pynapi.py (1.38 -> 1.39) 

---- Diffs:

================================================================
Index: packages/pynapi/pynapi.py
diff -u packages/pynapi/pynapi.py:1.38 packages/pynapi/pynapi.py:1.39
--- packages/pynapi/pynapi.py:1.38	Sun Feb 28 00:54:09 2010
+++ packages/pynapi/pynapi.py	Sun Feb 28 21:55:19 2010
@@ -102,8 +102,7 @@
     try:
         d.update(open(file).read(10485760))
     except (IOError, OSError), e:
-        print >> sys.stderr, "%s: %d/%d: Hashing video file failed: %s" % (prog, i, i_total, e)
-        return None
+        raise Exception('Hashing video file failed: %s' % ( e ))
     return d.hexdigest()
 
 def get_subtitle(digest, lang="PL"):
@@ -112,6 +111,7 @@
     repeat = 3
     sub = None
     http_code = 200
+    error = "Fetching subtitle failed:"
     while repeat > 0:
         repeat = repeat - 1
         try:
@@ -120,20 +120,23 @@
                 http_code = sub.getcode() 
             sub = sub.read()
         except (IOError, OSError), e:
-            print >> sys.stderr, "%s: %d/%d: Fetching subtitle failed: %s" % (prog, i, i_total, e)
+            error = error + " %s" % (e)
             time.sleep(0.5)
             continue
     
         if http_code != 200:
-            print >> sys.stderr, "%s: %d/%d: Fetching subtitle failed, HTTP code: %s" % (prog, i, i_total, str(http_code))
+            error = error + ",HTTP code: %s" % (str(http_code))
             time.sleep(0.5)
             continue
     
         if sub.startswith('NPc'):
-            print >> sys.stderr, "%s: %d/%d: Subtitle NOT FOUND" % (prog, i, i_total)
-            repeat = -1
-            continue
-
+    	    raise Exception('Subtitle NOT FOUND')
+    	    
+    	repeat = 0
+
+    if sub is None or sub == "":
+	raise Exception(error)
+	
     return sub
 
 def main(argv=sys.argv):
@@ -220,16 +223,12 @@
 
         print >> sys.stderr, "%s: %d/%d: Processing subtitle for %s" % (prog, i, i_total, file)
 
-        digest = calculate_digest(file)
-        
-        if digest is None:
-            continue
-    	
-    	sub = get_subtitle(digest, languages[lang])
-
-        if sub is None or sub == "":
-            print >> sys.stderr, "%s: %d/%d: Subtitle download FAILED" % (prog, i, i_total)
-            continue
+	try:
+	    digest = calculate_digest(file)
+	    sub = get_subtitle(digest, languages[lang])
+	except:
+	    print >> sys.stderr, "%s: %d/%d: %s" % (prog, i, i_total, sys.exc_info()[1])
+	    continue
 
         fp = open(vfile, 'w')
         fp.write(sub)
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/pynapi/pynapi.py?r1=1.38&r2=1.39&f=u



More information about the pld-cvs-commit mailing list