Created
February 9, 2014 20:22
-
-
Save appcove/8905424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim:encoding=utf-8:ts=2:sw=2:expandtab | |
from AppStruct.Util import * | |
from AppStruct.Web.Util import * | |
import AppStruct | |
import AppStruct.Util | |
import AppStruct.Web.Util | |
import FileStruct | |
############################################################################### | |
# Conf imports that don't need to be exposed in App | |
from .Local import Postgres, FileStruct_Path | |
@ConvertToInstance | |
class App(AppStruct.ThreadedApp): | |
# Conf imports | |
from .Local import Path, Identifier, DevLevel, CacheTime | |
# Database Connection | |
@AppStruct.ThreadedAppProperty | |
def DB(self, client): | |
if client is None or client.state == 'closed': | |
client = AppStruct.Database.PostgreSQL.Open(**Postgres) | |
return client | |
# Redis Connection | |
@AppStruct.ThreadedAppProperty | |
def Redis(self, client): | |
if client is None: | |
client = AppStruct.Database.Redis.Redis(db=self.DevLevel) | |
return client | |
# FileStruct Connection | |
@AppStruct.ThreadedAppProperty | |
def FS(self, client): | |
if client is None: | |
client = FileStruct.Client(FileStruct_Path) | |
return client | |
# Called once when the app loads | |
def Init(self): | |
with self: | |
self.Setting.update(self.DB.Row('SELECT * FROM "Main"."Setting"')) | |
self.Setting.test = 123 | |
# Called once per thread as the app loads | |
def ThreadInit(self): | |
pass | |
############################################################################### | |
# Global Utility Functions | |
############################################################################### | |
# Define all of the gloabls that will be imported with * | |
__all__ = \ | |
AppStruct.Util.__all__ + \ | |
AppStruct.Web.Util.__all__ + \ | |
( | |
'App', | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment