def setup_testing_db(): cp = ConfigParser.ConfigParser() cp.read("../development.ini") config = { "sqlalchemy.url": cp.get("app:main", "sqlalchemy.url", 0, {"here": normpath("%s/.." % dirname(abspath(__file__)))}) } # Setup the SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') model.init_model(engine) log.info("Create testing user accounts ...") random.seed("whatever") for i in range(0,100): sur_name = sur_names[random.randint(0, len(sur_names)-1)] given_name = given_names[random.randint(0, len(given_names)-1)] username = "******" % (sur_name, given_name) try: q = Session.query(model.DKUser) r = q.get(username) if not r: user = model.DKUser() user.username = username user.roles = ":".join(["", meta.ROLE_USER, ""]) user.passwd = hashlib.md5("cpksecurity").hexdigest() user.master_email = "*****@*****.**" % username user.actived = True Session.add(user) Session.commit() log.info(" Account '%s' setup complete." % username) else: log.info("Account '%s' already setup." % username) except Exception, e: print e
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ config = PylonsConfig() # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict( root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')], cpkdir=os.path.join(root, 'cpk'), ) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='doorkeeper', paths=paths) config['routes.map'] = make_map(config) config['pylons.app_globals'] = app_globals.Globals(config) config['pylons.h'] = doorkeeper.lib.helpers # Setup cache object as early as possible import pylons pylons.cache._push_object(config['pylons.app_globals'].cache) # Create the Mako TemplateLookup, with the default auto-escaping config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], error_handler=handle_mako_error, module_directory=os.path.join(app_conf['cache_dir'], 'templates'), input_encoding='utf-8', default_filters=['escape'], imports=['from webhelpers.html import escape']) # Setup the SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') model.init_model(engine) #init system parameters q = model.Session.query(model.DKSystem) config['pylons.app_globals'].system_params = dict([(e.key, e.val) for e in q.all()]) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) return config
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ config = PylonsConfig() # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')], cpkdir=os.path.join(root,'cpk'), ) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='doorkeeper', paths=paths) config['routes.map'] = make_map(config) config['pylons.app_globals'] = app_globals.Globals(config) config['pylons.h'] = doorkeeper.lib.helpers # Setup cache object as early as possible import pylons pylons.cache._push_object(config['pylons.app_globals'].cache) # Create the Mako TemplateLookup, with the default auto-escaping config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], error_handler=handle_mako_error, module_directory=os.path.join(app_conf['cache_dir'], 'templates'), input_encoding='utf-8', default_filters=['escape'], imports=['from webhelpers.html import escape']) # Setup the SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') model.init_model(engine) #init system parameters q = model.Session.query(model.DKSystem) config['pylons.app_globals'].system_params = dict([(e.key, e.val) for e in q.all()]) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) return config
def setup_testing_db(): cp = ConfigParser.ConfigParser() cp.read("../development.ini") config = { "sqlalchemy.url": cp.get("app:main", "sqlalchemy.url", 0, {"here": normpath("%s/.." % dirname(abspath(__file__)))}) } # Setup the SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') model.init_model(engine) log.info("Create testing user accounts ...") random.seed("whatever") for i in range(0, 100): sur_name = sur_names[random.randint(0, len(sur_names) - 1)] given_name = given_names[random.randint(0, len(given_names) - 1)] username = "******" % (sur_name, given_name) try: q = Session.query(model.DKUser) r = q.get(username) if not r: user = model.DKUser() user.username = username user.roles = ":".join(["", meta.ROLE_USER, ""]) user.passwd = hashlib.md5("cpksecurity").hexdigest() user.master_email = "*****@*****.**" % username user.actived = True Session.add(user) Session.commit() log.info(" Account '%s' setup complete." % username) else: log.info("Account '%s' already setup." % username) except Exception, e: print e