Skip to content

Instantly share code, notes, and snippets.

@appcove
Created February 9, 2014 20:22
Show Gist options
  • Save appcove/8905424 to your computer and use it in GitHub Desktop.
Save appcove/8905424 to your computer and use it in GitHub Desktop.
# 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