def docsubmit(self, req, form):
        """ Function called after submitting the document upload form.
            Performs the appropiate action depending on the input parameters
        """
        argd = wash_urlargd(form, {'docfolder': (str, ""),
                                   'matching': (str, ""),
                                   'mode': (str, ""),
                                   'submit_date': (str, ""),
                                   'submit_time': (str, ""),
                                   'priority': (str, "")})
        _ = gettext_set_language(argd['ln'])

        not_authorized = user_authorization(req, argd['ln'])
        if not_authorized:
            return not_authorized
        #Check if input fields are correct, if not, redirect to upload form
        correct_date = check_date(argd['submit_date'])
        correct_time = check_time(argd['submit_time'])
        if correct_time != 0:
            redirect_to_url(req,
            "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_date']))
        if correct_date != 0:
            redirect_to_url(req,
            "%s/batchuploader/documents?error=%s&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
            % (CFG_SITE_SECURE_URL, correct_date, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_time']))

        date = argd['submit_date'] not in ['yyyy-mm-dd', ''] \
                                and argd['submit_date'] or ''
        time = argd['submit_time'] not in ['hh:mm:ss', ''] \
                                and argd['submit_time'] or ''

        if date != '' and time == '':
            redirect_to_url(req, "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
                            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_date']))
        elif date == '' and time != '':
            redirect_to_url(req, "%s/batchuploader/documents?error=4&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
                            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_time']))

        errors, info = document_upload(req, argd['docfolder'], argd['matching'],
                                       argd['mode'], date, time, argd['ln'], argd['priority'])

        body = batchuploader_templates.tmpl_display_menu(argd['ln'])
        uid = getUid(req)
        navtrail = '''<a class="navtrail" href="%s/batchuploader/documents">%s</a>''' % \
                    (CFG_SITE_SECURE_URL, _("Document batch upload"))

        body += batchuploader_templates.tmpl_display_web_docupload_result(argd['ln'], errors, info)
        title = _("Document batch upload result")

        return page(title = title,
                    body = body,
                    metaheaderadd = batchuploader_templates.tmpl_styles(),
                    uid = uid,
                    navtrail = navtrail,
                    lastupdated = __lastupdated__,
                    req = req,
                    language = argd['ln'],
                    navmenuid = "batchuploader")
    def docsubmit(self, req, form):
        """ Function called after submitting the document upload form.
            Performs the appropiate action depending on the input parameters
        """
        argd = wash_urlargd(form, {'docfolder': (str, ""),
                                   'matching': (str, ""),
                                   'mode': (str, ""),
                                   'submit_date': (str, ""),
                                   'submit_time': (str, ""),
                                   'priority': (str, "")})
        _ = gettext_set_language(argd['ln'])

        not_authorized = user_authorization(req, argd['ln'])
        if not_authorized:
            return not_authorized
        #Check if input fields are correct, if not, redirect to upload form
        correct_date = check_date(argd['submit_date'])
        correct_time = check_time(argd['submit_time'])
        if correct_time != 0:
            redirect_to_url(req,
            "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_date']))
        if correct_date != 0:
            redirect_to_url(req,
            "%s/batchuploader/documents?error=%s&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
            % (CFG_SITE_SECURE_URL, correct_date, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_time']))

        date = argd['submit_date'] not in ['yyyy-mm-dd', ''] \
                                and argd['submit_date'] or ''
        time = argd['submit_time'] not in ['hh:mm:ss', ''] \
                                and argd['submit_time'] or ''

        if date != '' and time == '':
            redirect_to_url(req, "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
                            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_date']))
        elif date == '' and time != '':
            redirect_to_url(req, "%s/batchuploader/documents?error=4&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
                            % (CFG_SITE_SECURE_URL, argd['mode'], argd['docfolder'], argd['matching'], argd['submit_time']))

        errors, info = document_upload(req, argd['docfolder'], argd['matching'],
                                       argd['mode'], date, time, argd['ln'], argd['priority'])

        body = batchuploader_templates.tmpl_display_menu(argd['ln'])
        uid = getUid(req)
        navtrail = '''<a class="navtrail" href="%s/batchuploader/documents">%s</a>''' % \
                    (CFG_SITE_SECURE_URL, _("Document batch upload"))

        body += batchuploader_templates.tmpl_display_web_docupload_result(argd['ln'], errors, info)
        title = _("Document batch upload result")

        return page(title = title,
                    body = body,
                    metaheaderadd = batchuploader_templates.tmpl_styles(),
                    uid = uid,
                    navtrail = navtrail,
                    lastupdated = __lastupdated__,
                    req = req,
                    language = argd['ln'],
                    navmenuid = "batchuploader")
Example #3
0
            progress += 1
            task_update_progress("Done %d out of %d." % (progress, len(list_of_folders)))
    else:
        # Documents upload
        parent_dir = daemon_dir + "/documents/"
        try:
            os.makedirs(parent_dir)
        except OSError:
            pass
        matching_order = CFG_BATCHUPLOADER_FILENAME_MATCHING_POLICY
        for base_folder in ["append", "revise"]:
            folder = os.path.join(parent_dir, base_folder)
            if not os.path.exists(folder):
                os.makedirs(folder)
            for matching in matching_order:
                errors, info = document_upload(folder=folder, matching=matching, mode=base_folder)
                task_sleep_now_if_required(can_stop_too=True)
                if not errors:
                    break  # All documents succedeed with that matching
                for error in errors:
                    write_message("File: %s - %s with matching %s" % (error[0], error[1], matching), sys.stderr)
                write_message("Uploaded %s files: %s" % (info[0], ', '.join(info[1])))
    return 1


def main():
    """ Main that constructs all the bibtask. """
    task_init(authorization_action='runbatchuploader',
              authorization_msg="Batch Uploader",
              description="""Description:
    The batch uploader has two different run modes.
                    jobid = str(task_low_level_submission('bibupload', 'batchupload', mode, filename))
                    # Move file to done folder
                    filename = metafile + "_" + time.strftime("%Y%m%d%H%M%S", time.localtime()) + "_" + jobid
                    os.rename(os.path.join(files_dir, metafile), os.path.join(files_done_dir, filename))
                    task_sleep_now_if_required(can_stop_too=True)
            progress += 1
            task_update_progress("Done %d out of 4." % progress)
    else:
        # Documents upload
        daemon_dir = CFG_BATCHUPLOADER_DAEMON_DIR[0] == '/' and CFG_BATCHUPLOADER_DAEMON_DIR \
                     or CFG_PREFIX + '/' + CFG_BATCHUPLOADER_DAEMON_DIR
        parent_dir = daemon_dir + "/documents/"
        matching_order = CFG_BATCHUPLOADER_FILENAME_MATCHING_POLICY
        for folder in ["append/", "revise/"]:
            for matching in matching_order:
                errors = document_upload(folder=parent_dir + folder, matching=matching, mode=folder[:-1])[0]
                if not errors:
                    break # All documents succedeed with that matching
                for error in errors:
                    write_message("File: %s - %s with matching %s" % (error[0], error[1], matching), sys.stderr)
            task_sleep_now_if_required(can_stop_too=True)
    return 1

def main():
    """ Main that constructs all the bibtask. """
    task_init(authorization_action='runbatchuploader',
            authorization_msg="Batch Uploader",
            description="""Description:
    The batch uploader has two different run modes.
    If --metadata is specified (by default) then all files in folders insert,
    append, correct and replace are uploaded using the corresponding mode.
    def docsubmit(self, req, form):
        """ Function called after submitting the document upload form.
            Performs the appropiate action depending on the input parameters
        """
        argd = wash_urlargd(
            form,
            {
                "docfolder": (str, ""),
                "matching": (str, ""),
                "mode": (str, ""),
                "submit_date": (str, ""),
                "submit_time": (str, ""),
                "priority": (str, ""),
            },
        )
        _ = gettext_set_language(argd["ln"])

        not_authorized = user_authorization(req, argd["ln"])
        if not_authorized:
            return not_authorized
        # Check if input fields are correct, if not, redirect to upload form
        correct_date = check_date(argd["submit_date"])
        correct_time = check_time(argd["submit_time"])
        if correct_time != 0:
            redirect_to_url(
                req,
                "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
                % (CFG_SITE_SECURE_URL, argd["mode"], argd["docfolder"], argd["matching"], argd["submit_date"]),
            )
        if correct_date != 0:
            redirect_to_url(
                req,
                "%s/batchuploader/documents?error=%s&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
                % (
                    CFG_SITE_SECURE_URL,
                    correct_date,
                    argd["mode"],
                    argd["docfolder"],
                    argd["matching"],
                    argd["submit_time"],
                ),
            )

        date = argd["submit_date"] not in ["yyyy-mm-dd", ""] and argd["submit_date"] or ""
        time = argd["submit_time"] not in ["hh:mm:ss", ""] and argd["submit_time"] or ""

        if date != "" and time == "":
            redirect_to_url(
                req,
                "%s/batchuploader/documents?error=1&mode=%s&docfolder=%s&matching=%s&submit_date=%s"
                % (CFG_SITE_SECURE_URL, argd["mode"], argd["docfolder"], argd["matching"], argd["submit_date"]),
            )
        elif date == "" and time != "":
            redirect_to_url(
                req,
                "%s/batchuploader/documents?error=4&mode=%s&docfolder=%s&matching=%s&submit_time=%s"
                % (CFG_SITE_SECURE_URL, argd["mode"], argd["docfolder"], argd["matching"], argd["submit_time"]),
            )

        errors, info = document_upload(
            req, argd["docfolder"], argd["matching"], argd["mode"], date, time, argd["ln"], argd["priority"]
        )

        body = batchuploader_templates.tmpl_display_menu(argd["ln"])
        uid = getUid(req)
        navtrail = """<a class="navtrail" href="%s/batchuploader/documents">%s</a>""" % (
            CFG_SITE_SECURE_URL,
            _("Document batch upload"),
        )

        body += batchuploader_templates.tmpl_display_web_docupload_result(argd["ln"], errors, info)
        title = _("Document batch upload result")

        return page(
            title=title,
            body=body,
            metaheaderadd=batchuploader_templates.tmpl_styles(),
            uid=uid,
            navtrail=navtrail,
            lastupdated=__lastupdated__,
            req=req,
            language=argd["ln"],
            navmenuid="batchuploader",
        )
    else:
        # Documents upload
        parent_dir = daemon_dir + "/documents/"
        try:
            os.makedirs(parent_dir)
        except OSError:
            pass
        matching_order = CFG_BATCHUPLOADER_FILENAME_MATCHING_POLICY
        for folder in ["append/", "revise/"]:
            try:
                os.mkdir(parent_dir + folder)
            except:
                pass
            for matching in matching_order:
                errors = document_upload(folder=parent_dir + folder,
                                         matching=matching,
                                         mode=folder[:-1])[0]
                if not errors:
                    break  # All documents succedeed with that matching
                for error in errors:
                    write_message(
                        "File: %s - %s with matching %s" %
                        (error[0], error[1], matching), sys.stderr)
            task_sleep_now_if_required(can_stop_too=True)
    return 1


def main():
    """ Main that constructs all the bibtask. """
    task_init(
        authorization_action='runbatchuploader',