Changeset 3172 in products


Ignore:
Timestamp:
Apr 22, 2011 11:17:59 AM (13 years ago)
Author:
kroman0
Message:

Fixed problems with index downtime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.distrpoxy/trunk/quintagroup/distproxy/wsgi.py

    r1813 r3172  
    1010import urllib2 
    1111 
     12FILES = ['ico','txt','tgz','.gz','egg','zip','exe','cfg'] 
     13 
    1214 
    1315class PackageProxyApp(object): 
    1416 
    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): 
    1619        if not index_url:  
    1720            print "No repository index provided" 
     
    3134            opener = urllib2.build_opener(handler) 
    3235            urllib2.install_opener(opener) 
     36        if stimeout: 
     37            socket.setdefaulttimeout(float(stimeout)) 
    3338        self.index_url = index_url 
    3439        self.pack_dir = pack_dir 
     40        self.ptimeout = ptimeout or 3600 
    3541 
    3642    def __call__(self, environ, start_response): 
     
    4854        """check if we already have the file and download it if not"""    
    4955        pth = self.pack_dir + path 
    50         index =0  
    51         if not (path[-3:] in ['ico','txt','tgz','.gz','egg','zip','exe','cfg']):  
     56        index = 0  
     57        if not (path[-3:] in FILES):  
    5258            if not os.path.exists(pth): 
    53               os.makedirs(pth) #create dir if it is not there 
     59                os.makedirs(pth) # create dir if it is not there 
    5460            # add index.html for supposedly folders 
    5561            pth = pth + 'index.html' 
     
    5864            pth1 = '/'.join(pth.split('/')[:-1]) 
    5965            if not os.path.exists(pth1): 
    60               os.makedirs(pth1)#create parent dir if it is not there 
     66                os.makedirs(pth1) # create parent dir if it is not there 
    6167        url = self.index_url+path 
    6268        #if we dont have download it 
     
    6773            lf.close() 
    6874        #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       
    7483        return pth 
    7584 
     
    8291    password = local_conf.get('password', None) 
    8392    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) 
    8596 
    8697class StaticURLParser(urlparser.StaticURLParser): 
Note: See TracChangeset for help on using the changeset viewer.