Пример #1
0
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.')
Пример #2
0
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.')
Пример #3
0
def _get_record(recid, uid, result, fresh_record=False):
    """Retrieve record structure.
    """
    record = None
    mtime = None
    cache_dirty = None
    record_status = record_exists(recid)
    existing_cache = cache_exists(recid, uid)
    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 not existing_cache and record_locked_by_other_user(recid, uid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by user' % recid
    elif existing_cache and cache_expired(recid, uid) and \
        record_locked_by_other_user(recid, uid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by user' % recid
    elif record_locked_by_queue(recid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by queue' % recid
    else:
        if fresh_record:
            delete_cache(recid, uid)
            existing_cache = False
        if not existing_cache:
            record_revision, record = create_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            cache_dirty = False
        else:
            tmpRes = get_cache_contents(recid, uid)
            cache_dirty, record_revision, record = tmpRes[0], tmpRes[
                1], tmpRes[2]
            touch_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            if not latest_record_revision(recid, record_revision):
                result['cacheOutdated'] = True
        result['resultCode'], result['resultText'], result[
            'cacheDirty'], result[
                'cacheMTime'] = 0, 'Record OK', cache_dirty, mtime
    record_order_subfields(record)
    return record
Пример #4
0
def _get_record(recid, uid, result, fresh_record=False):
    """Retrieve record structure.
    """
    record = None
    mtime = None
    cache_dirty = None
    record_status = record_exists(recid)
    existing_cache = cache_exists(recid, uid)
    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 not existing_cache and record_locked_by_other_user(recid, uid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by user' % recid
    elif existing_cache and cache_expired(recid, uid) and \
        record_locked_by_other_user(recid, uid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by user' % recid
    elif record_locked_by_queue(recid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by queue' % recid
    else:
        if fresh_record:
            delete_cache(recid, uid)
            existing_cache = False
        if not existing_cache:
            record_revision, record = create_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            cache_dirty = False
        else:
            tmpRes = get_cache_contents(recid, uid)
            cache_dirty, record_revision, record = tmpRes[0], tmpRes[1], tmpRes[2]
            touch_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            if not latest_record_revision(recid, record_revision):
                result['cacheOutdated'] = True
        result['resultCode'], result['resultText'], result['cacheDirty'], result['cacheMTime'] = 0, 'Record OK', cache_dirty, mtime
    record_order_subfields(record)
    return record