/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
DybPython::dbsrv::MyCnf Class Reference

List of all members.

Public Member Functions

def __init__
def section
def mysqldb_pars

Public Attributes

 cfp
 sections
 path
 paths

Detailed Description

Definition at line 1566 of file dbsrv.py.


Constructor & Destructor Documentation

def DybPython::dbsrv::MyCnf::__init__ (   self,
  path = "~/.my.cnf",
  prime = {} 
)
:param path: to config file
:param prime: initial dict to prime the config, eg for current date

Definition at line 1567 of file dbsrv.py.

01567                                                  {}): 
01568         """
01569         :param path: to config file
01570         :param prime: initial dict to prime the config, eg for current date
01571         """
01572         cfp = ConfigParser(prime)
01573         paths = cfp.read( [os.path.expandvars(os.path.expanduser(p)) for p in path.split(":")] )
01574         log.debug("MyCnf read %s " % repr(paths) )
01575         self.cfp = cfp 
01576         self.sections = cfp.sections() 
01577         self.path = path
01578         self.paths  = paths
01579 

Member Function Documentation

def DybPython::dbsrv::MyCnf::section (   self,
  sect,
  home = None 
)
:param sect: name of section in config file
:return: dict of config parameters from specified section of config file

When the section is present in the config file simply return
the parameters. If the section is not present in the file then 
adopt the \"home\" instanance section and swap in the the database
from the sect name.

This allows access to all databases on a server without having 
corresponding config file sections for all of them.

Definition at line 1580 of file dbsrv.py.

01581                                       :
01582         """
01583         :param sect: name of section in config file
01584         :return: dict of config parameters from specified section of config file
01585 
01586         When the section is present in the config file simply return
01587         the parameters. If the section is not present in the file then 
01588         adopt the \"home\" instanance section and swap in the the database
01589         from the sect name.
01590 
01591         This allows access to all databases on a server without having 
01592         corresponding config file sections for all of them.
01593         """
01594         if sect in self.sections:
01595             it = dict(self.cfp.items(sect))
01596         else:
01597             if not home is None:
01598                 assert home.sect in self.sections, self.sections
01599                 it = dict(self.cfp.items(home.sect))
01600                 it['database'] = sect
01601                 log.debug("no section %s infer config from home.sect %s section assuming section name = dbname " % (sect, home.sect) )
01602             else:
01603                 it = None
01604         pass
01605         return it

def DybPython::dbsrv::MyCnf::mysqldb_pars (   self,
  sect,
  home = None 
)
:param sect: name of section in config file
:param home: DB instance 
:return: dict of mysql-python style connection parameters

Annoyingly mysql-python needs these keys

`host` host to connect
`user` user to connect as
`passwd` password to use
`db` database to use

whereas mysql uses slightly different ones

`host`   
`user`
`password`
`database` 

Normally can avoid this annoyance using::

    conn = MySQLdb.connect( read_default_group=sect )   

but when need to impinge `database/db` settings this is not possible.

Definition at line 1606 of file dbsrv.py.

01607                                            :
01608         """
01609         :param sect: name of section in config file
01610         :param home: DB instance 
01611         :return: dict of mysql-python style connection parameters
01612 
01613         Annoyingly mysql-python needs these keys
01614 
01615         `host` host to connect
01616         `user` user to connect as
01617         `passwd` password to use
01618         `db` database to use
01619 
01620         whereas mysql uses slightly different ones
01621 
01622         `host`   
01623         `user`
01624         `password`
01625         `database` 
01626 
01627         Normally can avoid this annoyance using::
01628 
01629             conn = MySQLdb.connect( read_default_group=sect )   
01630 
01631         but when need to impinge `database/db` settings this is not possible.
01632         """
01633         my2mp = dict(host="host",user="user",password="passwd",database="db", socket="unix_socket")
01634         my = self.section(sect, home=home)
01635 
01636         if my is None:
01637            msg = "missing required section \"%s\" in config file \"%s\" " % ( sect, self.path )
01638            log.fatal(msg)
01639            raise Exception(msg)
01640 
01641         mp = {}
01642         for k in filter(lambda k:k in my2mp,my.keys()):  # key translation, mysql to mysql-python
01643             mp[my2mp[k]] =  my[k]
01644         log.debug("translate mysql config %s into mysql-python config %s " % ( dict(my,password="***") , dict(mp,passwd="***") ))
01645         return mp 
01646 
01647 
01648 
01649 


Member Data Documentation

Definition at line 1570 of file dbsrv.py.

Definition at line 1570 of file dbsrv.py.

Definition at line 1570 of file dbsrv.py.

Definition at line 1570 of file dbsrv.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:55:41 for DybPython by doxygen 1.7.4