|
118 | 118 | 'rda-quasar-drdata' : "NCAR RDA Quasar DRDATA" |
119 | 119 | } |
120 | 120 |
|
| 121 | +BFILES = {} # cache backup file names and dates for each bid |
| 122 | + |
121 | 123 | # |
122 | 124 | # reset the up limit for a specified error type |
123 | 125 | # |
@@ -3012,3 +3014,52 @@ def check_storage_dflags(dflags, dscheck = None, logact = 0): |
3012 | 3014 | if cidx: PgDBI.pgexec("UPDATE dscheck SET dflags = '' WHERE cindex = {}".format(cidx), logact) |
3013 | 3015 |
|
3014 | 3016 | 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 |
0 commit comments