Exemplo n.º 1
0
def convert_to_diva(result_id, runjob_id, *args, **kwargs):
    runjob = RunJob.objects.get(pk=runjob_id)

    if result_id is None:
        page = runjob.page.compat_file_path
    else:
        result = Result.objects.get(result_id)
        page = result.result.path

    new_result = Result(run_job=runjob)
    new_result.save()

    result_save_path = new_result.result_path

    tdir = tempfile.mkdtemp()
    # some tiff files are corrupted, causing KDU to bail.
    # We'll take the safe route and convert all files, TIFF or not.
    name = os.path.basename(page)
    name, ext = os.path.splitext(name)

    tfile = os.path.join(tdir, "{0}.tiff".format(name))

    subprocess.call([PATH_TO_VIPS, "im_copy", page, tfile])

    result_file = "{0}.jpx".format(name)
    output_file = os.path.join(tdir, result_file)

    subprocess.call([
        PATH_TO_KDU, "-i", tfile, "-o", output_file, "-quiet", "Clevels=5",
        "Cblk={64,64}", "Cprecincts={256,256},{256,256},{128,128}",
        "Creversible=yes", "Cuse_sop=yes", "Corder=LRCP", "ORGgen_plt=yes",
        "ORGtparts=R", "-rate", "-,1,0.5,0.25"
    ])

    f = open(output_file, 'rb')
    new_result.result.save(os.path.join(result_save_path, result_file),
                           File(f))
    f.close()
    # debugging
    # shutil.move(tfile, result_save_path)
    shutil.rmtree(tdir)

    return str(new_result.uuid)
Exemplo n.º 2
0
def dummy_job(result_id, runjob_id, *args, **kwargs):
    runjob = RunJob.objects.get(pk=runjob_id)

    if result_id is None:
        page = runjob.page.compat_file_path
    else:
        result = Result.objects.get(result_id)
        page = result.result.path

    new_result = Result(run_job=runjob)
    new_result.save()

    result_save_path = new_result.result_path

    f = open(page, 'rb')
    new_result.result.save(os.path.join(result_save_path, page), File(f))
    f.close()

    return str(new_result.uuid)
Exemplo n.º 3
0
    def run_task(self, result_id, runjob_id, *args, **kwargs):
        runjob = RunJob.objects.get(pk=runjob_id)
        taskutil.set_runjob_status(runjob, RunJobStatus.RUNNING)

        # fall through to retrying if we're waiting for input
        if runjob.needs_input:
            runjob = taskutil.set_runjob_status(runjob,
                                                RunJobStatus.WAITING_FOR_INPUT)
            self.retry(args=[result_id, runjob_id],
                       *args,
                       countdown=10,
                       **kwargs)

        if runjob.status == RunJobStatus.WAITING_FOR_INPUT:
            runjob = taskutil.set_runjob_status(runjob, RunJobStatus.RUNNING)

        if result_id is None:
            # this is the first job in a run
            page = runjob.page.compat_file_path
        else:
            # we take the page image we want to operate on from the previous result object
            result = Result.objects.get(pk=result_id)
            page = result.result.path

        new_result = Result(run_job=runjob)
        taskutil.save_instance(new_result)

        result_save_path = new_result.result_path

        settings = {}
        for s in runjob.job_settings:
            setting_name = "_".join(s['name'].split(" "))
            setting_value = argconvert.convert_to_arg_type(
                s['type'], s['default'])
            settings[setting_name] = setting_value

        init_gamera()

        task_image = load_image(page)
        tdir = tempfile.mkdtemp()
        task_function = self.name.split(".")[-1]
        result_image = getattr(task_image, task_function)(**settings)
        result_file = "{0}.png".format(str(uuid.uuid4()))
        result_image.save_image(os.path.join(tdir, result_file))

        f = open(os.path.join(tdir, result_file))
        taskutil.save_file_field(new_result.result,
                                 os.path.join(result_save_path, result_file),
                                 File(f))
        f.close()
        shutil.rmtree(tdir)

        return str(new_result.uuid)
Exemplo n.º 4
0
def init_result(runjob):
    new_result = Result(run_job=runjob)
    new_result.save()
    return new_result
Exemplo n.º 5
0
def init_result(runjob):
    new_result = Result(run_job=runjob)
    new_result.save()
    return new_result