[Formed-commits] r292 - in trunk: . formed/formed/io formed/formed/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 29 15:59:59 CET 2008


Author: teichmann
Date: 2008-10-29 15:59:57 +0100 (Wed, 29 Oct 2008)
New Revision: 292

Modified:
   trunk/ChangeLog
   trunk/formed/formed/io/document.py
   trunk/formed/formed/io/factories.py
   trunk/formed/formed/model/data.py
Log:
Relative paths in external choices are now possible.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-09-04 10:37:32 UTC (rev 291)
+++ trunk/ChangeLog	2008-10-29 14:59:57 UTC (rev 292)
@@ -1,3 +1,16 @@
+2008-10-29	Sascha L. Teichmann <teichmann at intevation.de>
+
+	Relative paths in external choices are now possible. Relative paths are
+	relative to path of the master document.
+
+	* formed/model/data.py: external choice are now storing the path to the
+	  master document.
+
+	* formed/formed/io/document.py: Pass context to SAX builder.
+
+	* formed/formed/io/factories.py: For new created nodes look if there
+	  is a method 'setLoadContext' and call it.
+
 2008-09-04	Sascha L. Teichmann <teichmann at intevation.de>
 
 	* doc/beschreibung.txt: New. Initial description of FormEd (german).

Modified: trunk/formed/formed/io/document.py
===================================================================
--- trunk/formed/formed/io/document.py	2008-09-04 10:37:32 UTC (rev 291)
+++ trunk/formed/formed/io/document.py	2008-10-29 14:59:57 UTC (rev 292)
@@ -80,7 +80,7 @@
     BoolLeaf:               BOOL_TAG }
 
 def openDocument(path):
-    builder = SAXBuilder()
+    builder = SAXBuilder(path)
 
     builder.setCreators(factoryCreators)
     f = None

Modified: trunk/formed/formed/io/factories.py
===================================================================
--- trunk/formed/formed/io/factories.py	2008-09-04 10:37:32 UTC (rev 291)
+++ trunk/formed/formed/io/factories.py	2008-10-29 14:59:57 UTC (rev 292)
@@ -21,7 +21,12 @@
         self.ncClass      = ncClass
 
     def createFactory(self, name, attrs, ctx):
-        return self.factoryClass(attrs, self.ncClass())
+        obj = self.ncClass()
+        try:
+            getattr(obj, 'setLoadContext')(ctx)
+        except AttributeError:
+            pass
+        return self.factoryClass(attrs, obj)
 
 class NodeComponentFactory(Factory):
 

Modified: trunk/formed/formed/model/data.py
===================================================================
--- trunk/formed/formed/model/data.py	2008-09-04 10:37:32 UTC (rev 291)
+++ trunk/formed/formed/model/data.py	2008-10-29 14:59:57 UTC (rev 292)
@@ -21,6 +21,8 @@
 
 import formed.io.document
 
+import os
+
 class PageNode(Node):
     def __init__(self):
         Node.__init__(self)
@@ -132,22 +134,26 @@
     def __init__(self):
         Leaf.__init__(self)
         self.choice = None
+        self.path   = None
 
+    def setLoadContext(self, path):
+        self.path = os.path.dirname(path)
+
     def getChildren(self):
         if not self.choice:
             fname = self.getValue()
             if fname:
+                if not os.path.isabs(fname) and self.path:
+                    fname = os.path.join(self.path, fname)
                 try: # TODO: This loading code should be else where!
-                    import formed.io.document
-                    document = formed.io.document.openDocument(fname)
+                    from offline.io.document import openDocument
+                    document = openDocument(fname)
                     self.choice = document.findByClassAndName(ChoiceNode)
                 except Exception, inst:
                     print str(inst)
-                    pass
         if self.choice: 
             return self.choice.children
         return None
-
 class InfoLeaf(Leaf):
     def __init__(self):
         Leaf.__init__(self)



More information about the Formed-commits mailing list