def revise(bibrecdocs, curdir, sysno, file_path, bibdoc_name, doctype,
           iconsize, create_icon_doctypes,
           keep_previous_version_doctypes, createRelatedFormats_p):
    """
    Revises the given bibdoc with a new file
    """
    try:

        # Retrieve the current description and comment, or they
        # will be lost when revising
        latest_files = bibrecdocs.list_bibdocs(doctype)[0].list_latest_files()
        prev_desc, prev_comment = get_description_and_comment(latest_files)

        if doctype in keep_previous_version_doctypes:
            # Standard procedure, keep previous version
            bibdoc = bibrecdocs.add_new_version(file_path,
                                                bibdoc_name,
                                                prev_desc,
                                                prev_comment)
            _do_log(curdir, '  Revised ' + bibdoc.get_docname() + \
                    ' with : ' + file_path)

        else:
            # Soft-delete previous versions, and add new file
            # (we need to get the doctype before deleting)
            if bibrecdocs.has_docname_p(bibdoc_name):
                # Delete only if bibdoc originally
                # existed
                bibrecdocs.delete_bibdoc(bibdoc_name)
                _do_log(curdir, '  Deleted ' + bibdoc_name)
            try:
                bibdoc = bibrecdocs.add_new_file(file_path,
                                                 doctype,
                                                 bibdoc_name,
                                                 never_fail=True,
                                                 description=prev_desc,
                                                 comment=prev_comment)
                _do_log(curdir, '  Added ' + bibdoc.get_docname() + ': ' + \
                        file_path)

            except InvenioBibDocFileError, e:
                _do_log(curdir, str(e))
                register_exception(prefix='Move_Uploaded_Files_to_Storage ' \
                                   'tried to revise a file %s ' \
                                   'named %s in record %i. %s' % \
                                   (file_path, bibdoc_name, sysno, curdir),
                                   alert_admin=True)

        # Add icon
        iconpath = ''
        if doctype in create_icon_doctypes or \
               '*' in create_icon_doctypes:
            iconpath = _create_icon(file_path, iconsize)
            if iconpath is not None:
                bibdoc.add_icon(iconpath)
                _do_log(curdir, 'Added icon to ' + \
                        bibdoc.get_docname() + ': ' + iconpath)

        # Automatically create additional formats when
        # possible.
        additional_formats = []
        if createRelatedFormats_p:
            additional_formats = createRelatedFormats(file_path,
                                                      overwrite=False)
        for additional_format in additional_formats:
            bibdoc.add_new_format(additional_format,
                                  bibdoc_name,
                                  prev_desc,
                                  prev_comment)
            # Log
            _do_log(curdir, '  Addeded format ' + additional_format + \
                    ' to ' + bibdoc.get_docname() + ': ' + iconpath)
    i = 0
    for docname in docnames:
        i += 1
        task_sleep_now_if_required()
        msg = "Processing %s (%i/%i)" % (docname, i, len(docnames))
        write_message(msg)
        task_update_progress(msg)
        try:
            bibdoc = bibarchive.get_bibdoc(docname)
        except Exception, e:
            write_message("Could not process docname %s: %s" % (docname, e))
            continue

        (prev_desc, prev_comment) = \
                    get_description_and_comment(bibarchive.get_bibdoc(docname).list_latest_files())

        # List all files that are not icons or subformats
        current_files = [bibdocfile.get_path() for bibdocfile in bibdoc.list_latest_files() if \
                         not bibdocfile.get_subformat() and not bibdocfile.is_icon()]

        ## current_files = []
        ## if not force:
        ##     current_files = [bibdocfile.get_path() for bibdocfile bibdoc.list_latest_files()]
        for current_filepath in current_files:
            # Convert
            new_files = createRelatedFormats(fullpath=current_filepath,
                                             overwrite=force,
                                             consider_version=True)
            # Append
            for new_file in new_files:
def revise(bibrecdocs, curdir, sysno, file_path, bibdoc_name, doctype,
           iconsize, create_icon_doctypes, keep_previous_version_doctypes,
           createRelatedFormats_p):
    """
    Revises the given bibdoc with a new file
    """
    try:

        # Retrieve the current description and comment, or they
        # will be lost when revising
        latest_files = bibrecdocs.list_bibdocs(doctype)[0].list_latest_files()
        prev_desc, prev_comment = get_description_and_comment(latest_files)

        if doctype in keep_previous_version_doctypes:
            # Standard procedure, keep previous version
            bibdoc = bibrecdocs.add_new_version(file_path, bibdoc_name,
                                                prev_desc, prev_comment)
            _do_log(curdir, '  Revised ' + bibdoc.get_docname() + \
                    ' with : ' + file_path)

        else:
            # Soft-delete previous versions, and add new file
            # (we need to get the doctype before deleting)
            if bibrecdocs.has_docname_p(bibdoc_name):
                # Delete only if bibdoc originally
                # existed
                bibrecdocs.delete_bibdoc(bibdoc_name)
                _do_log(curdir, '  Deleted ' + bibdoc_name)
            try:
                bibdoc = bibrecdocs.add_new_file(file_path,
                                                 doctype,
                                                 bibdoc_name,
                                                 never_fail=True,
                                                 description=prev_desc,
                                                 comment=prev_comment)
                _do_log(curdir, '  Added ' + bibdoc.get_docname() + ': ' + \
                        file_path)

            except InvenioBibDocFileError, e:
                _do_log(curdir, str(e))
                register_exception(prefix='Move_Uploaded_Files_to_Storage ' \
                                   'tried to revise a file %s ' \
                                   'named %s in record %i. %s' % \
                                   (file_path, bibdoc_name, sysno, curdir),
                                   alert_admin=True)

        # Add icon
        iconpath = ''
        if doctype in create_icon_doctypes or \
               '*' in create_icon_doctypes:
            iconpath = _create_icon(file_path, iconsize)
            if iconpath is not None:
                bibdoc.add_icon(iconpath)
                _do_log(curdir, 'Added icon to ' + \
                        bibdoc.get_docname() + ': ' + iconpath)

        # Automatically create additional formats when
        # possible.
        additional_formats = []
        if createRelatedFormats_p:
            additional_formats = createRelatedFormats(file_path,
                                                      overwrite=False)
        for additional_format in additional_formats:
            bibdoc.add_new_format(additional_format, bibdoc_name, prev_desc,
                                  prev_comment)
            # Log
            _do_log(curdir, '  Addeded format ' + additional_format + \
                    ' to ' + bibdoc.get_docname() + ': ' + iconpath)
    i = 0
    for docname in docnames:
        i += 1
        task_sleep_now_if_required()
        msg = "Processing %s (%i/%i)" % (docname, i, len(docnames))
        write_message(msg)
        task_update_progress(msg)
        try:
            bibdoc = bibarchive.get_bibdoc(docname)
        except Exception, e:
            write_message("Could not process docname %s: %s" % (docname, e))
            continue

        (prev_desc, prev_comment) = \
                    get_description_and_comment(bibarchive.get_bibdoc(docname).list_latest_files())

        # List all files that are not icons or subformats
        current_files = [bibdocfile.get_path() for bibdocfile in bibdoc.list_latest_files() if \
                         not bibdocfile.get_subformat() and not bibdocfile.is_icon()]

        ## current_files = []
        ## if not force:
        ##     current_files = [bibdocfile.get_path() for bibdocfile bibdoc.list_latest_files()]
        for current_filepath in current_files:
            # Convert
            new_files = createRelatedFormats(fullpath=current_filepath,
                                             overwrite=force,
                                             consider_version=True)
            # Append
            for new_file in new_files: