Skip to content

Reconcile legacy Pg*.py modules with the pg_*.py classes (3.0.14) - #122

Merged
zaihuaji merged 1 commit into
mainfrom
hua-work-common
Sep 4, 2026
Merged

zaihuaji merged 1 commit into
mainfrom
hua-work-common

Conversation

@zaihuaji

@zaihuaji zaihuaji commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Reconciles the 9 legacy module-level Pg*.py twins with their active class-based pg_*.py implementations, which had drifted years behind. All nine are now AST-equivalent to their active counterparts, so downstream code still importing the old names gets the same logic.
  • Picks up the accumulated fixes along the way: Globus task waits on Quasar copies, dssdb.dssgrp-only user lookup (retired UCAR People DB), setuid chmod, psutil process scans replacing ps | grep, hashlib md5. Drops the retired HPSS and SLURM code paths and their PGLOG keys.
  • Fixes two defects that were present in both trees: endtime() split 'HH:MM:SS' on a literal 'T' and raised IndexError; tosystem() declared logact=0 while the body kept the if logact is None idiom, so the intended LOGWRN default was dead.
  • Version bumped to 3.0.14 in pyproject.toml, __init__.py and README.md.

Deliberate deviation

open_output / OUTPUT stays in PgOPT.py rather than moving to PgLOG alongside the active tree: ten downstream files reference PgOPT.OUTPUT, and the function needs PGOPT['extlog'], so the move would be circular. It now also assigns PgLOG.OUTPUT so the ported PgLOG.pgexit() can still close it.

Test plan

  • AST-canonical comparison of all 9 pairs reports 0 differing functions and 0 unexpected only-in-one-side functions (residuals are the addNoLeapDate/is_leapyear aliases and the documented open_output deviation)
  • No lost global declarations and no missing imports (checked mechanically per file)
  • py_compile clean on all 9 legacy modules plus the two touched active modules
  • All 18 modules (legacy + active) import successfully
  • Downstream rda_python_dsarch imports against the reconciled package
  • Behavioural spot checks: endtime('01:02:03','H') -> 01:59:59, endtime('01:02:03','N') -> 01:02:59, endtime('','H') -> 00:59:59; PgLOG.tosystem default logact is None; PgOPT.OUTPUT and PgLOG.OUTPUT both resolve

…version to 3.0.14

The module-level Pg*.py twins had drifted years behind the active class-based
pg_*.py implementations, so downstream callers still importing the old names
were silently running stale (and in places broken) logic.  All nine legacy
modules are now AST-equivalent to their active counterparts, which also picks
up the accumulated bug fixes (Globus task waits, dssgrp-only user lookup,
setuid chmod, psutil process scans, hashlib md5) and drops the retired HPSS,
SLURM and UCAR People DB code paths.

open_output/OUTPUT deliberately stays in PgOPT.py, since ten downstream files
reference PgOPT.OUTPUT and it needs PGOPT['extlog']; it now also assigns
PgLOG.OUTPUT so the ported PgLOG.pgexit() can still close it.

Also fixes two defects that were present in both trees: endtime() split
'HH:MM:SS' on a literal 'T' and raised IndexError, and tosystem() declared
logact=0 while the body kept the "if logact is None" idiom, so the intended
LOGWRN default was dead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 4, 2026 16:10
@zaihuaji
zaihuaji merged commit 36f41d4 into main Sep 4, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are confirmed runtime and security issues in the changed code paths (e.g., a bad open_output call site, hard-coded token default, and incorrect process-liveness handling on PermissionError).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR reconciles multiple legacy Pg*.py modules with their newer class-based pg_*.py implementations so that downstream code importing legacy names gets equivalent behavior, and bumps the package version to 3.0.14.

Changes:

  • Aligns legacy modules’ logic with the active class-based implementations (including multiple bug fixes and removals of retired paths like SLURM/HPSS).
  • Modernizes process scanning and background/timeout handling (moving from ps | grep to psutil and improving fork/timeout behavior).
  • Updates file operations/utilities (Globus wait behavior, in-Python MD5, sorting/search helpers) and bumps version strings across packaging/docs.
File summaries
File Description
src/rda_python_common/PgUtil.py Utility refactors and bug fixes (datetime parsing, sorting/search helpers, text-file detection).
src/rda_python_common/PgSplit.py Fixes dict/list construction pitfalls and normalizes optional logact defaults.
src/rda_python_common/PgSIG.py Replaces `ps
src/rda_python_common/PgOPT.py Keeps open_output in PgOPT, syncs PgLOG.OUTPUT, updates user UID lookup via PgDBI.
src/rda_python_common/PgLOG.py Drops retired HPSS/SLURM config, improves logging/email mechanics, adds command path expansion and output closing.
src/rda_python_common/PgLock.py Tightens lock info formatting and partition lock counter updates.
src/rda_python_common/PgFile.py Adjusts Globus copy semantics (wait for task completion), switches MD5 to hashlib, improves object-store stat handling.
src/rda_python_common/PgDBI.py Removes retired DB aliases, improves error parsing robustness, migrates user lookup to dssgrp and “missed user” handling.
src/rda_python_common/PgCMD.py Updates dscheck init/validation and enhances dynamic option retrieval (incl. optional ssh + command path expansion).
src/rda_python_common/pg_util.py Active-tree fix mirrored: endtime() uses non-digit splitting (avoids IndexError).
src/rda_python_common/pg_log.py Active-tree update mirrored: tosystem() default logact becomes None → LOGWRN.
src/rda_python_common/init.py Bumps __version__ to 3.0.14.
README.md Updates displayed current version to 3.0.14.
pyproject.toml Bumps package version to 3.0.14.
Review details
  • Files reviewed: 14/14 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 1216 to +1220
if valid_command(sm): SETPGLOG("EMLSEND", f"{sm} -t") # send email command
SETPGLOG("DBGLEVEL", '') # debug level
SETPGLOG("BAOTOKEN", 's.lh2t2kDjrqs3V8y2BU2zOocT') # OpenBao token
SETPGLOG("DBGPATH", PGLOG['DSSDBHM']+"/log") # path to debug log file
SETPGLOG("OBJCTBKT", "gdex-data") # default Bucket on Object Store
SETPGLOG("BACKUPEP", "gdex-quasar") # default Globus Endpoint on Quasar
SETPGLOG("DRDATAEP", "gdex-quasar-drdata") # DRDATA Globus Endpoint on Quasar
SETPGLOG("BAOTOKEN", 's.MdOPGayn0HcuuSPrmMqCvzJA') # OpenBao token
SETPGLOG("DBGPATH", PGLOG['DSSDBHM']+"/log") # path to debug log file
SETPGLOG("OBJCTBKT", "gdex-data") # default Bucket on Object Store
Comment on lines +567 to 571
uid = PgDBI.get_user_uid(params['LN'])
if not uid: PgLOG.pglog("Could not get user.uid for " + params['LN'], PGOPT['extlog'])
PGOPT['UID'] = uid
PgLOG.open_output(params['OF'] if 'OF' in params else None)

Comment on lines 667 to +672
def check_process(pid):

buf = PgLOG.pgsystem("ps -p {} -o pid".format(pid), PgLOG.LGWNEX, 20)
if buf:
mp = r'^\s*{}$'.format(pid)
lines = buf.split('\n')
for line in lines:
if re.match(mp, line): return 1

return 0
try:
os.kill(pid, 0)
except OSError:
return 0
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants