]> git.donarmstrong.com Git - neurodebian.git/commitdiff
Be nicer with DDE and cope with DOS protection.
authorMichael Hanke <michael.hanke@gmail.com>
Thu, 21 Jan 2010 12:46:23 +0000 (07:46 -0500)
committerMichael Hanke <michael.hanke@gmail.com>
Thu, 21 Jan 2010 12:46:23 +0000 (07:46 -0500)
Refused requests are asked again after 30 seconds delay. Moreover, any
request is now delayed by 3 seconds.

neurodebian/dde.py

index 927988f12bad59f1859aebe559847c9b82711928..729b7997c3e9b830cb5cbc7e042306d45e01cab3 100644 (file)
@@ -15,6 +15,7 @@ import urllib2
 import urllib
 import codecs
 import subprocess
+import time
 # templating
 from jinja2 import Environment, PackageLoader
 
@@ -385,11 +386,26 @@ def create_dir(path):
             os.mkdir(p)
 
 
-def dde_get(url):
+def dde_get(url, fail=False):
+    # enforce delay to be friendly to DDE
+    time.sleep(3)
     try:
-        return json.read(urllib2.urlopen(url+"?t=json").read())['r']
-    except (urllib2.HTTPError, StopIteration, urllib2.URLError):
-        print "NO PKG INFO AT:", url
+        data = json.read(urllib2.urlopen(url+"?t=json").read())['r']
+        print "SUCCESS:", url
+        return data
+    except urllib2.HTTPError, e:
+        print "NOINFO:", url, type(e)
+        return False
+    except urllib2.URLError, e:
+        print "URLERROR:", url, type(e)
+        if fail:
+            print "Permanant failure"
+            return False
+        print "Try again after 30 seconds..."
+        time.sleep(30)
+        return dde_get(url, fail=True)
+    except (StopIteration):
+        print "NOINFO:", url
         return False