def app_conf(): "init db and return app_conf" m_conf = g.conf.mconfig['contact'] db_path = os.path.join(g.conf._basedir, m_conf['db_path']) db = SqliteDatabase(db_path, **g.conf.DATABASE_CONNECT_OPTIONS) # proxy to db db_proxy.initialize(db) if not os.path.exists(db_path): db_init(db, m_conf) return m_conf
def init_proxy(dbURL): '''Instantiate proxy to the database :param dbURL: the url describing connection parameters to the choosen database. The url must have format explained in the `Peewee url documentation <http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#db-url>`_. examples: * sqlite: ``sqlite:///my_database.db`` * postgres: ``postgresql://postgres:my_password@localhost:5432/my_database`` * mysql: ``mysql://user:passwd@ip:port/my_db`` ''' db_proxy.initialize(db_url.connect(dbURL)) return db_proxy
def db_conn(): app_conf = g.conf.mconfig['rna_seq'] db_path = os.path.join(g.conf._basedir, app_conf['db_path']) db = SqliteDatabase(db_path, **g.conf.DATABASE_CONNECT_OPTIONS) db_proxy.initialize(db) return app_conf
import json, os from flask import g from models import db_proxy, Job, Job_type, Ip, Mail from datetime import datetime from peewee import SqliteDatabase from jinja2 import Environment, FileSystemLoader from share_util import guid, mail_handler import job_types from app import sys_conf app_conf = sys_conf.mconfig['jobs'] print(os.path.join(sys_conf._basedir, app_conf['db_path'])) db_path = os.path.join(sys_conf._basedir, app_conf['db_path']) db = SqliteDatabase(db_path, **sys_conf.DATABASE_CONNECT_OPTIONS) db_proxy.initialize(db) if not os.path.exists(db_path): db.create_tables([Job_type, Ip, Mail, Job], safe=True) for i in app_conf['type2info']: Job_type.create(name=i) class job_handler(): """offer a interface to treat web job """ def __init__(self): self.version = 'test' def add_by_info(self, info_o): "save a job from request" # check info_o in db or not t_sql = Job.select().where(Job.guid == info_o.get('guid', ''))
def db_load(self): "load db" db_path = os.path.join(sys_conf._basedir, self.m_conf['db_path']) db = SqliteDatabase(db_path, **sys_conf.DATABASE_CONNECT_OPTIONS) db_proxy.initialize(db)