Changeset 4234

Show
Ignore:
Timestamp:
07/04/2008 12:45:31 PM (2 months ago)
Author:
ed
Message:

Updated dApp to optionall raise a 404 Not Found error if a requested file is not found from urlFetch(). Also fixed a potential bug in which setting the SourceURL property could get erased by the init code in dApp.

Updated the resolvePathAndUpdate() method of dabo.ui to also check for code files when updating a .cdxml file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dApp.py

    r4226 r4234  
    222222        # Form to open if no forms were passed as a parameter 
    223223        self.default_form = None 
    224         # For web-enabled apps, this is the base URL from which the source 
    225         # files wil be retrieved 
    226         self._sourceURL = "" 
    227224        # Dict of "Last-Modified" values for dynamic web resources 
    228225        self._sourceLastModified = {} 
     
    614611 
    615612 
    616     def urlFetch(self, pth): 
     613    def urlFetch(self, pth, errorOnNotFound=False): 
    617614        """Fetches the specified resource from the internet using the SourceURL value 
    618615        as the base for the resource URL. If a newer version is found, the local copy 
    619         is updated with the retrieved resource. 
     616        is updated with the retrieved resource. If the resource isn't found, nothing  
     617        happens by default. If you want the error to be raised, pass True for the  
     618        parameter 'errorOnNotFound'. 
    620619        """ 
    621620        base = self.SourceURL 
     
    624623            return 
    625624        u2 = urllib2 
    626         # os.path.join works great for this 
    627         url = os.path.join(self.SourceURL, pth) 
     625        # os.path.join works great for this; just make sure that the  
     626        # pth value doesn't begin with a slash 
     627        url = os.path.join(self.SourceURL, pth.lstrip("/")) 
    628628        req = u2.Request(url) 
    629629        lastmod = self._sourceLastModified.get(url) 
     
    640640            if code in (304, 404): 
    641641                # Not changed or not found; nothing to do 
     642                if code == 404 and errorOnNotFound: 
     643                    # Re-raise the error 
     644                    raise u2.HTTPError, e 
    642645                return 
    643646        newFile = resp.read() 
     
    13301333             
    13311334    def _getSourceURL(self): 
    1332         return self._sourceURL 
     1335        try: 
     1336            return self._sourceURL 
     1337        except AttributeError: 
     1338            self._sourceURL = "" 
     1339            return self._sourceURL 
    13331340 
    13341341    def _setSourceURL(self, val): 
  • trunk/dabo/ui/uiwx/__init__.py

    r4196 r4234  
    10881088            # The srcFile has an absolute path; the URLs work on relative. 
    10891089            try: 
    1090                 splt = srcFile.split(cwd)[1] 
     1090                splt = srcFile.split(cwd)[1].lstrip("/") 
    10911091            except IndexError: 
    10921092                splt = srcFile 
    10931093            app.urlFetch(splt) 
     1094            try: 
     1095                nm, ext = os.path.splitext(splt) 
     1096            except ValueError: 
     1097                # No extension; skip it 
     1098                nm = ext = "" 
     1099            if ext == ".cdxml": 
     1100                # There might be an associated code file. If not, the error 
     1101                # will be caught in the app method, and no harm will be done. 
     1102                codefile = "%s-code.py" % nm 
     1103                app.urlFetch(codefile) 
    10941104    # At this point the file should be present and updated. If not... 
    10951105    if not os.path.exists(srcFile):