dabo Commit
Revision 3082
Date: 2007-04-24 11:39:02 -0700 (Tue, 24 Apr 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3082

Changed:
U   trunk/dabo/lib/connParser.py
U   trunk/dabo/lib/utils.py

Log:
Improved a lot of the handling of paths. It is now possible to correctly 
resolve a relative path when the source file and the contained file are in 
different directories, while the app is running from a third directory.


Diff:
Modified: trunk/dabo/lib/connParser.py
===================================================================
--- trunk/dabo/lib/connParser.py        2007-04-24 18:33:44 UTC (rev 3081)
+++ trunk/dabo/lib/connParser.py        2007-04-24 18:39:02 UTC (rev 3082)
@@ -4,18 +4,21 @@
 import os.path
 from xmltodict import escQuote
 import dabo
+import dabo.lib.utils as utils
 
 
 class connHandler(xml.sax.ContentHandler):
        def __init__(self):
                self.connDict = {}
-               self.blankConn = {"name": "",
+               self.blankConn = {
+                               "name": "",
                                "dbtype" : "",
                                "host" : "",
                                "database" : "",
                                "user" : "",
                                "password" : "",
-                               "port" : ""             }
+                               "port" : 3306
+                               }
                self.currDict = self.blankConn.copy()
                self.element = None
                                
@@ -52,13 +55,22 @@
                return self.connDict
        
 
-def importConnections(file=None):
-       if file is None:
+def importConnections(pth=None):
+       if pth is None:
                return None
-       file = fileRef(file)
+       f = fileRef(pth)
        ch = connHandler()
-       xml.sax.parse(file, ch)
+       xml.sax.parse(f, ch)
        ret = ch.getConnectionDict()
+       
+       for cxn, data in ret.items():
+               for key, val in data.items():
+                       if key=="database":
+                               osp = os.path
+                               relpath = utils.resolvePath(val, pth, 
abspath=False)
+                               abspath = 
osp.abspath(osp.join(osp.split(pth)[0], relpath))
+                               if osp.exists(abspath):
+                                       ret[cxn][key] = abspath 
        return ret
 
 

Modified: trunk/dabo/lib/utils.py
===================================================================
--- trunk/dabo/lib/utils.py     2007-04-24 18:33:44 UTC (rev 3081)
+++ trunk/dabo/lib/utils.py     2007-04-24 18:39:02 UTC (rev 3082)
@@ -138,6 +138,8 @@
        """
        if fromLoc is None:
                fromLoc = os.getcwd()
+       if toLoc.startswith(".."):
+               toLoc = os.path.join(os.path.split(fromLoc)[0], toLoc)
        toLoc = os.path.abspath(toLoc)
        if os.path.isfile(toLoc):
                toDir, toFile = os.path.split(toLoc)
@@ -148,7 +150,7 @@
        if os.path.isfile(fromLoc):
                fromLoc = os.path.split(fromLoc)[0]
        fromList = fromLoc.split(os.path.sep)
-       toList = toDir.split(os.path.sep)       
+       toList = toDir.split(os.path.sep)
        # There can be empty strings from the split
        while len(fromList) > 0 and not fromList[0]:
                fromList.pop(0)
@@ -202,14 +204,18 @@
                atts[convKey] = relPath
 
 
-def resolvePath(val, pth=None):
+def resolvePath(val, pth=None, abspath=False):
        """Takes a single string value in the format Dabo uses to store pathing
        in XML, and returns the original path relative to the specified path 
(or the
-       current directory, if no pth is specified).
+       current directory, if no pth is specified). If 'abspath' is True, 
returns an
+       absolute path instead of the default relative path.
        """
        prfx = getPathAttributePrefix()
        # Strip the path designator
        val = val.replace(prfx, "")
        # Convert to relative path
-       return relativePath(val, pth)
+       ret = relativePath(val, pth)
+       if abspath:
+               ret = os.path.abspath(ret)
+       return ret
 





_______________________________________________
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/dabo-dev/[EMAIL PROTECTED]

Reply via email to