3030import os
3131
3232import cx_Oracle
33- import Misc .AppConfigs
3433
3534
3635class DbMethods (object ):
@@ -44,7 +43,7 @@ class DbMethods(object):
4443 :ivar dbParams: Contains the database connection parameters.
4544 '''
4645
47- def __init__ (self , configFile = '' ):
46+ def __init__ (self ):
4847 self .logger = logging .getLogger (__name__ )
4948 self .logger .debug ("Logging set up in the module: %s" , os .path .basename (__file__ ))
5049 self .logger .debug ("using this version of dblib" )
@@ -53,8 +52,6 @@ def __init__(self, configFile=''):
5352 # parameters by the method __getDbParams
5453 self .dbParams = {}
5554
56- if configFile :
57- self .connect (configFile )
5855
5956 def connectParams (self , user = None , pswd = None , instance = None ):
6057 '''
@@ -88,20 +85,20 @@ def connectParams(self, user=None, pswd=None, instance=None):
8885 self .logger .info (msg )
8986 raise ConnectionError (self .dbParams ['username' ], self .dbParams ['instance' ])
9087
91- def connectNoDSN (self , user , pswd , instance , server , port = 1521 ):
88+ def connectNoDSN (self , user , pswd , serviceName , host , port = 1521 ):
9289 '''
9390 Allows for the creation of a database connection when the
9491 client does not have a valid TNS file. Allows you to connect
95- using port and server name.
92+ using port and host name.
9693
9794 :param user: schema that you are using to connnect to the database
9895 :type user: str
9996 :param pswd: password that goes with the schema
10097 :type pswd: str
101- :param instance : The database instance (service_name) that is being connected to.
102- :type instance : str
103- :param server : The server that the instance resides on
104- :type server : str
98+ :param serviceName : The database serviceName (service_name) that is being connected to.
99+ :type serviceName : str
100+ :param host : The host that the serviceName resides on
101+ :type host : str
105102 :param port: the port that the database listener is attached to.
106103 :type port: int
107104 '''
@@ -112,56 +109,20 @@ def connectNoDSN(self, user, pswd, instance, server, port=1521):
112109 cxOraPath = os .path .abspath (cx_Oracle .__file__ )
113110 self .logger .debug ("cx_oracle path is: %s" , cxOraPath )
114111
115- # dsn = cx_Oracle.makedsn(server , port, service_name=instance )
116- dsn = cx_Oracle .makedsn (server , port , service_name = instance ) # pylint: disable=no-member
117- self .logger .info ("successfully connected to host/sn %s/%s" , server , instance )
112+ # dsn = cx_Oracle.makedsn(host , port, service_name=serviceName )
113+ dsn = cx_Oracle .makedsn (host , port , service_name = serviceName ) # pylint: disable=no-member
114+ self .logger .info ("successfully connected to host/sn %s/%s" , host , serviceName )
118115 except Exception , e : # pylint: disable=broad-except
119116 msg = u'Got an error trying to create the dsn using the ' + \
120117 u'service_name keyword. Trying with no keywords'
121118 self .logger .debug (msg )
122119 self .logger .debug (repr (e ))
123- msg = u'input params are, server : {0}, port: {1}, inst {2}'
124- msg = msg .format (server , port , instance )
125- dsn = cx_Oracle .makedsn (server , port , instance ).replace (u'SID' , u'SERVICE_NAME' ) # pylint: disable=no-member
120+ msg = u'input params are, host : {0}, port: {1}, inst {2}'
121+ msg = msg .format (host , port , serviceName )
122+ dsn = cx_Oracle .makedsn (host , port , serviceName ).replace (u'SID' , u'SERVICE_NAME' ) # pylint: disable=no-member
126123 self .logger .debug (u'dsn returned is: %s' , dsn )
127124 self .connectParams (user , pswd , dsn )
128125
129- def connect (self , configFile ):
130- '''
131- :param configFile: a config file containing the connection parameters.
132- :type configFile: string (filepath)
133-
134- This is kind of a legacy method. Originally when this module was
135- created the idea is that connection parameters would be stored in a file.
136- Have now abandoned that idea, and now connection info is generally handled
137- by the secrets api. Secrets retrieves the parameters. This module then
138- receives them and uses them.
139-
140- This function will extract the parameters from the db config file and
141- create a connection using the parameters found in that file.
142- '''
143- self .confObj = Misc .AppConfigs .Config (configFile )
144- self .__getDbParams ()
145- self .connectParams ()
146-
147- def __getDbParams (self ):
148- '''
149- Retrieves the database parameters from the database config file.
150- '''
151- # get directory that this module is in, backup one, then go
152- # into config
153-
154- dbParamFileWithPath = self .confObj .getFullPathToDbParamsFile ()
155- print 'dbParamFileWithPath' , dbParamFileWithPath
156- fh = open (dbParamFileWithPath , 'r' )
157- self .dbParams ['username' ] = fh .readline ().replace ("\n " , "" )
158- self .dbParams ['password' ] = fh .readline ().replace ("\n " , "" )
159- self .dbParams ['instance' ] = fh .readline ().replace ("\n " , "" )
160- msg = "using the db accoung: " + str (self .dbParams ['username' ]) + \
161- " and the instance: " + str (self .dbParams ['instance' ])
162- self .logger .debug (msg )
163- fh .close ()
164-
165126 def commit (self ):
166127 '''
167128 commits the current connection
0 commit comments