commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5058 - in trunk: gnue-common/src/datasources gnue-common/src/logic gnue


From: jcater
Subject: r5058 - in trunk: gnue-common/src/datasources gnue-common/src/logic gnue-forms/src gnue-forms/src/GFObjects
Date: Fri, 30 Jan 2004 18:38:35 -0600 (CST)

Author: jcater
Date: 2004-01-30 18:38:34 -0600 (Fri, 30 Jan 2004)
New Revision: 5058

Added:
   trunk/gnue-common/src/datasources/ConnectionTriggerObj.py
Modified:
   trunk/gnue-common/src/datasources/GConnections.py
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/logic/NamespaceCore.py
   trunk/gnue-forms/src/GFForm.py
   trunk/gnue-forms/src/GFObjects/GFBlock.py
   trunk/gnue-forms/src/GFParser.py
Log:
added the connection names to the trigger global namespace. So, if you have a 
connection named 'gnue', you can do: gnue.getTimeStamp()

Added: trunk/gnue-common/src/datasources/ConnectionTriggerObj.py
===================================================================
--- trunk/gnue-common/src/datasources/ConnectionTriggerObj.py   2004-01-30 
18:03:36 UTC (rev 5057)
+++ trunk/gnue-common/src/datasources/ConnectionTriggerObj.py   2004-01-31 
00:38:34 UTC (rev 5058)
@@ -0,0 +1,72 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# GConnections.py
+#
+# DESCRIPTION:
+"""
+"""
+# NOTES:
+#
+
+__all__ = ['ConnectionTriggerObj']
+
+from gnue.common.definitions.GObjects import GObj
+from gnue.common.apps import GDebug
+import types
+
+_blockedMethods = ('connect','close','getLoginFields')
+
+class ConnectionTriggerObj(GObj): 
+  """
+  Class that allows us to insert Connection objects into trigger namespaces
+  """
+  def __init__(self, connection, name): 
+    self.name = name
+    self.__connection = connection
+    GObj.__init__(self, type="ConnTrigObj")
+    
+    self._triggerGlobal = True
+    self._triggerFunctions={}
+                            
+    for method in dir(connection): 
+      function = getattr(connection,method)
+      if method[0] != '_' and method not in _blockedMethods and type(function) 
== types.MethodType:
+        self._triggerFunctions[method] = {'function':function}
+    
+    self._triggerProperties={'login':  {'get':self.__getLogin}}
+        
+  def __getLogin(self): 
+    return self.__connection.manager.getAuthenticatedUser(self.name)
+    
+    
+def addAllConnections(connections, gobjNamespace): 
+  """
+  Adds all the connection names to the global trigger namespace
+  """
+  for name in connections.getConnectionNames(): 
+    try: 
+      conn = connections.getConnection(name)
+    except: 
+      GDebug.printMesg(5,"Cannot add connection %s to trigger namespace" % 
name)
+      continue
+    gobjNamespace.constructTriggerObject(ConnectionTriggerObj(conn, name))
+    
\ No newline at end of file

Modified: trunk/gnue-common/src/datasources/GConnections.py
===================================================================
--- trunk/gnue-common/src/datasources/GConnections.py   2004-01-30 18:03:36 UTC 
(rev 5057)
+++ trunk/gnue-common/src/datasources/GConnections.py   2004-01-31 00:38:34 UTC 
(rev 5058)
@@ -22,8 +22,10 @@
 # GConnections.py
 #
 # DESCRIPTION:
-# Class that loads connection definition files and maintains
-# database connections.
+"""
+Class that loads connection definition files and maintains
+database connections.
+"""
 #
 # NOTES:
 #
@@ -155,7 +157,7 @@
   # Returns an dictionary of dictionaries describing all connections:
   #  {connection name: {att name: value}}
   #
-  def getConnectionNames(self, includeAliases=1):
+  def getConnectionNames(self, includeAliases=True):
     if includeAliases:
       return self._definitions.keys()
     else:
@@ -459,7 +461,7 @@
     return 'gnue.common.datasources.drivers.' + string.join(path + 
[driver],'.')
   else:
     for module in modules:
-      print "trying module: %s" % module
+      GDebug.printMesg(5,"trying module: %s" % module)
       try:
         m = dyn_import ('gnue.common.datasources.drivers.' + string.join(path 
+ [module],'.')).DRIVERS
         rs = _find_base_driver(driver, m, path + [module])

Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2004-01-30 18:03:36 UTC 
(rev 5057)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2004-01-31 00:38:34 UTC 
(rev 5058)
@@ -176,7 +176,6 @@
     self._connections = connectionManager
 
   def initialize(self):
-    print self.name
     if not self.connection:
       # We are a connectionless datasource (virtual?)
       # We have to bind to something, so bind to empty or static driver

Modified: trunk/gnue-common/src/logic/NamespaceCore.py
===================================================================
--- trunk/gnue-common/src/logic/NamespaceCore.py        2004-01-30 18:03:36 UTC 
(rev 5057)
+++ trunk/gnue-common/src/logic/NamespaceCore.py        2004-01-31 00:38:34 UTC 
(rev 5058)
@@ -59,7 +59,7 @@
                              }
 
     self._rname = rootName
