Skip to content

Commit e6e0e8c

Browse files
authored
Merge pull request #26 from NCAR/main
get the changes from main
2 parents e0f5bb5 + 4a6b6c1 commit e6e0e8c

File tree

8 files changed

+168
-114
lines changed

8 files changed

+168
-114
lines changed

.github/workflows/python-app.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Python application
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: [ "main", "pkg_update" ]
99
pull_request:
1010
branches: [ "main" ]
1111

@@ -34,3 +34,6 @@ jobs:
3434
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --indent-size=3
3535
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3636
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
- name: Run Tests
38+
run: |
39+
pytest

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "rda_python_common"
7-
version = "1.0.17"
7+
version = "1.0.21"
88
authors = [
99
{ name="Zaihua Ji", email="zji@ucar.edu" },
1010
]
@@ -17,6 +17,15 @@ classifiers = [
1717
"Operating System :: OS Independent",
1818
"Development Status :: 5 - Production/Stable",
1919
]
20+
dependencies = [
21+
"psycopg2-binary",
22+
"rda-python-globus",
23+
]
2024

2125
[project.urls]
2226
"Homepage" = "https://github.com/NCAR/rda-python-common"
27+
28+
[tool.pytest.ini_options]
29+
pythonpath = [
30+
"src"
31+
]

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
iniconfig==2.1.0
2+
packaging==24.2
3+
pluggy==1.5.0
4+
psycopg2-binary==2.9.10
5+
pytest==8.3.5
6+
rda-python-globus

src/rda_python_common/PgFile.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
BHOST = PgLOG.PGLOG['BACKUPNM']
6868
DHOST = PgLOG.PGLOG['DRDATANM']
6969
OBJCTCMD = "isd_s3_cli"
70-
BACKCMD = "dsglobus"
70+
BACKCMD = "dsglobus"
7171

7272
HLIMIT = 0 # HTAR file count limit
7373
BLIMIT = 2 # minimum back tar file size in DB
@@ -338,17 +338,28 @@ def local_copy_object(tofile, fromfile, bucket = None, meta = None, logact = 0):
338338
def quasar_multiple_trasnfer(tofiles, fromfiles, topoint, frompoint, logact = 0):
339339

340340
ret = PgLOG.FAILURE
341-
qstr = '{"action":"transfer","label":"%s","verify_checksum":true,' % ENDPOINTS[topoint]
342-
# qstr = '{"action":"transfer","label":"%s",' % ENDPOINTS[topoint]
343-
qstr += '"source_endpoint":"%s","destination_endpoint":"%s","files":[\n' % (frompoint, topoint)
341+
344342
fcnt = len(fromfiles)
345-
bstr = ''
343+
transfer_files = {"files": []}
346344
for i in range(fcnt):
347-
qstr += '%s{"source_file":"%s","destination_file":"%s"}' % (bstr, fromfiles[i], tofiles[i])
348-
if i == 0: bstr = ',\n'
349-
qstr += ']}'
350-
351-
task = submit_globus_task(BACKCMD, topoint, logact, qstr)
345+
transfer_files["files"].append({
346+
"source_file": fromfiles[i],
347+
"destination_file": tofiles[i]
348+
})
349+
qstr = json.dumps(transfer_files)
350+
351+
action = 'transfer'
352+
source_endpoint = frompoint
353+
destination_endpoint = topoint
354+
label = f"{ENDPOINTS[frompoint]} to {ENDPOINTS[topoint]} {action}"
355+
verify_checksum = True
356+
357+
cmd = f'{BACKCMD} {action} -se {source_endpoint} -de {destination_endpoint} --label "{label}"'
358+
if verify_checksum:
359+
cmd += ' -vc'
360+
cmd += ' --batch -'
361+
362+
task = submit_globus_task(cmd, topoint, logact, qstr)
352363
if task['stat'] == 'S':
353364
ret = PgLOG.SUCCESS
354365
elif task['stat'] == 'A':
@@ -379,7 +390,9 @@ def endpoint_copy_endpoint(tofile, fromfile, topoint, frompoint, logact = 0):
379390
if tinfo and tinfo['data_size'] > 0:
380391
return PgLOG.pglog("{}-{}: file exists already".format(topoint, tofile), logact)
381392

