commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnue-common/gnue/common GClientApp.py GCon...


From: Jason Cater
Subject: gnue/gnue-common/gnue/common GClientApp.py GCon...
Date: Fri, 11 May 2001 18:42:56 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/05/11 18:42:55

Modified files:
        gnue-common/gnue/common: GClientApp.py GConnections.py 
                                 GParser.py 

Log message:
        Added support to gnuef for connection definition files

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GClientApp.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GConnections.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GParser.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gnue/gnue-common/gnue/common/GClientApp.py
diff -u gnue/gnue-common/gnue/common/GClientApp.py:1.3 
gnue/gnue-common/gnue/common/GClientApp.py:1.4
--- gnue/gnue-common/gnue/common/GClientApp.py:1.3      Fri May 11 17:04:35 2001
+++ gnue/gnue-common/gnue/common/GClientApp.py  Fri May 11 18:42:55 2001
@@ -34,6 +34,7 @@
 import sys
 import string 
 import os
+import GConnections
 
 
 class GClientApp:  
@@ -144,33 +145,36 @@
    
     # Get the connection definitions
 
-#    if self.OPTIONS['connections']: 
-#      self.connections_file = self.OPTIONS['connections']
-#    elif os.environ.has_key('GNUE_CONNECTIONS'):
-#      self.connections_file = self.OPTIONS['GNUE_CONNECTION']
-#    else: 
+    if self.OPTIONS['connections']: 
+      self.connections_file = self.OPTIONS['connections']
+    elif os.environ.has_key('GNUE_CONNECTIONS'):
+      self.connections_file = os.environ['GNUE_CONNECTIONS']
+    else: 
+      self.connections_file = "" # temp
 #      self.handleStartupError(
 #          'Unable to load the connections definition file.\n' \
 #          + '\n   Please set the environmental variable GNUE_CONNECTIONS or ' 
\
 #          + '\n   use the "-f" command option.')
 #
-#    GDebug.printMesg(1, 'Connection Definition: "%s"' % self.connections_file)
-#
-#    try:
-#      self.connections = GConnections.GConnections(self.connections_file)
-#    except GConnections.InvalidFormatError, msg: 
-#      self.handleStartupError(
-#          'Unable to load the connections definition file.\n' \
-#          + '\n   The connections file is in an invalid format. ' \
-#          + '\n   %s' \
-#             % msg)
-#    except:
-#      self.handleStartupError(
-#          'Unable to load the connections definition file.\n' \
-#          + '\n   The connections file specified either does ' \
-#          + '\n   not exist or is not readable by your account.\n' \
-#          + '\n   Location: "%s"'
-#             % self.connections_file)
+    GDebug.printMesg(1, 'Connection Definition: "%s"' % self.connections_file)
+
+    # Temporary "if" until we fully implement the connection definitions
+    if len(self.connections_file): 
+     try:
+      self.connections = GConnections.GConnections(self.connections_file)
+     except GConnections.InvalidFormatError, msg: 
+      self.handleStartupError(
+          'Unable to load the connections definition file.\n' \
+          + '\n   The connections file is in an invalid format. ' \
+          + '\n   %s' \
+             % msg)
+     except:
+      self.handleStartupError(
+          'Unable to load the connections definition file.\n' \
+          + '\n   The connections file specified either does ' \
+          + '\n   not exist or is not readable by your account.\n' \
+          + '\n   Location: "%s"'
+             % self.connections_file)
 
   #
   #  Display version information for this application
@@ -247,7 +251,7 @@
       sys.exit()
 
   #
-  #  Run with profiling 
+  #  Used when profiling 
   #
   def _profile(self): 
 
Index: gnue/gnue-common/gnue/common/GConnections.py
diff -u gnue/gnue-common/gnue/common/GConnections.py:1.1 
gnue/gnue-common/gnue/common/GConnections.py:1.2
--- gnue/gnue-common/gnue/common/GConnections.py:1.1    Fri May 11 16:09:16 2001
+++ gnue/gnue-common/gnue/common/GConnections.py        Fri May 11 18:42:55 2001
@@ -72,6 +72,8 @@
     except: 
       raise InvalidFormatError, 'The file cannot be parsed.'
 
+  def hasConnection(self, connection_name): 
+    return self.parser.has_section(connection_name)
 
   def get(self, connection_name, attribute, default=None): 
     if self.parser.has_section(connection_name): 
@@ -82,6 +84,31 @@
     else: 
        raise NotFoundError
 
+  #
+  # Returns an dictionary of dictionaries describing all connections: 
+  #  {connection name: {att name: value}}
+  #
+  def getConnections(self): 
+    rv = {}
+    for section in self.parser.sections(): 
+       rv[section]={}
+       for att in self.parser.options(section): 
+         rv[section][att] = self.parser.get(section, att)
+    return rv
+
+  #
+  # Returns a dictionary describing a connection: 
+  #  {att name: value}
+  #
+  def getConnection(self, connection_name): 
+    rv = {}
+    if self.parser.has_section(connection_name): 
+      for att in self.parser.options(connection_name): 
+        rv[att] = self.parser.get(connection_name, att)
+    else: 
+       raise NotFoundError
+
+    return rv
 
 #
 # This is an ugly hack to make the Python 1.5.2 ConfigParser
Index: gnue/gnue-common/gnue/common/GParser.py
diff -u gnue/gnue-common/gnue/common/GParser.py:1.5 
gnue/gnue-common/gnue/common/GParser.py:1.6
--- gnue/gnue-common/gnue/common/GParser.py:1.5 Fri Apr 20 18:23:27 2001
+++ gnue/gnue-common/gnue/common/GParser.py     Fri May 11 18:42:55 2001
@@ -49,9 +49,18 @@
 #  be used in the Forms/Reports Designer package where 
 #  we will not want the loaded form to connect to 
 #  databases, etc)
+#
+# "attributes" is a dictionary containing extra 
+# attributes that should be attached to this object. 
+#
+#  e.g., if attributes={myproperty:[0,1,2]}, then 
+#    before the object is initialized or returned, 
+#    object.myproperty == [0,1,2].
+#
 #######################################################
 
-def loadXMLObject(URL, handler, rootType, xmlFileType, initialize=1):
+def loadXMLObject(URL, handler, rootType, xmlFileType, 
+  initialize=1, attributes={}):
   # Create a parser
   parser = saxexts.make_parser()
   
@@ -77,6 +86,9 @@
     sys.exit()
 
   #object.showTree()
+
+  for att in attributes.keys(): 
+    object.__dict__[att] = attributes[att]
 
   if initialize:
     object.initializeTree()



reply via email to

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