Пример #1
0
	def get_template(self, uri):
		""" Look for URI with db prefix indicating we need to check/load from the database """
		if uri.startswith('db:'):
			database = request.environ.get('wsgiorg.routing_args', (None,{}))[1].get('database', None)
			name = uri[3:]
			uri = "db:%s:%s" % (database, name)  # Create a more unique URI for caching
			# Try and load the template from the database
			format = Session.query(Data).get(name)
			if format is not None:
				text = str(format.data)
				dbhash = hash(text)
	
				# Load the hash value from the cached version (if it exists)
				try:
					cachehash = hash(TemplateLookup.get_template(self, uri).source)
				except exceptions.TemplateLookupException, e:
					cachehash = -1
	
				# If the hash values are different, recompile and place the new version in the cache
				if cachehash != dbhash:
					log.debug("compile %s" % (uri))
					self.put_string(uri, text)
			else:
				c.missingtemplate = uri
				log.error("Cant locate template for DB uri '%s'" % uri)
				uri = '/missing.mako' # switch to missing template
			Session.close()
Пример #2
0
    def get_template(self, uri):
        """ Look for URI with db prefix indicating we need to check/load from the database """
        if uri.startswith('db:'):
            database = request.environ.get('wsgiorg.routing_args',
                                           (None, {}))[1].get(
                                               'database', None)
            name = uri[3:]
            uri = "db:%s:%s" % (database, name
                                )  # Create a more unique URI for caching
            # Try and load the template from the database
            format = Session.query(Data).get(name)
            if format is not None:
                text = str(format.data)
                dbhash = hash(text)

                # Load the hash value from the cached version (if it exists)
                try:
                    cachehash = hash(
                        TemplateLookup.get_template(self, uri).source)
                except exceptions.TemplateLookupException, e:
                    cachehash = -1

                # If the hash values are different, recompile and place the new version in the cache
                if cachehash != dbhash:
                    log.debug("compile %s" % (uri))
                    self.put_string(uri, text)
            else:
                c.missingtemplate = uri
                log.error("Cant locate template for DB uri '%s'" % uri)
                uri = '/missing.mako'  # switch to missing template
            Session.close()
Пример #3
0
def loadAttendanceFromDB(dbpath):
	ret = list()
	match = re.search('(\w+?)(\d+)\.db$', dbpath)
	if match is None:
		return ret
	series = match.group(1)
	year = int(match.group(2))

	session = Session()
	session.bind = create_engine('sqlite:///%s' % dbpath)
	settings = Settings()
	settings.load(session)

	for row in session.execute("select d.firstname, d.lastname, count(distinct r.eventid) from runs as r, cars as c, drivers as d where r.carid=c.id and c.driverid=d.id and r.eventid < 100 group by d.id"):
		count = int(row[2])
		ret.append((series.lower(), year, row[0].lower().strip(), row[1].lower().strip(), count, int(count > settings.useevents)))

	return ret
Пример #4
0
	def __call__(self, environ, start_response):
		"""Invoke the Controller"""
		# WSGIController.__call__ dispatches to the Controller method
		# the request is routed to. This routing information is
		# available in environ['pylons.routes_dict']
		log.debug("start(%s)" % (environ['PATH_INFO']))

		self.srcip = request.environ.get("X_FORWARDED_FOR", request.environ["REMOTE_ADDR"]) 
		self.routingargs = environ['wsgiorg.routing_args'][1]
		self.database = self.routingargs.get('database', None)
		if os.path.exists(self.databasePath(self.database)):
			engine = create_engine('sqlite:///%s' % self.databasePath(self.database), poolclass=NullPool)
		else:
			engine = create_engine('sqlite:///:memory:', poolclass=NullPool)
			self.database = None

		self.session = Session()
		self.session.bind = engine
		metadata.bind = engine

		self.settings = Settings()
		if self.database is not None:
			self.settings.load(self.session)
			if self.settings.schema != '661':
				start_response('200 OK', [('content-type', 'text/html')], None)
				return "Software schema verison is 661 but series database is " + self.settings.schema +  \
					", database schema or software needs to be updated to match"

		try:
			try:
				return WSGIController.__call__(self, environ, start_response)
			except BeforePage, p:
				start_response('200 OK', [('content-type', 'text/html')], None)
				return p.data
		finally:
			Session.remove()
			log.debug("finish(%s): %f" % (environ['PATH_INFO'], time.time() - self.a))