def connect(path, spatialite_path, evn_sep=';'): """ データベースへの接続 @param path sqliteのパス @param spatialite_path mod_spatialiteへのパス @param env_sep 環境変数PATHの接続文字 WINDOWSは; LINUXは: """ os.environ["PATH"] = os.environ["PATH"] + evn_sep + os.path.dirname( spatialite_path) db = SqliteExtDatabase(path) database_proxy.initialize(db) db.field_overrides = { 'polygon': 'POLYGON', 'point': 'POINT', 'linestring': 'LINESTRING', 'multipolygon': 'MULTIPOLYGON', 'multipoint': 'MULTIPOINT', 'multilinestring': 'MULTILINESTRING', } db.load_extension(os.path.basename(spatialite_path))
from tornado.options import options from playhouse.sqlite_ext import SqliteExtDatabase, ClosureTable from peewee import (Model, CharField, ForeignKeyField, IntegerField, BooleanField, DateTimeField, DoesNotExist, OperationalError) import fs log = logging.getLogger("tornado.general") """ connect to db load closure module create tables """ db = SqliteExtDatabase(options.db_file) db.load_extension(options.sqlite_closure_table_so) class File(Model): path = CharField() bytes = IntegerField() is_dir = BooleanField() modified = DateTimeField() size = CharField() # redundant parent = ForeignKeyField('self', null=True, related_name='children') class Meta: database = db FileClosure = ClosureTable(File)
fr = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") ch.setFormatter(fr) log.addHandler(ch) src_root = os.path.realpath(os.path.dirname(__file__)) log.debug("running in : {}".format(src_root)) app_root = os.path.realpath(os.path.dirname(src_root)) log.debug("application root is : {}".format(app_root)) #TODO: database selector db = SqliteExtDatabase(os.path.join(src_root, 'test_create_db.db')) #NOTE: the bin/sqlite/closure.so must be compilled before script use db_closure_ext = os.path.join(app_root, 'bin/sqlite/closure') #NOTE: do not include the ".so" db.load_extension(db_closure_ext) log.debug("database is : %s", db) log.debug("sqlite closure extension loaded : {}".format(ClosureTable)) #~ username = os.environ.get("USER") username = os.getenv("USER") log.debug("username is : %s", username) #~ class log(object): #~ class Host: def localhost_infos(): """ Return a collections.namedtuples of host machine informations """
from tornado.options import options from playhouse.sqlite_ext import SqliteExtDatabase, ClosureTable from peewee import (Model, CharField, ForeignKeyField, IntegerField, BooleanField, DateTimeField, DoesNotExist, OperationalError) import fs log = logging.getLogger("tornado.general") """ connect to db load closure module create tables """ db = SqliteExtDatabase(options.db_file) db.load_extension(options.sqlite_closure_table_so) class File(Model): path = CharField() bytes = IntegerField() is_dir = BooleanField() modified = DateTimeField() size = CharField() # redundant parent = ForeignKeyField('self', null=True, related_name='children') class Meta: database = db FileClosure = ClosureTable(File)