Skip to content

Commit 0adb43b

Browse files
authored
Merge pull request #10 from NCAR/hua-work-common
Hua work common
2 parents b617384 + 1ce96d8 commit 0adb43b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "rda_python_common"
7-
version = "1.0.5"
7+
version = "1.0.6"
88

99
authors = [
1010
{ name="Zaihua Ji", email="zji@ucar.edu" },

src/rda_python_common/PgDBI.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# hard coded db ports for dbnames
3939
DBPORTS = {
40-
'default' : 5432
40+
'default' : 0
4141
}
4242

4343
DBPASS = {}
@@ -517,9 +517,9 @@ def pgconnect(reconnect = 0, pgcnt = 0, autocommit = True):
517517
config['host'] = PGDBI['DBHOST'] if PGDBI['DBHOST'] else PGDBI['DEFHOST']
518518
if not PGDBI['DBPORT']: PGDBI['DBPORT'] = get_dbport(PGDBI['DBNAME'])
519519
if PGDBI['DBPORT']: config['port'] = PGDBI['DBPORT']
520-
config['password'] = get_pgpass_password()
521-
520+
config['password'] = '***'
522521
sqlstr = "psycopg2.connect(**{})".format(config)
522+
config['password'] = get_pgpass_password()
523523
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, sqlstr)
524524
try:
525525
PgLOG.PGLOG['PGDBBUF'] = pgdb = PgSQL.connect(**config)
@@ -2221,8 +2221,10 @@ def pgname(str, sign = None):
22212221
def get_pgpass_password():
22222222

22232223
if PGDBI['PWNAME']: return PGDBI['PWNAME']
2224-
if not DBPASS: read_pgpass()
2225-
return DBPASS.get((PGDBI['DBSHOST'], PGDBI['DBPORT'], PGDBI['DBNAME'], PGDBI['LNNAME']))
2224+
if not DBPASS: read_pgpass()
2225+
dbport = str(PGDBI['DBPORT']) if PGDBI['DBPORT'] else '5432'
2226+
pwname = DBPASS.get((PGDBI['DBSHOST'], dbport, PGDBI['DBNAME'], PGDBI['LNNAME']))
2227+
if not pwname: pwname = DBPASS.get((PGDBI['DBHOST'], dbport, PGDBI['DBNAME'], PGDBI['LNNAME']))
22262228

22272229
#
22282230
# Reads the .pgpass file and returns a dictionary of credentials.
@@ -2234,7 +2236,7 @@ def read_pgpass():
22342236
for line in f:
22352237
line = line.strip()
22362238
if not line or line.startswith("#"): continue
2237-
dbhost, dbport, dbname, usname, pwname = line.split(":")
2238-
DBPASS[(dbhost, dbport, dbname, usname)] = pwname
2239+
dbhost, dbport, dbname, lnname, pwname = line.split(":")
2240+
DBPASS[(dbhost, dbport, dbname, lnname)] = pwname
22392241
except FileNotFoundError:
22402242
pass

0 commit comments

Comments
 (0)