Changeset 3172 in products for quintagroup.distrpoxy/trunk
- Timestamp:
- Apr 22, 2011 11:17:59 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.distrpoxy/trunk/quintagroup/distproxy/wsgi.py
r1813 r3172 10 10 import urllib2 11 11 12 FILES = ['ico','txt','tgz','.gz','egg','zip','exe','cfg'] 13 12 14 13 15 class PackageProxyApp(object): 14 16 15 def __init__(self, index_url=None, pack_dir=None, username=None,password=None,realm=None): 17 def __init__(self, index_url=None, pack_dir=None, username=None, 18 password=None, realm=None, stimeout=None, ptimeout=None): 16 19 if not index_url: 17 20 print "No repository index provided" … … 31 34 opener = urllib2.build_opener(handler) 32 35 urllib2.install_opener(opener) 36 if stimeout: 37 socket.setdefaulttimeout(float(stimeout)) 33 38 self.index_url = index_url 34 39 self.pack_dir = pack_dir 40 self.ptimeout = ptimeout or 3600 35 41 36 42 def __call__(self, environ, start_response): … … 48 54 """check if we already have the file and download it if not""" 49 55 pth = self.pack_dir + path 50 index = 051 if not (path[-3:] in ['ico','txt','tgz','.gz','egg','zip','exe','cfg']):56 index = 0 57 if not (path[-3:] in FILES): 52 58 if not os.path.exists(pth): 53 os.makedirs(pth) #create dir if it is not there59 os.makedirs(pth) # create dir if it is not there 54 60 # add index.html for supposedly folders 55 61 pth = pth + 'index.html' … … 58 64 pth1 = '/'.join(pth.split('/')[:-1]) 59 65 if not os.path.exists(pth1): 60 os.makedirs(pth1)#create parent dir if it is not there66 os.makedirs(pth1) # create parent dir if it is not there 61 67 url = self.index_url+path 62 68 #if we dont have download it … … 67 73 lf.close() 68 74 #if we have the index.html file if it is older the 1 hour update 69 elif index and int(time()) - os.path.getmtime(pth) > 3600: 70 f = urllib2.urlopen(url) 71 lf = open(pth,'wb') 72 lf.write(f.read()) 73 lf.close() 75 elif index and int(time()) - os.path.getmtime(pth) > self.ptimeout: 76 try: 77 f = urllib2.urlopen(url) 78 lf = open(pth,'wb') 79 lf.write(f.read()) 80 lf.close() 81 except urllib2.URLError: 82 pass 74 83 return pth 75 84 … … 82 91 password = local_conf.get('password', None) 83 92 realm = local_conf.get('realm', None) 84 return PackageProxyApp(index_url, pack_dir, username, password, realm) 93 stimeout = local_conf.get('stimeout', None) 94 ptimeout = local_conf.get('ptimeout', None) 95 return PackageProxyApp(index_url, pack_dir, username, password, realm, stimeout, ptimeout) 85 96 86 97 class StaticURLParser(urlparser.StaticURLParser):
Note: See TracChangeset
for help on using the changeset viewer.