Skip to content

Commit df8fd2d

Browse files
author
zaihuaji
committed
Fix undefined variables
1 parent 192f2f4 commit df8fd2d

File tree

8 files changed

+31
-40
lines changed

8 files changed

+31
-40
lines changed

src/rda_python_common/PgCMD.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def get_partition_control(pgpart, pgrqst = None, pgctl = None, logact = 0):
307307
if not pgctl:
308308
if not pgrqst and pgpart['rindex']:
309309
pgrqst = PgDBI.pgget("dsrqst", "dsid, gindex, cindex, rqsttype", "rindex = {}".format(pgpart['rindex']), logact)
310-
if pgrqst: pgctl = get_dsrqst_control(dsrqst, logact)
310+
if pgrqst: pgctl = get_dsrqst_control(pgrqst, logact)
311311

312312
return pgctl
313313

src/rda_python_common/PgDBI.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ def add_new_table(tname, pre = None, suf = None, logact = 0):
413413
def valid_table(tname, pre = None, suf = None, logact = 0):
414414

415415
if pre:
416-
tbname = '{}_{}'.format(pre, tbname)
416+
tbname = '{}_{}'.format(pre, tname)
417417
elif suf:
418-
tbname = '{}_{}'.format(tbname, suf)
418+
tbname = '{}_{}'.format(tname, suf)
419419
else:
420420
tbname = tname
421421
if tbname in ADDTBLS: return tbname
@@ -1141,7 +1141,7 @@ def pghupdt(tablename, record, cnddict, logact = PGDBI['ERRLOG']):
11411141
break
11421142
pgcnt += 1
11431143

1144-
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, "pgmupdt: {}/{} record(s) updated to {}".format(count, cntrow, tablename))
1144+
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, "pghupdt: {}/{} record(s) updated to {}".format(ucnt, tablename))
11451145
if(logact&PgLOG.ENDLCK):
11461146
endtran()
11471147
elif curtran:
@@ -1191,7 +1191,7 @@ def pgmupdt(tablename, records, cnddicts, logact = PGDBI['ERRLOG']):
11911191

11921192
pgcur.close()
11931193

1194-
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, "pgmupdt: {}/{} record(s) updated to {}".format(ucnt, cntrow, tablename))
1194+
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, "pgmupdt: {} record(s) updated to {}".format(ucnt, tablename))
11951195
if(logact&PgLOG.ENDLCK):
11961196
endtran()
11971197
elif curtran:
@@ -1264,7 +1264,7 @@ def pghdel(tablename, cnddict, logact = PGDBI['ERRLOG']):
12641264
if not cnddict or isinstance(cnddict, int): PgLOG.pglog("Miss condition dict to delete from " + tablename, logact)
12651265
sqlstr = prepare_delete(tablename, None, list(cnddict))
12661266

1267-
values = tuple(cnddicts.values())
1267+
values = tuple(cnddict.values())
12681268
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, "Delete from {} for {}".format(tablename, values))
12691269

12701270
dcnt = pgcnt = 0
@@ -1306,7 +1306,7 @@ def pgmdel(tablename, cnddicts, logact = PGDBI['ERRLOG']):
13061306
values = list(zip(*v))
13071307
if PgLOG.PGLOG['DBGLEVEL']:
13081308
for row in values:
1309-
PgLOG.pgdbg(1000, "Delete from {} for {}".format(tablenames, row))
1309+
PgLOG.pgdbg(1000, "Delete from {} for {}".format(tablename, row))
13101310

13111311
dcnt = pgcnt = 0
13121312
while True:
@@ -1411,7 +1411,7 @@ def pgcheck(tablename, logact = 0):
14111411
def check_user_uid(userno, date = None):
14121412

14131413
if not userno: return 0
1414-
if tyep(userno) is str: userno = int(userno)
1414+
if type(userno) is str: userno = int(userno)
14151415

