def check_rev(recid, verbose=True, fix=False): revisions = get_record_revisions(recid) for recid, job_date in revisions: rev = '%s.%s' % (recid, job_date) try: get_marcxml_of_revision_id(rev) if verbose: print('%s: ok' % rev) except zlib.error: print('%s: invalid' % rev) if fix: fix_rev(recid, job_date, verbose)
def cli_revert_to_revision(revid): """Submit specified record revision REVID upload, to replace current version. """ if not revision_format_valid_p(revid): print('ERROR: revision %s is invalid; ' \ 'must be NNN.YYYYMMDDhhmmss.' % revid) sys.exit(1) xml_record = get_marcxml_of_revision_id(revid) if xml_record == '': print('ERROR: Revision %s does not exist. ' % revid) sys.exit(1) recid = split_revid(revid)[0] if record_locked_by_other_user(recid, -1): print('The record is currently being edited. ' \ 'Please try again in a few minutes.') sys.exit(1) if record_locked_by_queue(recid): print('The record is locked because of unfinished upload tasks. ' \ 'Please try again in a few minutes.') sys.exit(1) save_xml_record(recid, 0, xml_record) print('Your modifications have now been submitted. They will be ' \ 'processed as soon as the task queue is empty.')
def cli_diff_revisions(revid1, revid2): """Return diffs of MARCXML for record revisions REVID1, REVID2.""" for revid in [revid1, revid2]: if not revision_format_valid_p(revid): print('ERROR: revision %s is invalid; ' \ 'must be NNN.YYYYMMDDhhmmss.' % revid) sys.exit(1) xml1 = get_marcxml_of_revision_id(revid1) if not xml1: print('ERROR: Revision %s not found. ' % revid1) sys.exit(1) xml2 = get_marcxml_of_revision_id(revid2) if not xml2: print('ERROR: Revision %s not found. ' % revid2) sys.exit(1) print(get_xml_comparison(revid1, revid2, xml1, xml2))
def cli_get_revision(revid): """Return MARCXML for record revision REVID (=RECID.REVDATE) of a record.""" if not revision_format_valid_p(revid): print('ERROR: revision %s is invalid; ' \ 'must be NNN.YYYYMMDDhhmmss.' % revid) sys.exit(1) out = get_marcxml_of_revision_id(revid) if out: print(out) else: print('ERROR: Revision %s not found.' % revid)
def _get_record_slave(recid, result, mode=None, uid=None): """Check if record exists and return it in dictionary format. If any kind of error occurs returns None. If mode=='revision' then recid parameter is considered as revid.""" record = None if recid == 'none': mode = 'none' if mode == 'recid': record_status = record_exists(recid) #check for errors if record_status == 0: result['resultCode'], result[ 'resultText'] = 1, 'Non-existent record: %s' % recid elif record_status == -1: result['resultCode'], result[ 'resultText'] = 1, 'Deleted record: %s' % recid elif record_locked_by_queue(recid): result['resultCode'], result[ 'resultText'] = 1, 'Record %s locked by queue' % recid else: record = create_record(print_record(recid, 'xm'))[0] elif mode == 'tmpfile': file_path = '%s_%s.xml' % (_get_file_path( recid, uid), cfg['CFG_BIBEDIT_TO_MERGE_SUFFIX']) if not os.path.isfile(file_path): #check if file doesn't exist result['resultCode'], result[ 'resultText'] = 1, 'Temporary file doesnt exist' else: #open file tmpfile = open(file_path, 'r') record = create_record(tmpfile.read())[0] tmpfile.close() elif mode == 'revision': if revision_format_valid_p(recid): marcxml = get_marcxml_of_revision_id(recid) if marcxml: record = create_record(marcxml)[0] else: result['resultCode'], result[ 'resultText'] = 1, 'The specified revision does not exist' else: result['resultCode'], result[ 'resultText'] = 1, 'Invalid revision id' elif mode == 'none': return {} else: result['resultCode'], result[ 'resultText'] = 1, 'Invalid record mode for record2' record_order_subfields(record) return record
def _get_record_slave(recid, result, mode=None, uid=None): """Check if record exists and return it in dictionary format. If any kind of error occurs returns None. If mode=='revision' then recid parameter is considered as revid.""" record = None if recid == 'none': mode = 'none' if mode == 'recid': record_status = record_exists(recid) #check for errors if record_status == 0: result['resultCode'], result['resultText'] = 1, 'Non-existent record: %s' % recid elif record_status == -1: result['resultCode'], result['resultText'] = 1, 'Deleted record: %s' % recid elif record_locked_by_queue(recid): result['resultCode'], result['resultText'] = 1, 'Record %s locked by queue' % recid else: record = create_record( print_record(recid, 'xm') )[0] record_order_subfields(record) elif mode == 'tmpfile': file_path = '%s_%s.xml' % (_get_file_path(recid, uid), CFG_BIBEDIT_TO_MERGE_SUFFIX) if not os.path.isfile(file_path): #check if file doesn't exist result['resultCode'], result['resultText'] = 1, 'Temporary file doesnt exist' else: #open file tmpfile = open(file_path, 'r') record = create_record( tmpfile.read() )[0] tmpfile.close() elif mode == 'revision': if revision_format_valid_p(recid): marcxml = get_marcxml_of_revision_id(recid) if marcxml: record = create_record(marcxml)[0] else: result['resultCode'], result['resultText'] = 1, 'The specified revision does not exist' else: result['resultCode'], result['resultText'] = 1, 'Invalid revision id' elif mode == 'none': return {} else: result['resultCode'], result['resultText'] = 1, 'Invalid record mode for record2' return record