rda-python-common 1.0.30__py3-none-any.whl → 1.0.33__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rda-python-common might be problematic. Click here for more details.
- rda_python_common/PgDBI.py +20 -16
- rda_python_common/PgFile.py +1 -1
- rda_python_common/PgLOG.py +43 -22
- rda_python_common/PgOPT.py +2 -2
- {rda_python_common-1.0.30.dist-info → rda_python_common-1.0.33.dist-info}/METADATA +1 -1
- rda_python_common-1.0.33.dist-info/RECORD +15 -0
- rda_python_common-1.0.30.dist-info/RECORD +0 -15
- {rda_python_common-1.0.30.dist-info → rda_python_common-1.0.33.dist-info}/WHEEL +0 -0
- {rda_python_common-1.0.30.dist-info → rda_python_common-1.0.33.dist-info}/licenses/LICENSE +0 -0
- {rda_python_common-1.0.30.dist-info → rda_python_common-1.0.33.dist-info}/top_level.txt +0 -0
rda_python_common/PgDBI.py
CHANGED
|
@@ -315,13 +315,13 @@ def aborttran(autocommit = True):
|
|
|
315
315
|
#
|
|
316
316
|
# record error message to dscheck record and clean the lock
|
|
317
317
|
#
|
|
318
|
-
def record_dscheck_error(errmsg):
|
|
318
|
+
def record_dscheck_error(errmsg, logact = PGDBI['EXITLG']):
|
|
319
319
|
|
|
320
320
|
cnd = PgLOG.PGLOG['DSCHECK']['chkcnd']
|
|
321
321
|
if PgLOG.PGLOG['NOQUIT']: PgLOG.PGLOG['NOQUIT'] = 0
|
|
322
322
|
dflags = PgLOG.PGLOG['DSCHECK']['dflags']
|
|
323
323
|
|
|
324
|
-
pgrec = pgget("dscheck", "mcount, tcount, lockhost, pid", cnd,
|
|
324
|
+
pgrec = pgget("dscheck", "mcount, tcount, lockhost, pid", cnd, logact)
|
|
325
325
|
if not pgrec: return 0
|
|
326
326
|
if not pgrec['pid'] and not pgrec['lockhost']: return 0
|
|
327
327
|
(chost, cpid) = PgLOG.current_process_info()
|
|
@@ -330,8 +330,9 @@ def record_dscheck_error(errmsg):
|
|
|
330
330
|
# update dscheck record only if it is still locked by the current process
|
|
331
331
|
record = {}
|
|
332
332
|
record['chktime'] = int(time.time())
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
if logact&PgLOG.EXITLG:
|
|
334
|
+
record['status'] = "E"
|
|
335
|
+
record['pid'] = 0 # release lock
|
|
335
336
|
if dflags:
|
|
336
337
|
record['dflags'] = dflags
|
|
337
338
|
record['mcount'] = pgrec['mcount'] + 1
|
|
@@ -343,7 +344,7 @@ def record_dscheck_error(errmsg):
|
|
|
343
344
|
if pgrec['tcount'] > 1: errmsg = "Try {}: {}".format(pgrec['tcount'], errmsg)
|
|
344
345
|
record['errmsg'] = errmsg
|
|
345
346
|
|
|
346
|
-
return pgupdt("dscheck", record, cnd,
|
|
347
|
+
return pgupdt("dscheck", record, cnd, logact)
|
|
347
348
|
|
|
348
349
|
#
|
|
349
350
|
# local function to log query error
|
|
@@ -367,7 +368,7 @@ def qelog(dberror, sleep, sqlstr, vals, pgcnt, logact = PGDBI['ERRLOG']):
|
|
|
367
368
|
if vals: sqlstr += " with values: " + str(vals)
|
|
368
369
|
|
|
369
370
|
if dberror: sqlstr = "{}\n{}".format(dberror, sqlstr)
|
|
370
|
-
if logact&PgLOG.EXITLG and PgLOG.PGLOG['DSCHECK']: record_dscheck_error(sqlstr)
|
|
371
|
+
if logact&PgLOG.EXITLG and PgLOG.PGLOG['DSCHECK']: record_dscheck_error(sqlstr, logact)
|
|
371
372
|
PgLOG.pglog(sqlstr, logact)
|
|
372
373
|
if sleep: time.sleep(sleep)
|
|
373
374
|
|
|
@@ -1848,21 +1849,24 @@ def build_customized_email(table, field, condition, subject, logact = 0):
|
|
|
1848
1849
|
estat = PgLOG.FAILURE
|
|
1849
1850
|
msg = PgLOG.get_email()
|
|
1850
1851
|
if not msg: return estat
|
|
1851
|
-
|
|
1852
|
+
|
|
1852
1853
|
sender = PgLOG.PGLOG['CURUID'] + "@ucar.edu"
|
|
1853
1854
|
receiver = PgLOG.PGLOG['EMLADDR'] if PgLOG.PGLOG['EMLADDR'] else (PgLOG.PGLOG['CURUID'] + "@ucar.edu")
|
|
1854
1855
|
if receiver.find(sender) < 0: PgLOG.add_carbon_copy(sender, 1)
|
|
1855
|
-
|
|
1856
|
-
if PgLOG.PGLOG['CCDADDR']: ebuf += "Cc: {}\n".format(PgLOG.PGLOG['CCDADDR'])
|
|
1856
|
+
cc = PgLOG.PGLOG['CCDADDR']
|
|
1857
1857
|
if not subject: subject = "Message from {}-{}".format(PgLOG.PGLOG['HOSTNAME'], PgLOG.get_command())
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
if PgLOG.PGLOG['EMLSEND']:
|
|
1861
|
-
estat = PgLOG.send_customized_email(f"{table}.{condition}", ebuf, logact)
|
|
1858
|
+
estat = PgLOG.send_python_email(subject, receiver, msg, sender, cc, logact)
|
|
1862
1859
|
if estat != PgLOG.SUCCESS:
|
|
1863
|
-
|
|
1864
|
-
if
|
|
1865
|
-
|
|
1860
|
+
ebuf = "From: {}\nTo: {}\n".format(sender, receiver)
|
|
1861
|
+
if cc: ebuf += "Cc: {}\n".format(cc)
|
|
1862
|
+
ebuf += "Subject: {}!\n\n{}\n".format(subject, msg)
|
|
1863
|
+
|
|
1864
|
+
if PgLOG.PGLOG['EMLSEND']:
|
|
1865
|
+
estat = PgLOG.send_customized_email(f"{table}.{condition}", ebuf, logact)
|
|
1866
|
+
if estat != PgLOG.SUCCESS:
|
|
1867
|
+
estat = cache_customized_email(table, field, condition, ebuf, 0)
|
|
1868
|
+
if estat and logact:
|
|
1869
|
+
PgLOG.pglog("Email {} cached to '{}.{}' for {}, Subject: {}".format(receiver, table, field, condition, subject), logact)
|
|
1866
1870
|
|
|
1867
1871
|
return estat
|
|
1868
1872
|
|
rda_python_common/PgFile.py
CHANGED
|
@@ -145,7 +145,7 @@ def errlog(msg, etype, retry = 0, logact = 0):
|
|
|
145
145
|
logact |= PgLOG.EXITLG
|
|
146
146
|
ECNTS[etype] = 0
|
|
147
147
|
|
|
148
|
-
if PgLOG.PGLOG['DSCHECK'] and logact&PgLOG.EXITLG: PgDBI.record_dscheck_error(msg)
|
|
148
|
+
if PgLOG.PGLOG['DSCHECK'] and logact&PgLOG.EXITLG: PgDBI.record_dscheck_error(msg, logact)
|
|
149
149
|
PgLOG.pglog(msg, logact)
|
|
150
150
|
PgLOG.PGLOG['BCKGRND'] = bckgrnd
|
|
151
151
|
if not retry: time.sleep(PgSIG.PGSIG['ETIME'])
|
rda_python_common/PgLOG.py
CHANGED
|
@@ -20,6 +20,8 @@ import re
|
|
|
20
20
|
import pwd
|
|
21
21
|
import grp
|
|
22
22
|
import shlex
|
|
23
|
+
import smtplib
|
|
24
|
+
from email.message import EmailMessage
|
|
23
25
|
from subprocess import Popen, PIPE
|
|
24
26
|
from os import path as op
|
|
25
27
|
import time
|
|
@@ -116,7 +118,7 @@ PGLOG = { # more defined in untaint_suid() with environment variables
|
|
|
116
118
|
'PGBATCH' : '', # current batch service name, SLURM or PBS
|
|
117
119
|
'PGBINDIR' : '',
|
|
118
120
|
'SLMTIME' : 604800, # max runtime for SLURM bath job, (7x24x60x60 seconds)
|
|
119
|
-
'PBSTIME' : 86400, # max runtime for
|
|
121
|
+
'PBSTIME' : 86400, # max runtime for PBS bath job, (24x60x60 seconds)
|
|
120
122
|
'MSSGRP' : None, # set if set to different HPSS group
|
|
121
123
|
'RDAGRP' : "decs",
|
|
122
124
|
'EMLSEND' : None, # path to sendmail, None if not exists
|
|
@@ -131,7 +133,9 @@ PGLOG = { # more defined in untaint_suid() with environment variables
|
|
|
131
133
|
'ERR2STD' : [], # if non-empty reference to array of strings, change stderr to stdout if match
|
|
132
134
|
'STD2ERR' : [], # if non-empty reference to array of strings, change stdout to stderr if match
|
|
133
135
|
'MISSFILE': "No such file or directory",
|
|
134
|
-
'GITHUB' : "https://github.com"
|
|
136
|
+
'GITHUB' : "https://github.com" , # github server
|
|
137
|
+
'EMLSRVR' : "ndir.ucar.edu", # UCAR email server and port
|
|
138
|
+
'EMLPORT' : 25
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
HOSTTYPES = {
|
|
@@ -270,19 +274,31 @@ def send_customized_email(logmsg, emlmsg, logact = 0):
|
|
|
270
274
|
if entries['cc'][2]: logmsg += " Cc'd " + entries['cc'][2]
|
|
271
275
|
logmsg += " Subject: " + entries['sb'][2]
|
|
272
276
|
|
|
273
|
-
|
|
277
|
+
ret = FAILURE
|
|
278
|
+
if PGLOG['EMLSEND']: ret = pgsystem(PGLOG['EMLSEND'], logact, 4, emlmsg)
|
|
279
|
+
if not ret: ret = send_python_email(entries['sb'][2], entries['to'][2], emlmsg, entries['fr'][2], entries['cc'][2], logact)
|
|
280
|
+
|
|
281
|
+
if ret:
|
|
274
282
|
log_email(emlmsg)
|
|
275
283
|
if logact: pglog(logmsg, logact&(~EXITLG))
|
|
276
|
-
return SUCCESS
|
|
277
284
|
else:
|
|
278
285
|
errmsg = "Error sending email: " + logmsg
|
|
279
|
-
|
|
286
|
+
pglog(errmsg, (logact|ERRLOG)&~EXITLG)
|
|
287
|
+
|
|
288
|
+
return ret
|
|
280
289
|
|
|
281
290
|
#
|
|
282
|
-
# send an email
|
|
291
|
+
# send an email; if empty msg send email message saved in PGLOG['EMLMSG'] instead
|
|
283
292
|
#
|
|
284
293
|
def send_email(subject = None, receiver = None, msg = None, sender = None, logact = 0):
|
|
285
294
|
|
|
295
|
+
return send_python_email(subject, receiver, msg, sender, None, logact)
|
|
296
|
+
|
|
297
|
+
#
|
|
298
|
+
# send an email via python module smtplib; if empty msg send email message saved in PGLOG['EMLMSG'] instead
|
|
299
|
+
#
|
|
300
|
+
def send_python_email(subject = None, receiver = None, msg = None, sender = None, cc = None, logact = 0):
|
|
301
|
+
|
|
286
302
|
if not msg:
|
|
287
303
|
if PGLOG['EMLMSG']:
|
|
288
304
|
msg = PGLOG['EMLMSG']
|
|
@@ -290,10 +306,10 @@ def send_email(subject = None, receiver = None, msg = None, sender = None, logac
|
|
|
290
306
|
else:
|
|
291
307
|
return ''
|
|
292
308
|
|
|
293
|
-
docc =
|
|
309
|
+
docc = False if cc else True
|
|
294
310
|
if not sender:
|
|
295
311
|
sender = PGLOG['CURUID']
|
|
296
|
-
if sender != PGLOG['RDAUSER']: docc =
|
|
312
|
+
if sender != PGLOG['RDAUSER']: docc = False
|
|
297
313
|
if sender == PGLOG['RDAUSER']: sender = PGLOG['RDAEMAIL']
|
|
298
314
|
if sender.find('@') == -1: sender += "@ucar.edu"
|
|
299
315
|
if not receiver:
|
|
@@ -302,26 +318,31 @@ def send_email(subject = None, receiver = None, msg = None, sender = None, logac
|
|
|
302
318
|
if receiver.find('@') == -1: receiver += "@ucar.edu"
|
|
303
319
|
|
|
304
320
|
if docc and not re.match(PGLOG['RDAUSER'], sender): add_carbon_copy(sender, 1)
|
|
305
|
-
|
|
306
|
-
emlmsg
|
|
321
|
+
emlmsg = EmailMessage()
|
|
322
|
+
emlmsg.set_content(msg)
|
|
323
|
+
emlmsg['From'] = sender
|
|
324
|
+
emlmsg['To'] = receiver
|
|
307
325
|
logmsg = "Email " + receiver
|
|
308
|
-
if PGLOG['CCDADDR']
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
if not cc: cc = PGLOG['CCDADDR']
|
|
327
|
+
if cc:
|
|
328
|
+
emlmsg['Cc'] = cc
|
|
329
|
+
logmsg += " Cc'd " + cc
|
|
311
330
|
if not subject: subject = "Message from {}-{}".format(PGLOG['HOSTNAME'], get_command())
|
|
312
331
|
if not re.search(r'!$', subject): subject += '!'
|
|
313
|
-
emlmsg
|
|
332
|
+
emlmsg['Subject'] = subject
|
|
314
333
|
if CPID['CPID']: logmsg += " in " + CPID['CPID']
|
|
315
334
|
logmsg += ", Subject: {}\n".format(subject)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
335
|
+
try:
|
|
336
|
+
eml = smtplib.SMTP(PGLOG['EMLSRVR'], PGLOG['EMLPORT'])
|
|
337
|
+
eml.send_message(emlmsg)
|
|
338
|
+
except smtplib.SMTPException as err:
|
|
339
|
+
errmsg = f"Error sending email:\n{err}\n{logmsg}"
|
|
340
|
+
return pglog(errmsg, (logact|ERRLOG)&~EXITLG)
|
|
341
|
+
finally:
|
|
342
|
+
eml.quit()
|
|
343
|
+
log_email(str(emlmsg))
|
|
319
344
|
if logact: pglog(logmsg, logact&~EXITLG)
|
|
320
|
-
return
|
|
321
|
-
else:
|
|
322
|
-
errmsg = "Error sending email: " + logmsg
|
|
323
|
-
pglog(logmsg, (logact|ERRLOG)&~EXITLG)
|
|
324
|
-
return errmsg
|
|
345
|
+
return SUCCESS
|
|
325
346
|
|
|
326
347
|
#
|
|
327
348
|
# log email sent
|
rda_python_common/PgOPT.py
CHANGED
|
@@ -985,7 +985,7 @@ def action_error(errmsg, cact = None):
|
|
|
985
985
|
msg += " of " + params['DS'][0]
|
|
986
986
|
|
|
987
987
|
msg += ": " + errmsg
|
|
988
|
-
if PgLOG.PGLOG['DSCHECK']: PgDBI.record_dscheck_error(msg)
|
|
988
|
+
if PgLOG.PGLOG['DSCHECK']: PgDBI.record_dscheck_error(msg, PGOPT['extlog'])
|
|
989
989
|
PgLOG.pglog(msg, PGOPT['extlog'])
|
|
990
990
|
|
|
991
991
|
#
|
|
@@ -1692,7 +1692,7 @@ def send_request_email_notice(pgrqst, errmsg, fcount, rstat, readyfile = None, p
|
|
|
1692
1692
|
tbl = "dsrqst"
|
|
1693
1693
|
cnd = "rindex = {}".format(pgrqst['rindex'])
|
|
1694
1694
|
|
|
1695
|
-
if PgLOG.
|
|
1695
|
+
if PgLOG.send_customized_email(f"{tbl}.{cnd}", ebuf, 0):
|
|
1696
1696
|
if errmsg:
|
|
1697
1697
|
PgLOG.pglog("Error Email sent to {} for {}.{}:\n{}".format(einfo['SENDER'], tbl, cnd, errmsg), PGOPT['errlog'])
|
|
1698
1698
|
readyfile = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_common
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.33
|
|
4
4
|
Summary: RDA Python common library codes shared by other RDA python packages
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-common
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
rda_python_common/PgCMD.py,sha256=EYjG2Z4zEnvsXE1z-jt5UaNoEKxnOYYiMMzvW6HrKA4,20597
|
|
2
|
+
rda_python_common/PgDBI.py,sha256=12qnRXO7pWv8togtTsOvtVuGtwixnR-s2vLGPpdDfHw,74658
|
|
3
|
+
rda_python_common/PgFile.py,sha256=KnG9S0bgXAAhQIoSJWf3zON8xIua3do4New4O_qdlwg,98468
|
|
4
|
+
rda_python_common/PgLOG.py,sha256=kRoUGW5xG5SI7Ubb41RAbnSKItSJ59x8-tGDV52Q810,55251
|
|
5
|
+
rda_python_common/PgLock.py,sha256=12i84nsGBuifSyPnm8IR63LvHvRuVU573D5QKFlHdOI,22623
|
|
6
|
+
rda_python_common/PgOPT.py,sha256=zX8lWFdfV6GxjLKfMc9eM76mjIjss_ulPieerejcmks,55936
|
|
7
|
+
rda_python_common/PgSIG.py,sha256=ZVM9Qz6yIFurwIQJtV5-CFbKOTdFsZ-Rs95SEpDFgNk,35795
|
|
8
|
+
rda_python_common/PgSplit.py,sha256=QKPbF55m8KCTGmwVwL3uG_nuylCC4FSVfLuXeLjJHbE,8816
|
|
9
|
+
rda_python_common/PgUtil.py,sha256=OqESKCd72b9g8m8jwjPJhXDtPYlW6G8oSOhwChvz2Cg,48600
|
|
10
|
+
rda_python_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
rda_python_common-1.0.33.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
|
|
12
|
+
rda_python_common-1.0.33.dist-info/METADATA,sha256=0i7NzCeJ-p0KhJqhbLLojt_MeXzsNwlLl2EfDzg-7vo,716
|
|
13
|
+
rda_python_common-1.0.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
rda_python_common-1.0.33.dist-info/top_level.txt,sha256=KVQmx7D3DD-jsiheqL8HdTrRE14hpRnZY5_ioMArA5k,18
|
|
15
|
+
rda_python_common-1.0.33.dist-info/RECORD,,
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
rda_python_common/PgCMD.py,sha256=EYjG2Z4zEnvsXE1z-jt5UaNoEKxnOYYiMMzvW6HrKA4,20597
|
|
2
|
-
rda_python_common/PgDBI.py,sha256=Q-axfqJ_Ijq2dNcNv5hH63HV_I59pdkM8ZEfZdqri1Q,74480
|
|
3
|
-
rda_python_common/PgFile.py,sha256=756onQnWH_MK8llF0-8b6yV6KC1eY_eCPEkygxeJQQU,98460
|
|
4
|
-
rda_python_common/PgLOG.py,sha256=g0O3_sz5ZHkfZYr4cRuRjYz9qKXF3QUW-kyoSZozUjM,54515
|
|
5
|
-
rda_python_common/PgLock.py,sha256=12i84nsGBuifSyPnm8IR63LvHvRuVU573D5QKFlHdOI,22623
|
|
6
|
-
rda_python_common/PgOPT.py,sha256=G2apwdyeLBBXj6i2C1duUtia7KDzxkB1dpor18WYdT8,55946
|
|
7
|
-
rda_python_common/PgSIG.py,sha256=ZVM9Qz6yIFurwIQJtV5-CFbKOTdFsZ-Rs95SEpDFgNk,35795
|
|
8
|
-
rda_python_common/PgSplit.py,sha256=QKPbF55m8KCTGmwVwL3uG_nuylCC4FSVfLuXeLjJHbE,8816
|
|
9
|
-
rda_python_common/PgUtil.py,sha256=OqESKCd72b9g8m8jwjPJhXDtPYlW6G8oSOhwChvz2Cg,48600
|
|
10
|
-
rda_python_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
rda_python_common-1.0.30.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
|
|
12
|
-
rda_python_common-1.0.30.dist-info/METADATA,sha256=X4CFLBFdVgQGIYS_U51nzJN6srH9Fn8N4SdrXi9qg00,716
|
|
13
|
-
rda_python_common-1.0.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
-
rda_python_common-1.0.30.dist-info/top_level.txt,sha256=KVQmx7D3DD-jsiheqL8HdTrRE14hpRnZY5_ioMArA5k,18
|
|
15
|
-
rda_python_common-1.0.30.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|