Skip to content

Commit f56cfab

Browse files
authored
Merge pull request #12 from NCAR/hua-work-common
Hua work common
2 parents cde828a + e4ab773 commit f56cfab

File tree

4 files changed

+52
-354
lines changed

4 files changed

+52
-354
lines changed

pyproject.toml

Lines changed: 1 addition & 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.7"
7+
version = "1.0.8"
88

99
authors = [
1010
{ name="Zaihua Ji", email="zji@ucar.edu" },

src/rda_python_common/PgFile.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
'rda-quasar-drdata' : "NCAR RDA Quasar DRDATA"
119119
}
120120

121+
BFILES = {} # cache backup file names and dates for each bid
122+
121123
#
122124
# reset the up limit for a specified error type
123125
#
@@ -3012,3 +3014,52 @@ def check_storage_dflags(dflags, dscheck = None, logact = 0):
30123014
if cidx: PgDBI.pgexec("UPDATE dscheck SET dflags = '' WHERE cindex = {}".format(cidx), logact)
30133015

30143016
return msgary
3017+
3018+
#
3019+
# check a RDA file is backed up or not for given file record;
3020+
# clear the cached bfile records if frec is None.
3021+
# return 0 if not yet, 1 if backed up, or -1 if backed up but modified
3022+
#
3023+
def file_backup_status(frec, chgdays = 1, logact = 0):
3024+
3025+
if frec is None:
3026+
BFILES.clear()
3027+
return 0
3028+
3029+
bid = frec['bid']
3030+
if not bid: return 0
3031+
3032+
fields = 'bfile, dsid, date_modified'
3033+
if chgdays > 0: fields += ', note'
3034+
if bid not in BFILES: BFILES[bid] = PgDBI.pgget('bfile', fields, 'bid = {}'.format(bid), logact)
3035+
brec = BFILES[bid]
3036+
if not brec: return 0
3037+
3038+
if 'sfile' in frec:
3039+
fname = frec['sfile']
3040+
ftype = 'Saved'
3041+
else:
3042+
fname = frec['wfile']
3043+
ftype = 'Web'
3044+
ret = 1
3045+
fdate = frec['date_modified']
3046+
bdate = brec['date_modified']
3047+
if chgdays > 0 and PgUtil.diffdate(fdate, bdate) >= chgdays:
3048+
ret = -1
3049+
if brec['note']:
3050+
mp = r'{}<:>{}<:>(\d+)<:>(\w+)<:>'.format(fname, frec['type'])
3051+
ms = re.search(mp, brec['note'])
3052+
if ms:
3053+
fsize = int(ms.group(1))
3054+
cksum = ms.group(2)
3055+
if cksum and cksum == frec['checksum'] or not cksum and fsize == frec['data_size']:
3056+
ret = 1
3057+
3058+
if logact:
3059+
if ret == 1:
3060+
msg = "{}-{}: {} file backed up to /{}/{} by {}".format(frec['dsid'], fname, ftype, brec['dsid'], brec['bfile'], bdate)
3061+
else:
3062+
msg = "{}-{}: {} file changed on {}".format(frec['dsid'], fname, ftype, fdate)
3063+
PgLOG.pglog(msg, logact)
3064+
3065+
return ret

src/rda_python_common/PgGLBS.py

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)