def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # Establish the Registry for this application app = RegistryManager(app) # Static files javascripts_app = StaticJavascripts() static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) return app
def setup_config(command, filename, section, vars): """Place any commands to setup testing here""" print "Setup beginning" conf = appconfig('config:' + filename) load_environment(conf.global_conf, conf.local_conf) g = config['pylons.g'] # Populate the DB on 'paster setup-app' import cfgsrv.model as model print "Setting up database connectivity..." engine = g.sa_engine print "Creating tables..." model.metadata.create_all(bind=engine) # Create default administrator print "Creating default admin if not existing" try: q = model.Session.query(model.Admin) q.filter(model.Admin.login_name == 'inveneo').one() print "Admin already existing" except: admin_q = model.Admin() admin_q.login_name = 'inveneo' admin_q.first_name = 'Inveneo' admin_q.last_name = 'Administrator' admin_q.salt = SALT admin_q.password = crypt.crypt('1nvene0', SALT) # admin_q.salt = str(random.randint(0, 99)) + str(random.randint(0, 99)) # admin_q.password = crypt.crypt('<the usual>', admin_q.salt) model.Session.save(admin_q) model.Session.commit() print "Successfully created default admin" # Migrate old data old_station = model.Session.query(model.Old_Station).first() if old_station: print "There be existing data here, yar!" old_stations = model.Session.query(model.Old_Station).all() for old_station in old_stations: mac = old_station.mac print "Copying data for MAC %s" % mac new_station = model.Station(mac) new_station.update(old_station.properties()) model.Session.save(new_station) for old_station in old_stations: model.Session.delete(old_station) model.Session.commit() # Create default station print "Creating default station" stations = model.Session.query(model.Station) station = stations.filter(model.Station.mac == g.DEFAULT_MAC).first() if station: print "Default station already exists" else: station = model.Station(g.DEFAULT_MAC) model.Session.save(station) model.Session.commit() print "Successfully created default station" # Create default server print "Creating default server" servers = model.Session.query(model.Server) server = servers.filter(model.Server.name == g.DEFAULT_SERVER).first() if server: print "Server already existing" else: server = model.Server(g.DEFAULT_SERVER) model.Session.save(server) model.Session.commit() print "Successfully created default server" print "Setup finished"