-
Notifications
You must be signed in to change notification settings - Fork 0
/
MVC.py
executable file
·62 lines (50 loc) · 2.36 KB
/
MVC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# Model View Controller Class
# A relativly simple class to help connect and unify the Garden Pi web and hardware aspects
import sys
from sys import path
import os
from config.webserver_config import settings as cherrypy_config
from config.app_config import settings as app_config
class MVC( object ):
def __init__( self ):
self.app_name = 'Framework 1'
self.app_dir = os.path.abspath( os.path.dirname(__file__) ) + '/'
self.logging = True
self.raspberry_pi = True
self.db = {
'host' : app_config['database']['host'],
'name' : app_config['database']['name'],
'user' : app_config['database']['user'],
'pass' : app_config['database']['pass'],
}
self.cherrypy_config = cherrypy_config
#self.cherrypy_config['global']['server.sock_port'] = garden_pi_config['webserver']['host_port']
#self.cherrypy_config['global']['server.sock_host'] = garden_pi_config['webserver']['host_ip']
#self.cherrypy_config['/']['tools.staticdir.root'] = '%spublic_html' % self.app_dir
def loadDriver( self, driver_name, args = None, callable = False ):
return self.__load( 'Driver', driver_name, args = args, callable = callable )
def loadController( self, controller_name, args = None, callable = False ):
return self.__load( 'Controller', controller_name, args = args, callable = callable )
def loadModel( self, model_name, args = None, callable = False ):
return self.__load( 'Model', model_name, args = args, callable = callable )
def loadHelper( self, helper_name, args = None, callable = False ):
return self.__load( 'Helper', helper_name, args = args, callable = callable )
def __load( self, type, name, args = None, callable = False ):
if '/' in name:
folder = name[ 0 : name.find('/') ]
name = name[ name.find('/') + 1 : len( name ) ]
path.insert( 1, self.app_dir + type.lower() + 's/' + folder )
else:
path.insert( 1, self.app_dir + type.lower() + 's' )
item_name = type + name
__import__( item_name )
if args:
item = getattr( sys.modules[ "%s" % item_name ], "%s" % item_name )( args )
else:
if callable:
item = getattr( sys.modules[ "%s" % item_name ], "%s" % item_name )
else:
item = getattr( sys.modules[ "%s" % item_name ], "%s" % item_name )( )
return item
# Endfile: MVC.py