dabo Commit
Revision 5557
Date: 2009-12-19 10:13:48 -0800 (Sat, 19 Dec 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5557
Changed:
U trunk/dabo/dApp.py
U trunk/dabo/lib/DesignerXmlConverter.py
U trunk/dabo/lib/utils.py
Log:
Fixed the issues with custom classes in the Class Designer not being properly
inherited when running inside other class designs. The problem came down to
pathing, as have most similar issues, so I approached it by adding some smarter
pathing code.
There is now a method in lib.utils named 'locateRelativeTo()' that will take a
main file and a target file, and try to find the target file, using the main
file's location as a starting point. It will also look in the standard
subdirectories of a typical Dabo application for the target file. If found, it
returns the full path to the target. If not, it returns the original target
file path.
I also consolidated the logic for app standard directories. Recent changes had
not kept the different locations where they were referenced in sync, so now
there is an attribute of dApp called '_standardDirs' that is a tuple of the
subdirectory names. There is also now a method of dApp called
'getStandardDirectories()' that will return a tuple containing the
HomeDirectory and the full paths to all these subdirectories.
Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2009-12-17 14:13:35 UTC (rev 5556)
+++ trunk/dabo/dApp.py 2009-12-19 18:13:48 UTC (rev 5557)
@@ -177,6 +177,9 @@
if dabo.settings.loadUserLocale:
locale.setlocale(locale.LC_ALL, '')
+ # Subdirectories that make up a standard Dabo app
+ self._standardDirs = ("biz", "cache", "db", "lib", "reports",
"resources", "test", "ui")
+
self._uiAlreadySet = False
dabo.dAppRef = self
self._beforeInit()
@@ -940,7 +943,7 @@
currsyspath = sys.path
if not currdir in sys.path:
sys.path.insert(0, currdir)
- for dd in ("biz", "db", "ui", "lib", "resources", "reports"):
+ for dd in self._standardDirs:
currmod = getattr(self, dd, None)
if sys.version.split()[0].split(".") >= ["2", "5"]:
try:
@@ -956,6 +959,14 @@
sys.path = currsyspath
+ def getStandardDirectories(self):
+ """Return a tuple of the fullpath to each standard directory"""
+ hd = self.HomeDirectory
+ subdirs = [os.path.join(hd, dd) for dd in self._standardDirs]
+ subdirs.insert(0, hd)
+ return tuple(subdirs)
+
+
def _initUI(self):
""" Set the user-interface library for the application. Ignored
if the UI was already explicitly set by user code.
@@ -1049,7 +1060,7 @@
If a starting file path is provided, use that first. If not,
use the
HomeDirectory as the starting point.
"""
- stdDirs = ("biz", "cache", "db", "main.py", "reports",
"resources", "test", "ui")
+ stdDirs = self._standardDirs + ("main.py", )
if dirname not in stdDirs:
dabo.errorLog.write(_("Non-standard directory '%s'
requested") % dirname)
return None
Modified: trunk/dabo/lib/DesignerXmlConverter.py
===================================================================
--- trunk/dabo/lib/DesignerXmlConverter.py 2009-12-17 14:13:35 UTC (rev
5556)
+++ trunk/dabo/lib/DesignerXmlConverter.py 2009-12-19 18:13:48 UTC (rev
5557)
@@ -50,6 +50,8 @@
self._codeFileText = self._hdrText
# Tracks the current sizer type
self._sizerTypeStack = []
+ # Location of the cdxml source file, if any
+ self._srcFile = None
def classFromXml(self, src):
@@ -334,7 +336,9 @@
# This will get set to True if we process a splitter
control
isSplitter = False
splitterString = ""
- if os.path.exists(clsname) and ("classID" in atts):
+ if "classID" in atts:
+ if not os.path.exists(clsname):
+ clsname =
dabo.lib.utils.locateRelativeTo(self._srcFile, clsname)
chldList = [[child]] + specChildList[:]
nm = self.createInheritedClass(clsname,
chldList)
code = {}
Modified: trunk/dabo/lib/utils.py
===================================================================
--- trunk/dabo/lib/utils.py 2009-12-17 14:13:35 UTC (rev 5556)
+++ trunk/dabo/lib/utils.py 2009-12-19 18:13:48 UTC (rev 5557)
@@ -11,6 +11,7 @@
# utils.foo()
import os
+osp = os.path
import sys
import dabo
try:
@@ -55,7 +56,7 @@
# os.path.expanduser should work on all posix systems (*nix, Mac, and
some
# Windows NT setups):
- hd = os.path.expanduser("~")
+ hd = osp.expanduser("~")
# If for some reason the posix function above didn't work, most Linux
setups
# define the environmental variable $HOME, and perhaps this is done
sometimes
@@ -108,8 +109,8 @@
dd = getUserHomeDirectory()
if dd is not None:
- dd = os.path.join(dd, appName)
- if not os.path.exists(dd):
+ dd = osp.join(dd, appName)
+ if not osp.exists(dd):
# try to create the dabo directory:
try:
os.makedirs(dd)
@@ -148,21 +149,21 @@
if fromLoc is None:
fromLoc = os.getcwd()
if toLoc.startswith(".."):
- if os.path.isdir(fromLoc):
- toLoc = os.path.join(fromLoc, toLoc)
+ if osp.isdir(fromLoc):
+ toLoc = osp.join(fromLoc, toLoc)
else:
- 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)
+ toLoc = osp.join(osp.split(fromLoc)[0], toLoc)
+ toLoc = osp.abspath(toLoc)
+ if osp.isfile(toLoc):
+ toDir, toFile = osp.split(toLoc)
else:
toDir = toLoc
toFile = ""
- fromLoc = os.path.abspath(fromLoc)
- if os.path.isfile(fromLoc):
- fromLoc = os.path.split(fromLoc)[0]
- fromList = fromLoc.split(os.path.sep)
- toList = toDir.split(os.path.sep)
+ fromLoc = osp.abspath(fromLoc)
+ if osp.isfile(fromLoc):
+ fromLoc = osp.split(fromLoc)[0]
+ fromList = fromLoc.split(osp.sep)
+ toList = toDir.split(osp.sep)
# There can be empty strings from the split
while len(fromList) > 0 and not fromList[0]:
fromList.pop(0)
@@ -184,7 +185,7 @@
def relativePath(toLoc, fromLoc=None):
"""Given two paths, returns a relative path from fromLoc to toLoc."""
- return os.path.sep.join(relativePathList(toLoc, fromLoc))
+ return osp.sep.join(relativePathList(toLoc, fromLoc))
def getPathAttributePrefix():
@@ -228,10 +229,42 @@
# Convert to relative path
ret = relativePath(val, pth)
if abspath:
- ret = os.path.abspath(ret)
+ ret = osp.abspath(ret)
return ret
+def locateRelativeTo(containerPath, itemPath):
+ """Paths to items, such as custom contained classes, should be relative
to
+ the container they are in.
+ """
+ # Start with the item's current location
+ dirsToCheck = [""]
+ if containerPath:
+ # Add the location of the containing form or class
+ containerDir = osp.dirname(containerPath)
+ dirsToCheck.append(containerDir)
+ try:
+ # Look in the standard Dabo app directories. We may not be
+ # running with an active app reference, so the try/except
+ # will handle that.
+ appPaths = dabo.dAppRef.getStandardDirectories()
+ dirsToCheck.extend(appPaths)
+ except AttributeError:
+ pass
+ # Add the current working directory
+ dirsToCheck.append(os.getcwd())
+ itemName = osp.basename(itemPath)
+ # Default to the original value
+ resolved = itemPath
+ for testDir in dirsToCheck:
+ testPath = osp.join(testDir, itemName)
+ if osp.exists(testPath):
+ # We found the file
+ resolved = testPath
+ break
+ return resolved
+
+
def cleanMenuCaption(cap, bad=None):
"""Menu captions can contain several special characters that make them
unsuitable for things such as preference settings. This method provides
_______________________________________________
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]