From: Michael Hanke Date: Thu, 21 Jan 2010 12:46:23 +0000 (-0500) Subject: Be nicer with DDE and cope with DOS protection. X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2ee0671952d70559cd66996e115b8ef33a4b1bd4;p=neurodebian.git Be nicer with DDE and cope with DOS protection. Refused requests are asked again after 30 seconds delay. Moreover, any request is now delayed by 3 seconds. --- diff --git a/neurodebian/dde.py b/neurodebian/dde.py index 927988f..729b799 100644 --- a/neurodebian/dde.py +++ b/neurodebian/dde.py @@ -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