commit-gnue
[Top][All Lists]
Advanced

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

gnue/common doc/Connections.txt etc/sample.conn...


From: Jason Cater
Subject: gnue/common doc/Connections.txt etc/sample.conn...
Date: Sat, 27 Apr 2002 19:13:49 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/04/27 19:13:48

Modified files:
        common/doc     : Connections.txt 
        common/etc     : sample.connections.conf 
        common/src     : GConnections.py 

Log message:
        * Lots of cleanup to the connections.conf parsing.
        * Added support for aliases= in the connections.conf file

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/doc/Connections.txt.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/etc/sample.connections.conf.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GConnections.py.diff?cvsroot=OldCVS&tr1=1.31&tr2=1.32&r1=text&r2=text

Patches:
Index: gnue/common/doc/Connections.txt
diff -c gnue/common/doc/Connections.txt:1.1 gnue/common/doc/Connections.txt:1.2
*** gnue/common/doc/Connections.txt:1.1 Fri May 25 12:11:55 2001
--- gnue/common/doc/Connections.txt     Sat Apr 27 19:13:48 2002
***************
*** 17,23 ****
  
  Any line beginning with a "#" or a ";" is considered a comment and is ignored.
  
! Whitespace before or after the first equals sign ("=") is ignored.  All 
  whitespace in a parameter's value is preserved.
  
  
--- 17,23 ----
  
  Any line beginning with a "#" or a ";" is considered a comment and is ignored.
  
! Whitespace before or after the first equals sign ("=") is ignored.  All
  whitespace in a parameter's value is preserved.
  
  
***************
*** 25,33 ****
  Sections
  --------
  
! A section begins with a connection name enclosed in brackets ("[" & "]").  It 
! is then followed by one or more parameters.  A section ends either when a new 
! section is defined or at the end of the file.  A sample section that defines 
  a connection named "gnue":
  
        [gnue]
--- 25,33 ----
  Sections
  --------
  
! A section begins with a connection name enclosed in brackets ("[" & "]").  It
! is then followed by one or more parameters.  A section ends either when a new
! section is defined or at the end of the file.  A sample section that defines
  a connection named "gnue":
  
        [gnue]
***************
*** 41,56 ****
  ----------
  
  connection
-   
-    This parameter specifies a connection string to be used by the database 
-    provider.  The format of the connection string is provider dependent and 
-    not all providers recoognize this parameter.  
  
!    In most implementations, a connection string can be used in place of the 
!    "dbname" and "host" parameters.  
  
-    Example (for an ODBC connection): 
-     
        connection = "Driver={mySQL};Server=localhost;Database=gnue;"
  
     This parameter has no default and is not required unless implemented as
--- 41,56 ----
  ----------
  
  connection
  
!    This parameter specifies a connection string to be used by the database
!    provider.  The format of the connection string is provider dependent and
!    not all providers recoognize this parameter.
! 
!    In most implementations, a connection string can be used in place of the
!    "dbname" and "host" parameters.
! 
!    Example (for an ODBC connection):
  
        connection = "Driver={mySQL};Server=localhost;Database=gnue;"
  
     This parameter has no default and is not required unless implemented as
***************
*** 59,67 ****
  
  comment
  
!    This parameter is a text field that is seen in a list of available 
!    connections.  The comment should provide more information regarding 
!    the connection than the connection name.  
  
     Example (for a connection named "acctaud"):
         
--- 59,67 ----
  
  comment
  
!    This parameter is a text field that is seen in a list of available
!    connections.  The comment should provide more information regarding
!    the connection than the connection name.
  
     Example (for a connection named "acctaud"):
         
***************
*** 116,157 ****
     This parameter has no default and is required.
  
  
