SOURCES: pynapi.py Retry on some failures.
arekm
arekm at pld-linux.org
Tue Apr 21 22:52:56 CEST 2009
Author: arekm Date: Tue Apr 21 20:52:56 2009 GMT
Module: SOURCES Tag: HEAD
---- Log message:
Retry on some failures.
---- Files affected:
SOURCES:
pynapi.py (1.27 -> 1.28)
---- Diffs:
================================================================
Index: SOURCES/pynapi.py
diff -u SOURCES/pynapi.py:1.27 SOURCES/pynapi.py:1.28
--- SOURCES/pynapi.py:1.27 Wed Feb 18 18:29:11 2009
+++ SOURCES/pynapi.py Tue Apr 21 22:52:51 2009
@@ -22,6 +22,7 @@
import urllib
import subprocess
import tempfile
+import time
import os
import getopt
@@ -151,23 +152,38 @@
url = "http://napiprojekt.pl/unit_napisy/dl.php?l=%s&f=%s&t=%s&v=other&kolejka=false&nick=&pass=&napios=%s" % \
(languages[lang], d.hexdigest(), f(d.hexdigest()), os.name)
+ repeat = 3
sub = None
http_code = 200
- try:
- sub = urllib.urlopen(url)
- if hasattr(sub, 'getcode'):
- 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)
- continue
+ while repeat > 0:
+ repeat = repeat - 1
+ try:
+ sub = urllib.urlopen(url)
+ if hasattr(sub, 'getcode'):
+ 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)
+ 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))
+ 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
+
+ repeat = 0
- if http_code != 200:
- print >> sys.stderr, "%s: %d/%d: Fetching subtitle failed, HTTP code: %s" % (prog, i, i_total, str(http_code))
+ if sub is None or sub == "":
+ print >> sys.stderr, "%s: %d/%d: Subtitle download FAILED" % (prog, i, i_total)
continue
- if sub.startswith('NPc'):
- print >> sys.stderr, "%s: %d/%d: Subtitle NOT FOUND" % (prog, i, i_total)
+ if repeat == -1:
continue
fp = tempfile.NamedTemporaryFile('wb', suffix=".7z")
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/pynapi.py?r1=1.27&r2=1.28&f=u
More information about the pld-cvs-commit
mailing list