-
+    
     if objectTree:
       self._globalNamespace[self._rname] = 
self.constructTriggerObject(objectTree)
     else:
@@ -97,12 +97,11 @@
             object = 
NamespaceFunction(item,gobjObject._triggerFunctions[item]['function'])
             triggerObject.__dict__[item] = object
             # Add this function to global namespace if the GObj requests it
-            if gobjObject._triggerFunctions[item].has_key('global') and \
-               gobjObject._triggerFunctions[item]['global'] != 0:
+            if gobjObject._triggerFunctions[item].get('global',0):
               self._globalNamespace[item] = object
 
           else:
-            GDebug.printMesg(0,'Only functions are supported in an objects 
_triggerFunctions %s %s' % (gobjObject,item))
+            raise 'Only functions are supported in an objects 
_triggerFunctions (%s %s)' % (gobjObject,item)
 
             sys.exit()
 

Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py      2004-01-30 18:03:36 UTC (rev 5057)
+++ trunk/gnue-forms/src/GFForm.py      2004-01-31 00:38:34 UTC (rev 5058)
@@ -39,7 +39,7 @@
 from gnue.common.definitions.GRootObj import GRootObj
 from gnue.common.logic.GTrigger import TriggerError
 from gnue.common.definitions.GObjects import GObj
-
+from gnue.common.datasources import ConnectionTriggerObj
 from gnue.forms.GFObjects import *
 from gnue.forms import GFParser
 
@@ -177,6 +177,7 @@
         self._layout = child
 
     self.initTriggerSystem()
+    ConnectionTriggerObj.addAllConnections(self._instance.connections, 
self._triggerNamespaceTree)
     self._triggerns.update(self._triggerNamespaceTree._globalNamespace)
 
     ## TODO: This ain't right!  Fix after 0.5.0

Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2004-01-30 18:03:36 UTC (rev 
5057)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2004-01-31 00:38:34 UTC (rev 
5058)
@@ -187,7 +187,7 @@
     # Create a stub/non-bound datasource if we aren't bound to one
     if not hasattr(self,'datasource') or not self.datasource:
       ds = GFDataSource(self)
-      self.datasource = ds.name = "dts_%s" % self
+      self.datasource = ds.name = "__dts_%s" % id(self)
       form._datasourceDictionary[ds.name] = ds
       ds._buildObject()
       ds.phaseInit()
@@ -622,7 +622,6 @@
     self.block = block
     self.new = True
     self.done = False
-    print "Iterator created"
 
   def __iter__(self):
     return self

Modified: trunk/gnue-forms/src/GFParser.py
===================================================================
--- trunk/gnue-forms/src/GFParser.py    2004-01-30 18:03:36 UTC (rev 5057)
+++ trunk/gnue-forms/src/GFParser.py    2004-01-31 00:38:34 UTC (rev 5058)
@@ -51,18 +51,19 @@
 
 
 
+##
+##
+##
+def loadFile(buffer, instance, initialize=True):
+  """
+  This method loads a form from an XML file and returns
+  a GFForm object.  If initialize is 1 (default), then
+  the form is initialized and ready to go.
 
-#######################################################
-# This method loads a form from an XML file and returns
-# a GFForm object.  If initialize is 1 (default), then
-# the form is initialized and ready to go.
-#
-# (initialize=0 is currently not used -- will probably
-#  be used in the Forms Designer package where we will
-#  not want the loaded form to connect to databases, etc)
-#######################################################
-
-def loadFile(buffer, instance, initialize=1):
+  (initialize=0 is currently not used -- will probably
+  be used in the Forms Designer package where we will
+  not want the loaded form to connect to databases, etc)
+  """
   return GParser.loadXMLObject (buffer, xmlFormsHandler, 'GFForm', 'form',
            initialize, attributes={"_instance": instance,
                                "_parameters": instance._parameters,
@@ -851,9 +852,9 @@
     copy._deepcopy_dispatch[types.ClassType] = copy._deepcopy_atomic
     copy._deepcopy_dispatch[type(int)] = copy._deepcopy_atomic                 
           
     dialog=copy.deepcopy(xmlElements['form'])
-    dialog['Required'] = 0
-    dialog['SingleInstance'] = 0
-    dialog['Importable'] = 1
+    dialog['Required'] = False
+    dialog['SingleInstance'] = False
+    dialog['Importable'] = True
     dialog['Attributes']['style']['Default']='dialog'
     dialog['ParentTags']= ('form',)
     xmlElements.update({'dialog':dialog})
@@ -905,12 +906,13 @@
 #
 # xmlFormsHandler
 #
-# This class is called by the XML parser to
-# process the xml file.
-#
 #######################################################
 
-class xmlFormsHandler (GParser.xmlHandler):
+class xmlFormsHandler (GParser.xmlHandler): 
+  """
+  This class is called by the XML parser to
+  process the .GFD file.
+  """
   def __init__(self):
     
 
@@ -918,7 +920,7 @@
     
     # This is a temp thing until we figure out
     # how to better do layout namespaces
-    self.xmlNamespaceAttributesAsPrefixes = 1
+    self.xmlNamespaceAttributesAsPrefixes = True
 
     self.xmlElements = getXMLelements()
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]