def __init__(self, *args): paste.script.appinstall.SetupCommand('setup-app').run(['development.ini#test']) self.conf = appconfig('config:development.ini#test', relative_to=conf_dir) CONFIG.push_process_config({'app_conf': self.conf.local_conf, 'global_conf': self.conf.global_conf}) self.wsgiapp = loadapp('config:development.ini#test', relative_to=conf_dir) # FIXME: Sometimes, for some reason, this attribute isn't set, # which causes url_for to fail request_config().environ = { 'SCRIPT_NAME': '', 'HTTP_HOST': 'localhost', } self.setup_database() self.setup_fixtures() TestCase.__init__(self, *args)
def __init__(self): # Gets the application class name using Paste Deploy config appClassName = CONFIG.get(self.SERVLET_PARAMETER_APPLICATION) if appClassName is None: raise ServletException, ('Application not specified ' 'in servlet parameters') try: applicationClass = loadClass(appClassName) except ImportError: raise ServletException, ('Failed to import module: ' + appClassName) except AttributeError: raise ServletException, ('Failed to load application class: ' + appClassName) super(app, self).__init__(applicationClass) self._applicationProperties.update(CONFIG)
# Utility script to strip commas out of tag names # (in there because of bugs in form script that did not strip commas):w import os # here_dir = os.path.dirname(os.path.abspath(__file__)) # conf_dir = os.path.dirname(os.path.dirname(here_dir)) conf_dir = os.path.abspath('./') print conf_dir conf_file = os.path.join(conf_dir, 'development.ini') # conf_file = os.path.join(conf_dir, 'ckan.net.ini') from paste.deploy import loadapp, CONFIG import paste.deploy conf = paste.deploy.appconfig('config:' + conf_file) CONFIG.push_process_config({'app_conf': conf.local_conf, 'global_conf': conf.global_conf}) import ckan.models def correct(): print 'Beginning processing' for tag in ckan.models.Tag.select(): print 'Processing tag: ', tag.name if tag.name.endswith(','): print 'Tag with comma found' correct_name = tag.name[:-1] print 'Correct name: ', correct_name # is there a tag already out there with this name? existing = list(ckan.models.Tag.selectBy(name=correct_name)) if len(existing) == 0: # no -- then just rename print 'Renaming'
soClasses = [Group, User, Page, Tag, Comments, Annotation] def setup_classes(): all_extra = [] for cls in soClasses: print 'Handling table', cls.sqlmeta.table cls.dropTable(ifExists=True) sql, extra = cls.createTableSQL() all_extra.extend(extra) print sql cls.createTable(ifNotExists=True) print '\n'.join(all_extra) if __name__ == '__main__': import sys import os from paste.deploy import CONFIG, appconfig if not sys.argv[1:]: print 'usage: ... conf_file' sys.exit(2) conf_filename = sys.argv[1] if not conf_filename.startswith('config:'): conf_filename = 'config:' + conf_filename conf = appconfig(conf_filename, relative_to=os.getcwd()) conf = {'global_conf': conf.global_conf, 'app_conf': conf.local_conf} CONFIG.push_process_config(conf) setup_classes()
def setup_config(command, filename, section, vars): """ Set up the task tracker's fixtures """ dummy, sect = section.split(':') conf = appconfig('config:%s#%s' % (filename, sect), relative_to=conf_dir) load_environment(conf.global_conf, conf.local_conf, setup_config=True) CONFIG.push_process_config({'app_conf': conf.local_conf, 'global_conf': conf.global_conf}) #you'll need these when you need to zap tables # DONT EVER UNCOMMENT THIS CODE. # for table in soClasses[::-1]: # table.dropTable(ifExists=True) constraints = [] for table in soClasses: _constraints = table.createTable(ifNotExists=True, applyConstraints=False) if _constraints is not None: constraints += _constraints connection = hub.hub.getConnection() for constraint in constraints: connection.query(constraint) def makeUser(usename, password="******"): """Makes a user.""" return User(username=usename, password=password.encode("base64")) for user in """admin auth anon magicbronson rmarianski jhammel cabraham ltucker novalis rob whit ian smk jarasi cholmes bryan vanessa""".split(): makeUser(user) def makeRole(**kwargs): """Makes a role if it doesn't already exist.""" role = Role.selectBy(name = kwargs['name']) if role.count(): role = role[0] role.set(**kwargs) return role else: return Role(**kwargs) def makeAction(**kwargs): """Makes an action if it doesn't already exist.""" action = Action.selectBy(action = kwargs['action']) if action.count(): action = action[0] action.set(**kwargs) return action else: return Action(**kwargs) anon = makeRole(name="Anonymous", description="Anyone at all", level=100) auth = makeRole(name="Authenticated", description="Any logged-in OpenPlans user", level=60) pm = makeRole(name="ProjectMember", description="Any project member", level=50) taskowner = makeRole(name="TaskOwner", description="The person who owns the task", level=40) manager = makeRole(name="ListOwner", description="Any person who owns the list", level=30) pa = makeRole(name="ProjectAdmin", description="Any project administrator", level=20) all = [manager, pm, auth, anon] members = [manager, pm, auth] setRoles(makeAction(action="tasklist_create"), [pa, pm]) setRoles(makeAction(action="tasklist_delete"), [pa, manager]) setRoles(makeAction(action="task_show"), all) setRoles(makeAction(action="tasklist_show"), all) setRoles(makeAction(action="tasklist_update"), [manager, pa]) setRoles(makeAction(action="task_create"), all) setRoles(makeAction(action="task_update"), all) setRoles(makeAction(action="task_claim"), members) setRoles(makeAction(action="task_change_status"), all) setRoles(makeAction(action="task_assign"), members) setRoles(makeAction(action="task_comment"), members)
else: return Response("Not your server") else: h.redirect_to('login') # who gives import md5 import time import datetime import random import os from myghtyutils.session import Session from paste.deploy import CONFIG COOKIE_DOMAIN = CONFIG.current_conf()['app_conf']['cookie_domain'] def _my_create_id(self): # copy-pasted from session.py self.id = md5.new( "%f%s%f%d" % (time.time(), id({}), random.random(), os.getpid())).hexdigest() self.is_new = True if self.use_cookies: self.cookie[self.key] = self.id self.cookie[self.key]['path'] = '/' self.cookie[self.key]["domain"] = COOKIE_DOMAIN if self.cookie_expires is not True: if self.cookie_expires is False: expires = datetime.datetime.fromtimestamp(0x7FFFFFFF)
import pkg_resources pkg_resources.working_set.add_entry(conf_dir) pkg_resources.require('Paste') pkg_resources.require('PasteScript') from paste.deploy import loadapp, CONFIG import paste.deploy import paste.fixture import paste.script.appinstall from web.config.routing import * from routes import request_config, url_for test_file = os.path.join(conf_dir, 'test.ini') conf = paste.deploy.appconfig('config:' + test_file) CONFIG.push_process_config({'app_conf': conf.local_conf, 'global_conf': conf.global_conf}) cmd = paste.script.appinstall.SetupCommand('setup-app') cmd.run([test_file]) class TestController(TestCase): def __init__(self, *args): wsgiapp = loadapp('config:test.ini', relative_to=conf_dir) self.app = paste.fixture.TestApp(wsgiapp) TestCase.__init__(self, *args) __all__ = ['url_for', 'TestController']