rda-python-common 1.0.32__tar.gz → 1.0.33__tar.gz
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-1.0.32 → rda_python_common-1.0.33}/PKG-INFO +1 -1
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/pyproject.toml +1 -1
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgDBI.py +13 -10
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgLOG.py +43 -22
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgOPT.py +1 -1
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/PKG-INFO +1 -1
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/LICENSE +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/README.md +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/setup.cfg +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgCMD.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgFile.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgLock.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgSIG.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgSplit.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/PgUtil.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common/__init__.py +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/SOURCES.txt +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/dependency_links.txt +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/requires.txt +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/top_level.txt +0 -0
- {rda_python_common-1.0.32 → rda_python_common-1.0.33}/test/test_common.py +0 -0
|
@@ -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
|
|
@@ -1849,21 +1849,24 @@ def build_customized_email(table, field, condition, subject, logact = 0):
|
|
|
1849
1849
|
estat = PgLOG.FAILURE
|
|
1850
1850
|
msg = PgLOG.get_email()
|
|
1851
1851
|
if not msg: return estat
|
|
1852
|
-
|
|
1852
|
+
|
|
1853
1853
|
sender = PgLOG.PGLOG['CURUID'] + "@ucar.edu"
|
|
1854
1854
|
receiver = PgLOG.PGLOG['EMLADDR'] if PgLOG.PGLOG['EMLADDR'] else (PgLOG.PGLOG['CURUID'] + "@ucar.edu")
|
|
1855
1855
|
if receiver.find(sender) < 0: PgLOG.add_carbon_copy(sender, 1)
|
|
1856
|
-
|
|
1857
|
-
if PgLOG.PGLOG['CCDADDR']: ebuf += "Cc: {}\n".format(PgLOG.PGLOG['CCDADDR'])
|
|
1856
|
+
cc = PgLOG.PGLOG['CCDADDR']
|
|
1858
1857
|
if not subject: subject = "Message from {}-{}".format(PgLOG.PGLOG['HOSTNAME'], PgLOG.get_command())
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if PgLOG.PGLOG['EMLSEND']:
|
|
1862
|
-
estat = PgLOG.send_customized_email(f"{table}.{condition}", ebuf, logact)
|
|
1858
|
+
estat = PgLOG.send_python_email(subject, receiver, msg, sender, cc, logact)
|
|
1863
1859
|
if estat != PgLOG.SUCCESS:
|
|
1864
|
-
|
|
1865
|
-
if
|
|
1866
|
-
|
|
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)
|
|
1867
1870
|
|
|
1868
1871
|
return estat
|
|
1869
1872
|
|
|
@@ -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
|
|
@@ -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
|
{rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/PKG-INFO
RENAMED
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/requires.txt
RENAMED
|
File without changes
|
{rda_python_common-1.0.32 → rda_python_common-1.0.33}/src/rda_python_common.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|