Changeset e64ab6 in indico for indico/MaKaC/common/db.py


Ignore:
Timestamp:
09/11/09 14:58:05 (4 years ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, new-improved-taskdaemon, new-webex, prov-dual-interface, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, d9941f8582b36b24821a11ea5ba16fda6a457fb1
Children:
6e28cf
Parents:
d44cf5
Message:

[IMPROVEMENT] DBMgr parameters

Greater flexibility choosing hostname and port (needed for unit
testing).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/common/db.py

    rfd0c10 re64ab6  
    7474    _instance = None 
    7575 
    76     def __init__( self ): 
     76    def __init__( self, hostname=None, port=None ): 
    7777        import Configuration # Please leave this import here, db.py is imported during installation process 
    7878        cfg = Configuration.Config.getInstance() 
    79         self._storage=ClientStorage(cfg.getDBConnectionParams(), username=cfg.getDBUserName(), password=cfg.getDBPassword(), realm=cfg.getDBRealm()) 
     79 
     80        if not hostname: 
     81            hostname = cfg.getDBConnectionParams()[0] 
     82        if not port: 
     83            port = cfg.getDBConnectionParams()[1] 
     84 
     85        self._storage=ClientStorage((hostname, port), username=cfg.getDBUserName(), password=cfg.getDBPassword(), realm=cfg.getDBRealm()) 
    8086        self._db=MaKaCDB(self._storage) 
    8187        self._conn={} 
    8288 
    8389    @classmethod 
    84     def getInstance( cls ): 
     90    def getInstance( cls, *args, **kwargs ): 
    8591        if cls._instance == None: 
    8692            Logger.get('dbmgr').debug('cls._instance is None') 
    87             cls._instance=DBMgr() 
     93            cls._instance=DBMgr(*args, **kwargs) 
    8894        return cls._instance 
    89      
    90     @classmethod 
    91     def initializeAndGetInstance(cls, address, username = '', password = '', realm = ''): 
    92         """ Use this method when you need to create a DBMgr that will not use the "standard" address and port 
    93             (who are normally retrieved from Config, i.e. indico.conf). 
    94             Its implementation is quite hacky so that we don't change at all the getInstance and __init__ methods used in many places in Indico. 
    95         """ 
    96         if cls._instance == None: 
    97             Logger.get('dbmgr').debug('cls._instance is None (initializeAndGetInstance)') 
    98              
    99             class CustomDBMgr:  # we need this old-style class because DBMgr is an old-style class and we cannot change the class of an object from new-style to old-style 
    100                 pass            # if DBMgr is ever changed to new-style (inherit from object) then we could initialize 'o' in a simpler way with "o = object()"  
    101             o = CustomDBMgr() 
    102             o.__class__ = cls # cls = DBMgr 
    103              
    104             o._storage = ClientStorage(address, username=username, password=password, realm=realm) 
    105             o._db = MaKaCDB(o._storage) 
    106             o._conn = {} 
    107              
    108             cls._instance = o 
    109              
    110         return cls._instance 
    111      
    11295 
    11396    def _getConnObject(self): 
Note: See TracChangeset for help on using the changeset viewer.