# 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/common_html.py
# def get_head(title, css = None, html5 = False):
# 
# 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 os
import sys
import json
import time
import types
import hocr
    import cgi
from jobs import sge_jobs
from common import common_html
from common import utils
    from flup.server.cgi import WSGIServer
   ('job_id', 'job id', format_job_id_accounting),
   ('sge_jobnumber', 'sge job id', format_sge_jobnumber_accounting),
   ('sge_hostname', 'host name', format_hostname),
   ('sge_qsub_time', 'submit at', format_timestamp),
   ('sge_start_time', 'start at', format_timestamp),
   ('sge_end_time', 'end at', format_timestamp),
   ('sge_failed', 'failed'),
   ('sge_exit_status', 'exit status'),
   ('sge_ru_utime', 'utime', format_time),
   ('sge_ru_stime', 'stime', format_time),
   ('sge_ru_wallclock', 'wallclock'),
   ('sge_used_maxvmem', 'max vmem', format_max_vmem),
]

def query_params(environ):
    field = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ)

    rdict = {
        'format' : 'html',
        'cmd' : 'status',
        'filter' : '',
        'book' : '',
        'lang' : ''
        }
    for name in field:
        if type(field[name]) == types.ListType:
            rdict[name] = field[name][-1].value
        else:
            rdict[name] = field[name].value


# 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/common_html.py
# def get_head(title, css = None, html5 = False):
# 
# 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: hocr/hocr_cgi.py
import os
import sys
import json
import time
import types
import hocr
    import cgi
from jobs import sge_jobs
from common import common_html
from common import utils
    from flup.server.cgi import WSGIServer

   ('job_id', 'job id', format_job_id_accounting),
   ('sge_jobnumber', 'sge job id', format_sge_jobnumber_accounting),
   ('sge_hostname', 'host name', format_hostname),
   ('sge_qsub_time', 'submit at', format_timestamp),
   ('sge_start_time', 'start at', format_timestamp),
   ('sge_end_time', 'end at', format_timestamp),
   ('sge_failed', 'failed'),
   ('sge_exit_status', 'exit status'),
   ('sge_ru_utime', 'utime', format_time),
   ('sge_ru_stime', 'stime', format_time),
   ('sge_ru_wallclock', 'wallclock'),
   ('sge_used_maxvmem', 'max vmem', format_max_vmem),
]

def query_params(environ):
    field = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ)

    rdict = {
        'format' : 'html',
        'cmd' : 'status',
        'filter' : '',
        'book' : '',
        'lang' : ''
        }
    for name in field:
        if type(field[name]) == types.ListType:
            rdict[name] = field[name][-1].value
        else:
            rdict[name] = field[name].value


    return rdict