14161416
if date is None:
14171417
datecond = "until_date IS NULL"
@@ -1433,7 +1433,7 @@ def check_user_uid(userno, date = None):
14331433
pgrec = ucar_user_info(userno)
14341434
if not pgrec: pgrec = {'userno' : userno, 'stat_flag' : 'M'}
14351435
uid = pgadd("dssdb.user", pgrec, (PGDBI['EXITLG']|PgLOG.AUTOID))
1436-
if uid: PgLOG.pglog("{}: Scientist ID Added as user.uid = {}".format(useno, uid), PgLOG.LGWNEM)
1436+
if uid: PgLOG.pglog("{}: Scientist ID Added as user.uid = {}".format(userno, uid), PgLOG.LGWNEM)
14371437

14381438
return uid
14391439

@@ -1629,14 +1629,6 @@ def check_cdp_wuser(username):
16291629
pgrec = pgget("wuser", "wuid", "cdpname = '{}'".format(username), PGDBI['EXITLG'])
16301630
if pgrec: return pgrec['wuid']
16311631

1632-
# missing wuser record add one in
1633-
pgrec = get_cdp_user(None, None, username)
1634-
if not pgrec:
1635-
if username not in LMISSES:
1636-
PgLOG.pglog("Missing CDP User '{}'".format(username), PgLOG.LGWNEM)
1637-
LMISSES['username'] = 1
1638-
return 0
1639-
16401632
idrec = pgget("wuser", "wuid", "email = '{}'".format(pgrec['email']), PGDBI['EXITLG'])
16411633
wuid = idrec['wuid'] if idrec else 0
16421634
if wuid > 0:

src/rda_python_common/PgFile.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def move_object_file(tofile, fromfile, tobucket, frombucket, logact = 0):
948948
return PgLOG.FAILURE
949949

950950
cmd = "{} mv -b {} -db {} -k {} -dk {}".format(OBJCTCMD, frombucket, tobucket, fromfile, tofile)
951-
ucmd = "{} gm -k {} -b {}".format(OBJCTCMD, fromfile, bucket)
951+
ucmd = "{} gm -k {} -b {}".format(OBJCTCMD, fromfile, frombucket)
952952
ubuf = PgLOG.pgsystem(ucmd, PgLOG.LOGWRN, CMDRET)
953953
if ubuf and re.match(r'^\{', ubuf): cmd += " -md '{}'".format(ubuf)
954954

