Пример #1
0
 def __init__(self, script_path, site_name=None, _config=None, _gnrconfig=None, counter=None, noclean=None,
              options=None):
     global GNRSITE
     GNRSITE = self
     counter = int(counter or '0')
     self._currentPages = {}
     abs_script_path = os.path.abspath(script_path)
     if os.path.isfile(abs_script_path):
         self.site_path = os.path.dirname(abs_script_path)
     else:
         self.site_path = PathResolver().site_name_to_path(script_path)
     self.site_name = site_name or os.path.basename(self.site_path)
     if _gnrconfig:
         self.gnr_config = _gnrconfig
     else:
         self.gnr_config = self.load_gnr_config()
         self.set_environment()
         
     if _config:
         self.config = _config
     else:
         self.config = self.load_site_config()
         
     self.default_uri = self.config['wsgi?home_uri'] or '/'
     if self.default_uri[-1] != '/':
         self.default_uri += '/'
     self.mainpackage = self.config['wsgi?mainpackage']
     self.default_page = self.config['wsgi?default_page']
     self.allConnectionsFolder = os.path.join(self.site_path, 'data', '_connections')
     self.allUsersFolder = os.path.join(self.site_path, 'data', '_users')
     
     self.homepage = self.config['wsgi?homepage'] or self.default_uri + 'index'
     self.indexpage = self.config['wsgi?homepage'] or '/index'
     self._guest_counter = 0
     if not self.homepage.startswith('/'):
         self.homepage = '%s%s' % (self.default_uri, self.homepage)
     self.secret = self.config['wsgi?secret'] or 'supersecret'
     self.config['secret'] = self.secret
     self.debug = options.debug if options else boolean(self.config['wsgi?debug'])
     self.cache_max_age = self.config['wsgi?cache_max_age'] or 2592000
     self.statics = StaticHandlerManager(self)
     self.statics.addAllStatics()
     
     self.gnrapp = self.build_gnrapp()
     self.wsgiapp = self.build_wsgiapp()
     self.db = self.gnrapp.db
     self.dbstores = self.db.dbstores
     self.resource_loader = ResourceLoader(self)
     self.pages_dir = os.path.join(self.site_path, 'pages')
     self.site_static_dir = self.config['resources?site'] or '.'
     if self.site_static_dir and not os.path.isabs(self.site_static_dir):
         self.site_static_dir = os.path.normpath(os.path.join(self.site_path, self.site_static_dir))
     self.find_gnrjs_and_dojo()
     self.page_factory_lock = RLock()
     self.webtools = self.resource_loader.find_webtools()
     self.services = ServiceHandlerManager(self)
     self.print_handler = self.addService(PrintHandler, service_name='print')
     self.mail_handler = self.addService(MailHandler, service_name='mail')
     self.addSiteServices()
     self.register = SiteRegister(self)
     if counter == 0 and self.debug:
         self.onInited(clean=not noclean)