dabo Commit
Revision 4234
Date: 2008-07-04 12:45:31 -0700 (Fri, 04 Jul 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4234

Changed:
U   trunk/dabo/dApp.py
U   trunk/dabo/ui/uiwx/__init__.py

Log:
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.


Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py  2008-07-04 17:14:02 UTC (rev 4233)
+++ trunk/dabo/dApp.py  2008-07-04 19:45:31 UTC (rev 4234)
@@ -221,9 +221,6 @@
                self.formsToOpen = []  
                # Form to open if no forms were passed as a parameter
                self.default_form = None
-               # For web-enabled apps, this is the base URL from which the 
source
-               # files wil be retrieved
-               self._sourceURL = ""
                # Dict of "Last-Modified" values for dynamic web resources
                self._sourceLastModified = {}
 
@@ -613,18 +610,21 @@
                return (self._frameworkPrefs.web_update, 
self._frameworkPrefs.update_interval)
 
 
-       def urlFetch(self, pth):
+       def urlFetch(self, pth, errorOnNotFound=False):
                """Fetches the specified resource from the internet using the 
SourceURL value
                as the base for the resource URL. If a newer version is found, 
the local copy
-               is updated with the retrieved resource.
+               is updated with the retrieved resource. If the resource isn't 
found, nothing 
+               happens by default. If you want the error to be raised, pass 
True for the 
+               parameter 'errorOnNotFound'.
                """
                base = self.SourceURL
                if not base:
                        # Nothing to do
                        return
                u2 = urllib2
-               # os.path.join works great for this
-               url = os.path.join(self.SourceURL, pth)
+               # os.path.join works great for this; just make sure that the 
+               # pth value doesn't begin with a slash
+               url = os.path.join(self.SourceURL, pth.lstrip("/"))
                req = u2.Request(url)
                lastmod = self._sourceLastModified.get(url)
                resp = None
@@ -639,6 +639,9 @@
                        code = e.code
                        if code in (304, 404):
                                # Not changed or not found; nothing to do
+                               if code == 404 and errorOnNotFound:
+                                       # Re-raise the error
+                                       raise u2.HTTPError, e
                                return
                newFile = resp.read()
                if newFile:
@@ -1329,7 +1332,11 @@
 
                        
        def _getSourceURL(self):
-               return self._sourceURL
+               try:
+                       return self._sourceURL
+               except AttributeError:
+                       self._sourceURL = ""
+                       return self._sourceURL
 
        def _setSourceURL(self, val):
                self._sourceURL = val

Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py      2008-07-04 17:14:02 UTC (rev 4233)
+++ trunk/dabo/ui/uiwx/__init__.py      2008-07-04 19:45:31 UTC (rev 4234)
@@ -1087,10 +1087,20 @@
                if app.SourceURL:
                        # The srcFile has an absolute path; the URLs work on 
relative.
                        try:
-                               splt = srcFile.split(cwd)[1]
+                               splt = srcFile.split(cwd)[1].lstrip("/")
                        except IndexError:
                                splt = srcFile
                        app.urlFetch(splt)
+                       try:
+                               nm, ext = os.path.splitext(splt)
+                       except ValueError:
+                               # No extension; skip it
+                               nm = ext = ""
+                       if ext == ".cdxml":
+                               # There might be an associated code file. If 
not, the error
+                               # will be caught in the app method, and no harm 
will be done.
+                               codefile = "%s-code.py" % nm
+                               app.urlFetch(codefile)
        # At this point the file should be present and updated. If not...
        if not os.path.exists(srcFile):
                raise IOError, _("The file '%s' cannot be found") % srcFile




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to