@@ -1146,7 +1146,7 @@ def make_one_backup_directory(dir, odir, endpoint = None, logact = 0):
11461146
if not endpoint: endpoint = PgLOG.PGLOG['BACKUPEP']
11471147
info = check_backup_file(dir, endpoint, 0, logact)
11481148
if info:
1149-
if info['isfile']: return errlog("{}-{}: is file, cannot make backup directory".format(enpdpoint, dir), 'B', 1, logact)
1149+
if info['isfile']: return errlog("{}-{}: is file, cannot make backup directory".format(endpoint, dir), 'B', 1, logact)
11501150
return PgLOG.SUCCESS
11511151
elif info != None:
11521152
return PgLOG.FAILURE
@@ -1166,10 +1166,9 @@ def make_one_backup_directory(dir, odir, endpoint = None, logact = 0):
11661166
if syserr:
11671167
if syserr.find("No such file or directory") > -1:
11681168
ret = make_one_backup_directory(op.dirname(dir), odir, endpoint, logact)
1169-
if ret == PgLOG.SUCCESS or loop or opt&64 == 0: break
1169+
if ret == PgLOG.SUCCESS or loop: break
11701170
time.sleep(PgSIG.PGSIG['ETIME'])
11711171
else:
1172-
if opt&64 == 0: return PgLOG.FAILURE
11731172
errmsg = "Error Execute: {}\n{}".format(cmd, syserr)
11741173
(hstat, msg) = host_down_status('', QHOSTS[endpoint], 1, logact)
11751174
if hstat: errmsg += "\n" + msg
@@ -1293,7 +1292,7 @@ def change_local_group(file, ngrp = None, ogrp = None, logname = None, logact =
12931292
if ngid == ogid: return PgLOG.SUCCESS
12941293

12951294
try:
1296-
os.chown(file, nuid, ngid)
1295+
os.chown(file, ouid, ngid)
12971296
except Exception as e:
12981297
return errlog(str(e), 'L', 1, logact)
12991298

@@ -1892,7 +1891,7 @@ def backup_file_stat(line, opt):
18921891
mtime = items[5]
18931892
ms = re.match(r'^(\d+:\d+:\d+)', mtime)
18941893
if ms: mtime = ms.group(1)
1895-
if PgLOG.PGLOG['GMTZ']: (mdate, mtime) = PgUtil.addhour(date, time, PgLOG.PGLOG['GMTZ'])
1894+
if PgLOG.PGLOG['GMTZ']: (mdate, mtime) = PgUtil.addhour(mdate, mtime, PgLOG.PGLOG['GMTZ'])
18961895
if opt&1:
18971896
info['date_modified'] = mdate
18981897
info['time_modified'] = mtime

src/rda_python_common/PgLock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def lock_partition(pidx, dolock, logact = 0):
485485
if logout: PgLOG.pglog(pinfo + ": error update lock", logout)
486486
pidx = -pidx
487487
else:
488-
PgLOG.pglog("{}: Relocked {}/{}".format(pinfom, lkrec['pid'], lkrec['lockhost']), logout)
488+
PgLOG.pglog("{}: Relocked {}/{}".format(pinfo, lkrec['pid'], lkrec['lockhost']), logout)
489489
pidx = -pidx
490490

491491
return end_db_transaction(pidx)

src/rda_python_common/PgOPT.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,14 +1240,14 @@ def compress_files(files, formats, count):
12401240
strcmp = 'Compress'
12411241
actcmp = 1
12421242
fmtcnt = len(formats)
1243-
if not fmtcont: return files # just in case
1243+
if not fmtcnt: return files # just in case
12441244
s = 's' if count > 1 else ''
12451245
PgLOG.pglog("{}ing {} File{} for {} ...".format(strcmp, count, s, params['DS']), PGOPT['wrnlog'])
12461246
cmpcnt = 0
12471247
for i in range(count):
1248-
fmt = formats[i] if(i < fntcmt and formats[i]) else formats[0]
1249-
(ofile, fmt) = PgFile.compress_local_file(files[i], fmt, cmpact, MUYOPT['extlog'])
1250-
if ofiles != files[i]:
1248+
fmt = formats[i] if(i < fntcnt and formats[i]) else formats[0]
1249+
(ofile, fmt) = PgFile.compress_local_file(files[i], fmt, cmpact, PGOPT['extlog'])
1250+
if ofile != files[i]:
12511251
files[i] = ofile
12521252
cmpcnt += 1
12531253

src/rda_python_common/PgPGS.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ def pgs_sql_file(tablenames, fields, condition = None):
2727

2828
sqlfile = "{}/pgs{}.sql".format(PGPGS['SQLPATH'], os.getpid())
2929

30-
sqlstr = "SELECT {}\nFROM {}".format(fields, tablename)
30+
sqlstr = "SELECT {}\nFROM {}".format(fields, tablenames)
3131
if condition:
3232
if re.match(r'^\s*(ORDER|GROUP|HAVING)\s', condition, re.I):
33-
slqstr += "\n{}".format(condition)
33+
sqlstr += "\n{}".format(condition)
3434
else:
3535
sqlstr += "\nWHERE {}".format(condition)
36-
asqlstr += ";\n"
36+
sqlstr += ";\n"
3737
try:
3838
SQL = open(sqlfile, 'w')
3939
SQL.write(sqlstr)
40-
close(SQL)
40+
SQL.close()
4141
except Exception as e:
4242
PgLOG.pglog("Error Open '{}': {}".format(sqlfile, str(e)), PgLOG.LGWNEX)
4343

@@ -63,7 +63,7 @@ def pgsget(tablenames, fields, condition = None, logact = 0):
6363
for line in re.split(r'\n', sqlout):
6464
vals = re.split(r'\s*\|\s+', line)
6565
if colcnt: # gather data
66-
record = dict(zip(filds, vals))
66+
record = dict(zip(fields, vals))
6767
break
6868
else: # gather field names
6969
flds = vals
@@ -91,7 +91,7 @@ def pgsget(tablenames, fields, condition = None, logact = 0):
9191
def pgsmget(tablenames, fields, condition = None, logact = 0):
9292

9393
sqlfile = pgs_sql_file(tablenames, fields, condition)
94-
sqlout = pgsystem("psql {} < {}".format(PGPGS['PGSSERV'], sqlfile), logact, 273+1024) # 1+16+256
94+
sqlout = PgLOG.pgsystem("psql {} < {}".format(PGPGS['PGSSERV'], sqlfile), logact, 273+1024) # 1+16+256
9595

9696
rowcnt = colcnt = 0
9797
records = {}

src/rda_python_common/PgSIG.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def validate_multiple_process(aname, plimit, uname = None, sargv = None, logact
353353
if pcnt >= plimit:
354354
msg = aname
355355
if sargv: msg += ' ' + sargv
356-
msg += ": already running in {} processes on {}".format(pid, PgLOG.PGLOG['HOSTNAME'])
356+
msg += ": already running in {} processes on {}".format(pcnt, PgLOG.PGLOG['HOSTNAME'])
357357
if uname: msg += ' By ' + uname
358358
PgLOG.pglog(msg + ', Quit Now', logact)
359359
sys.exit(0)
@@ -1044,9 +1044,8 @@ def check_background(bcmd, bid = 0, logact = PgLOG.LOGWRN, dowait = 0):
10441044

10451045
if logact&PgLOG.EXITLG: logact &= ~PgLOG.EXITLG
10461046
if not bid and bcmd: bid = bcmd2cbid(bcmd)
1047-
i = 0
1047+
bcnt = i = 0
10481048
while True:
1049-
bcnt = 0;
10501049
if bid:
10511050
if check_process(bid): # process is not done yet
10521051
if bcmd:
@@ -1064,8 +1063,9 @@ def check_background(bcmd, bid = 0, logact = PgLOG.LOGWRN, dowait = 0):
10641063
del CBIDS[bid]
10651064

10661065
if not (bcnt and dowait): break
1067-
show_wait_message(i, "{}: wait {}/{} background processes".format(PGSIG['DSTR'], pcnt, PGSIG['MPROC']), logact, dowait)
1066+
show_wait_message(i, "{}: wait {}/{} background processes".format(PGSIG['DSTR'], bcnt, PGSIG['MPROC']), logact, dowait)
10681067
i += 1
1068+
bcnt = 0
10691069

10701070
return bcnt
10711071

@@ -1135,7 +1135,7 @@ def show_wait_message(loop, msg, logact = PgLOG.LOGWRN, dowait = 0):
11351135
@contextmanager
11361136
def pgtimeout(seconds = 0, logact = 0):
11371137

1138-
if not seconds: seconds = PGLOG['TIMEOUT']
1138+
if not seconds: seconds = PgLOG.PGLOG['TIMEOUT']
11391139
signal.signal(signal.SIGALRM, raise_pgtimeout)
11401140
signal.alarm(seconds)
11411141
try:

src/rda_python_common/PgSplit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def pgadd_wfile(dsid, wfrec, logact = PgLOG.LOGERR, getid = None):
138138
def pgmadd_wfile(dsid, wfrecs, logact = PgLOG.LOGERR, getid = None):
139139

140140
records = {'wfile' : wfrecs['wfile'],
141-
'dsid' : (wfrecs['dsid'] if 'dsid' in wfrecs else [dsid]*len(records['wfile']))}
141+
'dsid' : (wfrecs['dsid'] if 'dsid' in wfrecs else [dsid]*len(wfrecs['wfile']))}
142142
wret = PgDBI.pgmadd('wfile', records, logact, 'wid')
143143
wcnt = wret if isinstance(wret, int) else len(wret)
144144
if wcnt:

0 commit comments

Comments
 (0)