Changeset 179

Show
Ignore:
Timestamp:
07/22/08 15:07:27 (5 months ago)
Author:
apdavison
Message:

facets.fkbtools.getZipURL() sometimes has problems when accessing the FKB via https rather than srb. The problem seems to be related to too-frequent requests. getZipURL() now checks that the file has been unzipped correctly, and repeats the request until success or timeout.

However, a better solution would seem to be to install the srb module!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/facets/fkbtools.py

    r176 r179  
    2323import tables 
    2424import logging 
     25import time 
    2526 
    2627def getFromURL(url): 
     
    4041    Return the temporary directory. 
    4142    """ 
    42     logging.debug('  getZipURL("%s")' % url) 
    43     localfilepath = getFromURL(url) 
    44     tmpdir = os.path.dirname(localfilepath) 
    45     logging.debug('  run process: "unzip -o -q %s -d %s"' % (localfilepath,tmpdir)) 
    46     p = subprocess.Popen("unzip -o -q %s -d %s" % (localfilepath,tmpdir), shell=True, 
    47                          stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
    48     success = p.wait() 
     43    TIMEOUT = 30 # seconds 
     44    SLEEP = 1 # seconds 
     45    success = -1 
     46    start_time = time.time() 
     47    while success != 0: 
     48        if time.time()-start_time > TIMEOUT: 
     49            raise Exception("Timeout when trying to get zipfile from %s" % url) 
     50        logging.debug('  getZipURL("%s")' % url) 
     51        localfilepath = getFromURL(url) 
     52        tmpdir = os.path.dirname(localfilepath) 
     53        logging.debug('  run process: "unzip -o -q %s -d %s"' % (localfilepath,tmpdir)) 
     54        p = subprocess.Popen("unzip -o -q %s -d %s" % (localfilepath,tmpdir), shell=True, 
     55                             stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
     56        success = p.wait() 
     57        if success != 0: 
     58            logging.warning("Problem unzipping file: %s %s.\nRetrying %s." % (p.stdout.read(), p.stderr.read(), url)) 
     59            time.sleep(SLEEP) 
     60            SLEEP *= 2 
    4961    return tmpdir 
    5062 
     
    149161            pass 
    150162    tmpdir = getZipURL(url) 
    151     topdir = os.path.join(tmpdir,[f for f in os.listdir(tmpdir) if f.find(".zip") < 0 and f.find("MACOSX") < 0][0]) 
    152      
    153      
     163    dirlist = [f for f in os.listdir(tmpdir) if f.find(".zip") < 0 and f.find("MACOSX") < 0] 
     164    if len(dirlist) == 1: 
     165        topdir = os.path.join(tmpdir, dirlist[0]) 
     166    else: 
     167        raise Exception("Problem obtaining stimulus. Contents of %s: %s" % (tmpdir, os.listdir(tmpdir))) 
    154168    frame_list = (os.path.join(topdir,"frames"),topdir) 
    155169    f = open(os.path.join(topdir,"parameters"),'r') # parameteters should contain the frame_duration parameter 
  • trunk/src/facets/srblib.py

    r176 r179  
    168168        def close(self): 
    169169            srb.obj_close(self.server.cid,self.srb_fid) 
    170              
    171  
    172  
     170             
    173171 
    174172except ImportError: 
     
    216214            print ('sending request /SRB/SRBManageFiles?action=getChildren&subDir=%s/%s' % (self._root,self.pwd)) 
    217215            conn.putheader('Accept', 'text/html') 
    218            conn.putheader('Accept', 'text/xml') 
     216            conn.putheader('Accept', 'text/xml') 
    219217            conn.putheader('Accept', 'text/plain') 
    220218            conn.putheader("Authorization",self._auth) 
  • trunk/src/spikes.py

    r157 r179  
    344344        for id,spikes in self.spiketrains.items(): # 
    345345            self.spiketrains[id] = SpikeTrain(spike_times=spikes, dt=self.dt, t_start=self.t_start, t_stop=self.t_stop) 
    346         if self.t_start is None or self.t_stop is None
     346        if len(self) > 0 and (self.t_start is None or self.t_stop is None)
    347347            self.__calc_startstop() 
    348348 
     
    373373        assert isinstance(val, SpikeTrain), "A SpikeList object can only contain SpikeTrain objects" 
    374374        self.spiketrains[i] = val 
     375        self.id_list.append(i) 
    375376        self.__calc_startstop() 
    376377