Пример #1
0
def iterate_over_new(recIDs, fmt):
    """
    Iterate over list of IDs

    @param list: the list of record IDs to format
    @param fmt: the output format to use
    @return: tuple (total number of records, time taken to format, time taken to insert)
    """
    tbibformat  = 0     # time taken up by external call
    tbibupload  = 0     # time taken up by external call

    tot = len(recIDs)
    for count, recID in enumerate(recIDs):
        t1 = os.times()[4]
        formatted_record, needs_2nd_pass = format_record_1st_pass(recID=recID,
                                                  of=fmt,
                                                  on_the_fly=True,
                                                  save_missing=False)
        save_preformatted_record(recID=recID,
                                 of=fmt,
                                 res=formatted_record,
                                 needs_2nd_pass=needs_2nd_pass,
                                 low_priority=True)
        t2 = os.times()[4]
        tbibformat += t2 - t1
        if count % 100 == 0:
            write_message("   ... formatted %s records out of %s" % (count, tot))
            task_update_progress('Formatted %s out of %s' % (count, tot))
            task_sleep_now_if_required(can_stop_too=True)

    if tot % 100 != 0:
        write_message("   ... formatted %s records out of %s" % (tot, tot))

    return tot, tbibformat, tbibupload
Пример #2
0
def format_record(recID, of, ln=CFG_SITE_LANG, verbose=0, search_pattern=None,
                  xml_record=None, user_info=None, on_the_fly=False,
                  save_missing=True, force_2nd_pass=False):
    """
    Returns the formatted record with id 'recID' and format 'of'

    If corresponding record does not exist for given output format,
    returns ''

    ln specifies which language is used for translations.

    verbose can be increased to display debug output.

    xml_record can be specified to ignore the recID and use the given xml
    instead.

    on_the_fly means we always generate the format, ignoring the cache.

    save_missing can be used to specify to never cache a format after it has
    been generated. By default, we have a list of cached formats and the result
    of these formats is saved in the database.

    force_2nd_pass forces the 2nd pass which is basically a second formatting.
    This is used in case a bibformat element generates new BibFormat tags
    and thus we do not detect them automatically.
    (the normal way is to use nocache="1" in a template to have it treated
     in the 2nd pass instead)

    @param recID: the id of the record to fetch
    @param of: the output format code
    @return: formatted record as String, or '' if it does not exist
    """
    out, needs_2nd_pass = bibformat_engine.format_record_1st_pass(
                                        recID=recID,
                                        of=of,
                                        ln=ln,
                                        verbose=verbose,
                                        search_pattern=search_pattern,
                                        xml_record=xml_record,
                                        user_info=user_info,
                                        on_the_fly=on_the_fly,
                                        save_missing=save_missing)
    if needs_2nd_pass or force_2nd_pass:
        out = bibformat_engine.format_record_2nd_pass(
                                    recID=recID,
                                    of=of,
                                    template=out,
                                    ln=ln,
                                    verbose=verbose,
                                    search_pattern=search_pattern,
                                    xml_record=xml_record,
                                    user_info=user_info)

    return out
Пример #3
0
def _update_format(recid, fmt):
    """Usual format update procedure, gets the formatted record and saves it.

    :param int recid: record id to process
    :param str fmt: format to update/create, i.e. 'HB'
    """
    record, needs_2nd_pass = format_record_1st_pass(recID=recid,
                                                    of=fmt,
                                                    on_the_fly=True,
                                                    save_missing=False)
    save_preformatted_record(recID=recid,
                             of=fmt,
                             res=record,
                             needs_2nd_pass=needs_2nd_pass,
                             low_priority=True)
Пример #4
0
def _update_format(recid, fmt):
    """Usual format update procedure, gets the formatted record and saves it.

    :param int recid: record id to process
    :param str fmt: format to update/create, i.e. 'HB'
    """
    record, needs_2nd_pass = format_record_1st_pass(recID=recid,
                                                    of=fmt,
                                                    on_the_fly=True,
                                                    save_missing=False)
    save_preformatted_record(recID=recid,
                             of=fmt,
                             res=record,
                             needs_2nd_pass=needs_2nd_pass,
                             low_priority=True)
Пример #5
0
def format_record(recID,
                  of,
                  ln=CFG_SITE_LANG,
                  verbose=0,
                  search_pattern=None,
                  xml_record=None,
                  user_info=None,
                  on_the_fly=False,
                  save_missing=True,
                  force_2nd_pass=False):
    """
    Returns the formatted record with id 'recID' and format 'of'

    If corresponding record does not exist for given output format,
    returns ''

    ln specifies which language is used for translations.

    verbose can be increased to display debug output.

    xml_record can be specified to ignore the recID and use the given xml
    instead.

    on_the_fly means we always generate the format, ignoring the cache.

    save_missing can be used to specify to never cache a format after it has
    been generated. By default, we have a list of cached formats and the result
    of these formats is saved in the database.

    force_2nd_pass forces the 2nd pass which is basically a second formatting.
    This is used in case a bibformat element generates new BibFormat tags
    and thus we do not detect them automatically.
    (the normal way is to use nocache="1" in a template to have it treated
     in the 2nd pass instead)

    @param recID: the id of the record to fetch
    @param of: the output format code
    @return: formatted record as String, or '' if it does not exist
    """
    out, needs_2nd_pass = bibformat_engine.format_record_1st_pass(
        recID=recID,
        of=of,
        ln=ln,
        verbose=verbose,
        search_pattern=search_pattern,
        xml_record=xml_record,
        user_info=user_info,
        on_the_fly=on_the_fly,
        save_missing=save_missing)
    if needs_2nd_pass or force_2nd_pass:
        out = bibformat_engine.format_record_2nd_pass(
            recID=recID,
            of=of,
            template=out,
            ln=ln,
            verbose=verbose,
            search_pattern=search_pattern,
            xml_record=xml_record,
            user_info=user_info)

    return out