382-
cmd = "{} -t -vc -se {} -de {} -sf {} -df {}".format(BACKCMD, frompoint, topoint, fromfile, tofile)
393+
action = 'transfer'
394+
cmd = f'{BACKCMD} {action} -se {frompoint} -de {topoint} -sf {fromfile} -df {tofile} -vc'
395+
383396
task = submit_globus_task(cmd, topoint, logact)
384397
if task['stat'] == 'S':
385398
ret = PgLOG.SUCCESS
@@ -435,7 +448,8 @@ def check_globus_status(taskid, endpoint = None, logact = 0):
435448
if not taskid: return ret
436449
if not endpoint: endpoint = PgLOG.PGLOG['BACKUPEP']
437450
mp = r'Status:\s+({})'.format('|'.join(QSTATS.values()))
438-
cmd = "{} -gt --task-id {}".format(BACKCMD, taskid)
451+
452+
cmd = f"{BACKCMD} get-task {taskid}"
439453
astats = ['OK', 'Queued']
440454

441455
for loop in range(2):
@@ -452,7 +466,7 @@ def check_globus_status(taskid, endpoint = None, logact = 0):
452466
if logact&PgLOG.NOWAIT:
453467
errmsg = "{}: Cancel Task due to {}:\n{}".format(taskid, detail, buf)
454468
errlog(errmsg, 'B', 1, logact)
455-
ccmd = "{} -ct --task-id {}".format(BACKCMD, taskid)
469+
ccmd = f"{BACKCMD} cancel-task {taskid}"
456470
PgLOG.pgsystem(ccmd, logact, 7)
457471
else:
458472
time.sleep(PgSIG.PGSIG['ETIME'])
@@ -759,7 +773,7 @@ def delete_backup_file(file, endpoint = None, logact = 0):
759773
info = check_backup_file(file, endpoint, 0, logact)
760774
if not info: return PgLOG.FAILURE
761775

762-
cmd = "{} -d -ep {} -tf {}".format(BACKCMD, endpoint, file)
776+
cmd = f"{BACKCMD} delete -ep {endpoint} -tf {file}"
763777
task = submit_globus_task(cmd, endpoint, logact)
764778
if task['stat'] == 'S':
765779
return PgLOG.SUCCESS
@@ -1028,7 +1042,7 @@ def move_backup_file(tofile, fromfile, endpoint = None, logact = 0):
10281042
elif tinfo != None:
10291043
return ret
10301044

1031-
cmd = "{} --rename -ep {} --oldpath {} --newpath {}".format(BACKCMD, endpoint, fromfile, tofile)
1045+
cmd = f"{BACKCMD} rename -ep {endpoint} --old-path {fromfile} --new-path {tofile}"
10321046
loop = 0
10331047
while loop < 2:
10341048
buf = PgLOG.pgsystem(cmd, logact, CMDRET)
@@ -1158,7 +1172,7 @@ def make_one_backup_directory(dir, odir, endpoint = None, logact = 0):
11581172
if not odir: odir = dir
11591173
if not make_one_backup_directory(op.dirname(dir), odir, endpoint, logact): return PgLOG.FAILURE
11601174

1161-
cmd = "{} --mkdir -ep {} -p {}".format(BACKCMD, endpoint, dir)
1175+
cmd = f"{BACKCMD} mkdir -ep {endpoint} -p {dir}"
11621176
for loop in range(2):
11631177
buf = PgLOG.pgsystem(cmd, logact, CMDRET)
11641178
syserr = PgLOG.PGLOG['SYSERR']
@@ -1843,7 +1857,7 @@ def check_backup_file(file, endpoint = None, opt = 0, logact = 0):
18431857
if not endpoint: endpoint = PgLOG.PGLOG['BACKUPEP']
18441858
bdir = op.dirname(file)
18451859
bfile = op.basename(file)
1846-
cmd = "{} -ls -ep {} -p {} --filter {}".format(BACKCMD, endpoint, bdir, bfile)
1860+
cmd = f"{BACKCMD} ls -ep {endpoint} -p {bdir} --filter {bfile}"
18471861
ccnt = loop = 0
18481862
while loop < 2:
18491863
buf = PgLOG.pgsystem(cmd, logact, CMDRET)
@@ -2208,7 +2222,8 @@ def backup_glob(dir, endpoint = None, opt = 0, logact = 0):
22082222

22092223
if not dir: return None
22102224
if not endpoint: endpoint = PgLOG.PGLOG['BACKUPEP']
2211-
cmd = "{} -ls -ep {} -p {}".format(BACKCMD, endpoint, dir)
2225+
2226+
cmd = f"{BACKCMD} ls -ep {endpoint} -p {dir}"
22122227
flist = {}
22132228
for loop in range(2):
22142229
buf = PgLOG.pgsystem(cmd, logact, CMDRET)

0 commit comments

Comments
 (0)