! ---------
! Providers
! ---------
! 
! postgresql 
! 
!    This provides services to a PostgreSQL (http://www.postgresql.org) 
!    database.  PostgreSQL is an Open Source/Free Software Object-Relational 
!    database implementation that supports most SQL constructs and implements
!    user-defined functions.
  
!    This provider requires the "dbname" and "host" parameters. "dbname" refers
!    to the database name and "host" refers to the IP or DNS name of the server 
!    that PostgreSQL runs on.
  
  
- mysql 
  
!    This provides services to a MySQL (http://www.mysql.com) database.  MySQL 
!    is an Open Source/Free Software Relational database implementation that 
!    supports most SQL constructs.
! 
!    This provider requires the "dbname" and "host" parameters. "dbname" refers
!    to the database name and "host" refers to the IP or DNS name of the server 
!    that MySQL runs on.
! 
! 
! geas 
  
!    This provides services to a GEAS (http://www.gnue.org) data source.  GEAS 
!    is an Open Source/Free Software middle-ware implementation written as part
!    of the GNU Enterprise project.
  
!    This provider requires the "dbname" and "host" parameters. "dbname" refers
!    to the database name and "host" refers to the IP or DNS name of the server 
!    that MySQL runs on.
  
  
  --------------
--- 116,139 ----
     This parameter has no default and is required.
  
  
! aliases
  
!    This space delimited parameter creates "aliases" for the current 
connection.
!    For example, if you have a section:
  
+    [test1]
+    aliases = test2, test3
+    provider = postgresql
  
  
!    Then "test1" can also be referred to in datasources as "test2" and "test3".
!    
  
! ---------
! Providers
! ---------
  
! See README.databases for a complete list of providers.
  
  
  --------------
***************
*** 191,197 ****
     $ gfclient
  
  Ideally, GNUE_CONNECTIONS would be set in a user's .profile file.  In a 
! multi-system environment (where the individial clients can be run on 
  different machines), it would be best to home the connections file either
  on a shared drive or as a URL referencable resource.  This way, only one 
  connections file must be maintained.
--- 173,179 ----
     $ gfclient
  
  Ideally, GNUE_CONNECTIONS would be set in a user's .profile file.  In a 
! multi-system environment (where the individial clients can be run on
  different machines), it would be best to home the connections file either
  on a shared drive or as a URL referencable resource.  This way, only one 
  connections file must be maintained.
Index: gnue/common/etc/sample.connections.conf
diff -c gnue/common/etc/sample.connections.conf:1.1 
gnue/common/etc/sample.connections.conf:1.2
*** gnue/common/etc/sample.connections.conf:1.1 Mon Nov  5 22:55:24 2001
--- gnue/common/etc/sample.connections.conf     Sat Apr 27 19:13:48 2002
***************
*** 1,17 ****
  [devel]
! comment = GNUe Sample Connection for MySQL based developer database
  provider = mysql
  host = gnue
  dbname = developer
  
- [prod]
- comment = PostgreSQL Sample Connection to a production database
- provider = pypgsql
- host = gnue
- dbname = production
  
! [gnue]
! comment = Connection to a database dedicated to gnue 
! provider = pypgsql
! host = gnue
! dbname = gnue
--- 1,28 ----
+ 
+ # This connection uses the PostgreSQL "psycopg" driver
+ # and also creates two aliases, dcl and test, for itself.
+ # We will be connecting to the postgresql server on
+ # "localhost" to a database called "gnue".
+ [gnue]
+ comment = GNUe Test Database
+ aliases = dcl test
+ provider = psycopg
+ host = localhost
+ dbname = gnue
+ 
+ 
+ # An example MySQL connection
  [devel]
! comment = XYZ Development Database
  provider = mysql
  host = gnue
  dbname = developer
  
  
! # An Oracle connection using DCOracle2.
! # myTNSconn is a TNS connection that
! # is defined in your tnsnames.ora file.
! [prod]
! comment = XYZ Production Database
! provider = oracle
! service = myTNSconn
Index: gnue/common/src/GConnections.py
diff -c gnue/common/src/GConnections.py:1.31 
gnue/common/src/GConnections.py:1.32
*** gnue/common/src/GConnections.py:1.31        Mon Apr  8 18:02:06 2002
--- gnue/common/src/GConnections.py     Sat Apr 27 19:13:48 2002
***************
*** 31,37 ****
  #
  
  from ConfigParser import *
! import sys, string
  import GDebug
  import GDataObjects
  import GLoginHandler
--- 31,37 ----
  #
  
  from ConfigParser import *
! import sys, string, copy
  import GDebug
  import GDataObjects
  import GLoginHandler
***************
*** 86,107 ****
  
      self._openConnections = {}
  
  
    def setLoginHandler(self, loginHandler):
      self._loginHandler = loginHandler
  
  
    def hasConnectionParameters(self, connection_name):
!     return self._parser.has_section(connection_name)
  
  
    def getConnectionParameter(self, connection_name, attribute, default=None):
!     if self._parser.has_section(connection_name):
        try:
!         return self._parser.get(connection_name, attribute)
        except:
          return default
!     else:
        raise NotFoundError, \
           'The connections file does not contain a definition \n       for 
"%s".\n\nFile: %s' \
              % (connection_name, self._location)
--- 86,135 ----
  
      self._openConnections = {}
  
+     self._primaries = {}
+     self._aliases = {}
+     self._definitions = {}
+ 
+ 
+     # Read all the sections into a dict
+     # and make a note of all alias names
+     for section in self._parser.sections():
+        self._primaries[section]={}
+        for att in self._parser.options(section):
+          if att == 'aliases':
+            for alias in 
string.split(string.lower(self._parser.get(section,att))):
+              self._aliases[alias] = section
+          else:
+            self._primaries[section][att] = self._parser.get(section, att)
+ 
+     # Fill in any aliases with their parameters
+     for alias in self._aliases.keys():
+       section = self._aliases[alias]
+       self._aliases[alias] = copy.copy(self._primaries[section])
+       self._aliases[alias]['_alias_of'] = section
+ 
+ 
+     self._definitions.update(self._aliases)
+     self._definitions.update(self._primaries)
+ 
+ 
  
    def setLoginHandler(self, loginHandler):
      self._loginHandler = loginHandler
  
  
    def hasConnectionParameters(self, connection_name):
!     return self._definitions.has_key(connection_name)
  
  
    def getConnectionParameter(self, connection_name, attribute, default=None):
!     try:
!       definition = self._definitions[connection_name]
        try:
!         return definition[attribute]
        except:
          return default
!     except KeyError:
        raise NotFoundError, \
           'The connections file does not contain a definition \n       for 
"%s".\n\nFile: %s' \
              % (connection_name, self._location)
***************
*** 111,147 ****
    # Returns an dictionary of dictionaries describing all connections:
    #  {connection name: {att name: value}}
    #
!   def getConnectionNames(self):
!     return self._parser.sections()
  
  
    #
    # Returns an dictionary of dictionaries describing all connections:
    #  {connection name: {att name: value}}
    #
!   def getAllConnectionParameters(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 getConnectionParameters(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, \
           'The connections file does not contain a definition \n       for 
"%s".\n\nFile: %s' \
              % (connection_name, self._location)
  
-     return rv
  
    #
    # Add a connection entry (session specific; i.e., doesn't add
--- 139,174 ----
    # Returns an dictionary of dictionaries describing all connections:
    #  {connection name: {att name: value}}
    #
!   def getConnectionNames(self, includeAliases=1):
!     if includeAliases:
!       return self._definitions.keys()
!     else:
!       return self._primaries.keys()
  
  
    #
    # Returns an dictionary of dictionaries describing all connections:
    #  {connection name: {att name: value}}
    #
!   def getAllConnectionParameters(self, includeAliases=1):
!     if includeAliases:
!       return copy.deepcopy(self._definitions)
!     else:
!       return copy.deepcopy(self._primaries)
! 
  
    #
    # Returns a dictionary describing a connection:
    #  {att name: value}
    #
    def getConnectionParameters(self, connection_name):
!     try:
!       return copy.deepcopy(self._definitions[connection_name])
!     except KeyError:
        raise NotFoundError, \
           'The connections file does not contain a definition \n       for 
"%s".\n\nFile: %s' \
              % (connection_name, self._location)
  
  
    #
    # Add a connection entry (session specific; i.e., doesn't add
***************
*** 149,158 ****
    # list of available connections.
    #
    def addConnectionSpecification (self, name, parameters):
!     self._parser.remove_section(string.lower(name))
!     self._parser.add_section(string.lower(name))
!     for key in parameters.keys():
!       self._parser.set(string.lower(name), key, parameters[key])
  
  
    #
--- 176,182 ----
    # list of available connections.
    #
    def addConnectionSpecification (self, name, parameters):
!     self._definitions[string.lower(name)] = copy.copy(parameters)
  
  
    #



reply via email to

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