Skip to content

Commit 5b7c805

Browse files
committed
Merge branch 'python2' of https://github.com/bcgov/dbc-pylib into python2
2 parents 0359b9f + 296967f commit 5b7c805

File tree

18 files changed

+904
-135
lines changed

18 files changed

+904
-135
lines changed

DB/DB/DbLib.py

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import os
3131

3232
import cx_Oracle
33-
import Misc.AppConfigs
3433

3534

3635
class 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

DB/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from setuptools import setup
88

99
setup(name='DB',
10-
version='0.4',
10+
version='1.0',
1111
description='wrapper for database communication',
1212
url='httpshttps://github.com/bcgov/dbc-pylib/tree/master/DB',
1313
author='Kevin Netherton',

DBCSecrets/DBCSecrets/GetSecrets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ def loadSecrets(self):
856856
'in the secrets file {1}'
857857
raise ValueError(msg.format(
858858
self.const.secrets_env_var, secretsFileFullPath))
859+
self.logger.debug("secretString: %s", secretString)
859860
struct = json.loads(secretString)
860861
self.secretsStruct = struct
861862

FMEUtil/FMEUtil/FMEConstants.py

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
used to keep track of property names used by fme rest api.
77
'''
88
from enum import Enum
9-
from lxml.html.builder import ACRONYM
109

1110

1211
class Schedule(Enum):
@@ -32,4 +31,98 @@ class FMEFrameworkPublishedParameters(Enum):
3231
KIRK_JOBLABEL = 4
3332

3433

35-
34+
class Workspace(Enum):
35+
lastSaveDate = 1
36+
lastPublishDate = 2
37+
name = 3
38+
description = 4
39+
repositoryName = 5
40+
title = 6
41+
type = 7
42+
userName = 8
43+
44+
class WorkspaceInfo(Enum):
45+
'''
46+
sample data
47+
u'buildNumber': 17539,
48+
u'category': u'DataBC Warehouse Replication',
49+
u'name': u'OBJECTID',
50+
u'datasets': { u'destination': [ { u'featuretypes': [ { u'attributes': [ { u'decimals': 0,
51+
52+
'''
53+
buildNumber = 1
54+
category = 2
55+
datasets = 3
56+
description = 4
57+
enabled = 5
58+
fileSize = 6
59+
history = 7
60+
isVersioned = 8
61+
lastPublishDate = 9
62+
lastSaveBuild = 10
63+
lastSaveDate = 11
64+
legalTermsConditions = 12
65+
name = 13
66+
parameters = 14
67+
properties = 15
68+
requirements = 16
69+
requirementsKeyword = 17
70+
resources = 18
71+
services = 19
72+
title = 20
73+
type = 21
74+
usage = 22
75+
userName = 23
76+
77+
class Properties(Enum):
78+
attributes = 1
79+
category = 2
80+
name = 3
81+
value = 4
82+
83+
class Parameters(Enum):
84+
'''
85+
example data:
86+
{ u'defaultValue': u'PROXY_FADM_WHSE',
87+
u'description': u'Source schema used to login to the database (upper case only please)',
88+
u'model': u'string',
89+
u'name': u'SRC_ORA_PROXY_SCHEMA',
90+
u'type': u'TEXT'},
91+
{ u'defaultValue': u'DLV',
92+
u'description': u'Destination Database Keyword (DLV|TST|PRD)',
93+
u'listOptions': [ { u'caption': u'DLV',
94+
u'value': u'DLV'},
95+
{ u'caption': u'TST',
96+
u'value': u'TST'},
97+
{ u'caption': u'PRD',
98+
u'value': u'PRD'},
99+
{ u'caption': u'DEV',
100+
u'value': u'DEV'}],
101+
'''
102+
defaultValue = 1
103+
description = 2
104+
model = 3
105+
name = 4
106+
type = 5
107+
listOptions = 6
108+
109+
class DataSets(Enum):
110+
# both of these properties are tied to lists
111+
destination = 1
112+
source = 2
113+
114+
class DataSet(Enum):
115+
'''
116+
example of data:
117+
u'format': u'SDE30',
118+
u'location': u'random.bcgov',
119+
u'name': u'SDE30_1',
120+
u'properties': [ { u'attributes': { }, ...
121+
u'source': True}
122+
123+
'''
124+
featuretypes = 1
125+
format = 2
126+
location = 3
127+
properties = 4
128+
source = 5

0 commit comments

Comments
 (0)