def ft_db_connect_sqlite(path=None): """ Connect to sqlite dababase, with given path or default path. """ if path != None: db_path = path else: db_path = ft_getconfig('DATABASEPATH')+ft_getconfig('DATABASENAME') conn = sqlite3.connect(db_path) return conn
def ft_api_submit(): """ Used for XHR to POST desired flasktex job. QUERY_STRING example as follows: * renderer=xelatex * timeout=60 """ # TODO AUTH # Then, obtain data and start the job try: data = request.get_data().decode('UTF-8') except UnicodeDecodeError as e: abort(400, 'UnicodeDecodeError') renderer = ft_getconfig('DEFAULTRENDERER') timeout = ft_getconfig('WORKERTIMEOUT') if not request.args.get('renderer') == None: renderer = request.args.get('renderer') if not request.args.get('timeout') == None: timeout = request.args.get('timeout') worker = flasktex.texworker.TexWorker(data, renderer=renderer, timeout=timeout) worker.run() return make_response('ok workid={}'.format(worker.workid), 200)
""" Background worker for latex """ import subprocess import os, sys import shutil import signal import sqlite3 import time import syslog import multiprocessing from flasktex.config import ft_getconfig # CONFIG DEFAULT_RENDERER = ft_getconfig("DEFAULTRENDERER") DEFAULT_TIMEOUT = ft_getconfig("WORKERTIMEOUT") DATABASE_NAME = ft_getconfig("DATABASENAME") DATABASE_PATH = ft_getconfig("DATABASEPATH") assert DEFAULT_RENDERER assert DEFAULT_TIMEOUT assert DATABASE_NAME assert DATABASE_PATH class TexWorker(): """ A background worker to automatically finish the work. Will indeed daemonize by double-fork. Will end-up in given seconds. """