Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
python -c "import rda_python_common; print(rda_python_common.__version__)"
```

You should see the installed version (currently `2.1.10`). If the import
You should see the installed version (currently `2.1.11`). If the import
fails, double-check that the active Python environment is the one where you
ran `pip install`.

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rda_python_common"
version = "2.1.10"
version = "2.1.11"
authors = [
{ name="Zaihua Ji", email="zji@ucar.edu" },
]
Expand All @@ -18,8 +18,8 @@ classifiers = [
"Development Status :: 5 - Production/Stable",
]
dependencies = [
"hvac",
"psycopg2==2.9.10",
"psycopg2-binary",
"psutil",
"rda-python-globus",
"unidecode",
"hvac"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
iniconfig==2.1.0
packaging==24.2
pluggy==1.5.0
psycopg2==2.9.10
psycopg2-binary==2.9.10
psutil
pytest==8.3.5
rda-python-globus
unidecode
Expand Down
2 changes: 1 addition & 1 deletion src/rda_python_common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from . import PgLOG, PgUtil, PgDBI, PgFile, PgLock, PgCMD, PgSIG, PgOPT, PgSplit

__version__ = "2.1.10"
__version__ = "2.1.11"

__all__ = [
"PgLOG",
Expand Down
27 changes: 18 additions & 9 deletions src/rda_python_common/pg_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import glob
import json
import hashlib
from .pg_util import PgUtil
from .pg_sig import PgSIG

Expand Down Expand Up @@ -2874,24 +2875,32 @@ def get_md5sum(self, file, count = 0, logact = 0):
(with None for missing files) for multiple files, or None
on failure.
"""
cmd = 'md5sum '
if count > 0:
checksum = [None]*count
for i in range(count):
if op.isfile(file[i]):
chksm = self.pgsystem(cmd + file[i], logact, 20)
if chksm:
ms = re.search(r'(\w{32})', chksm)
if ms: checksum[i] = ms.group(1)
checksum[i] = self._file_md5(file[i], logact)
else:
checksum = None
if op.isfile(file):
chksm = self.pgsystem(cmd + file, logact, 20)
if chksm:
ms = re.search(r'(\w{32})', chksm)
if ms: checksum = ms.group(1)
checksum = self._file_md5(file, logact)
return checksum

def _file_md5(self, path, logact=0):
"""Compute MD5 hex digest of *path*, reading in 1 MiB chunks.

Returns the hex digest string, or None on read error.
"""
try:
h = hashlib.md5()
with open(path, 'rb') as fh:
for chunk in iter(lambda: fh.read(1048576), b''):
h.update(chunk)
return h.hexdigest()
except OSError as e:
self.pglog("Error md5sum {}: {}".format(path, str(e)), logact)
return None

# Evaluate md5 checksums and compare them for two given files
# file1, file2: file names
# Return: 0 if same and 1 if not
Expand Down
18 changes: 8 additions & 10 deletions src/rda_python_common/pg_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import shlex
import smtplib
from email.message import EmailMessage
import subprocess
from subprocess import Popen, PIPE
from os import path as op
import time
Expand Down Expand Up @@ -769,7 +770,7 @@ def show_usage(self, progname, opts=None):
nilcnt = 0
if begin: sys.stdout.write(line)
else:
os.system("more " + usgname)
subprocess.run(['more', usgname])
self.pgexit(0)
Comment on lines 772 to 774

def err2std(self, line):
Expand Down Expand Up @@ -1600,15 +1601,12 @@ def set_specialist_home(self, specialist):
os.environ['MAIL'] = re.sub(self.PGLOG['CURUID'], specialist, os.environ['MAIL'])
home = "{}/{}".format(self.PGLOG['USRHOME'], specialist)
shell = "tcsh"
buf = self.pgsystem("grep ^{}: /etc/passwd".format(specialist), self.LOGWRN, 20)
if buf:
lines = buf.split('\n')
for line in lines:
ms = re.search(r':(/.+):(/.+)', line)
if ms:
home = ms.group(1)
shell = op.basename(ms.group(2))
break
try:
pwent = pwd.getpwnam(specialist)
home = pwent.pw_dir
shell = op.basename(pwent.pw_shell)
except KeyError:
pass
if home != os.environ['HOME'] and op.exists(home):
os.environ['HOME'] = home
return shell
Expand Down
Loading
Loading