# Path: jobs/sge_jobs.py
# class DbJob(db.UserDb):
#     def __init__(self):
#     def get_job_table(self, state_filter, limit = 50, offset = 0,
#                       cmd_filter = None):
#     def get_accounting_table(self, limit = 50, offset = 0, job_ids = None):
#     def pending_request(self, limit = 16, offset = 0):
#     def _add_request(self, jobname, run_cmd, args, max_vmem, cpu_bound, force):
#     def add_request(self, jobname, run_cmd, args,  max_vmem,
#                     cpu_bound = True, force = False):
#     def exec_request(self, r):
#     def run_batch(self, nr_running, limit = 16):
#     def _exec_check(self, request):
#     def check_running(self):
#     def search_accounting(self, jobs, last_time_day = 2):
#     def update_accounting(self):
# def quote_arg(arg):
# def job_cmdline_arg(request, cmd):
# def sge_cmdline_arg(request):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):


import json
import pdf_to_djvu
import sys
import os
    import cgi
from jobs import sge_jobs
from common import utils
    from flup.server.cgi import WSGIServer
# -*- coding: utf-8 -*-
#
# @file pdf_to_djvu_cgi.py
#
# @remark Copyright 2016 Philippe Elie
# @remark Read the file COPYING
#
# @author Philippe Elie


def queue_pdf_to_djvu(ia_id):
    job_req = {
        'jobname' : 'pdf_to_djvu',
        'run_cmd' : 'python',
        'force' : True,
        'args' : [
            os.path.expanduser('~/phe/ocr/pdf_to_djvu.py'),
            # FIXME: later use command line switch to provide a more general
            # service
            ia_id,
            ],
        'max_vmem' : 2048,
        }

    db_obj = sge_jobs.DbJob()

    print job_req

    db_obj.add_request(**job_req)


# Path: jobs/sge_jobs.py
# class DbJob(db.UserDb):
#     def __init__(self):
#     def get_job_table(self, state_filter, limit = 50, offset = 0,
#                       cmd_filter = None):
#     def get_accounting_table(self, limit = 50, offset = 0, job_ids = None):
#     def pending_request(self, limit = 16, offset = 0):
#     def _add_request(self, jobname, run_cmd, args, max_vmem, cpu_bound, force):
#     def add_request(self, jobname, run_cmd, args,  max_vmem,
#                     cpu_bound = True, force = False):
#     def exec_request(self, r):
#     def run_batch(self, nr_running, limit = 16):
#     def _exec_check(self, request):
#     def check_running(self):
#     def search_accounting(self, jobs, last_time_day = 2):
#     def update_accounting(self):
# def quote_arg(arg):
# def job_cmdline_arg(request, cmd):
# def sge_cmdline_arg(request):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):


# Path: ocr/pdf_to_djvu_cgi.py
import json
import pdf_to_djvu
import sys
import os
    import cgi
from jobs import sge_jobs
from common import utils
    from flup.server.cgi import WSGIServer

# -*- coding: utf-8 -*-
#
# @file pdf_to_djvu_cgi.py
#
# @remark Copyright 2016 Philippe Elie
# @remark Read the file COPYING
#
# @author Philippe Elie


def queue_pdf_to_djvu(ia_id):
    job_req = {
        'jobname' : 'pdf_to_djvu',
        'run_cmd' : 'python',
        'force' : True,
        'args' : [
            os.path.expanduser('~/phe/ocr/pdf_to_djvu.py'),
            # FIXME: later use command line switch to provide a more general
            # service
            ia_id,
            ],
        'max_vmem' : 2048,
        }

    db_obj = sge_jobs.DbJob()

    print job_req

    db_obj.add_request(**job_req)


def query_params(environ):