本文整理汇总了Python中pyramid.paster.get_app函数的典型用法代码示例。如果您正苦于以下问题:Python get_app函数的具体用法?Python get_app怎么用?Python get_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_app函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
# Check if the pyramid config file is set, if so use paster to manage
# imports
conf_file = self.pyramid_conf()
if conf_file:
paster.get_app(conf_file)
else:
# instantiate a pyramid configurator
config = Configurator()
module_str = self.arguments[0]
# import the module
module = import_module(module_str)
# check if the module has an `includeme` method and call it
# because the base route must be added
if hasattr(module, 'includeme'):
module.includeme(config)
config.commit()
# scan the module for services
scanner = venusian.Scanner(config=config)
scanner.scan(module)
rendered = []
# fetch all services
services = get_services()
# if the services option is set render only the named services
names = self.options.get('services')
if names:
services = [s for s in services if s.baseRouteName in names]
for service in services:
service_id = "service_%d" % self.serialno('service')
rendered.append(ServiceDirective.render(service, service_id))
return rendered
示例2: main
def main():
parser = argparse.ArgumentParser(description="Create and populate the database tables.")
parser.add_argument("-i", "--iniconfig", default="production.ini", help="project .ini config file")
parser.add_argument("-n", "--app-name", default="app", help='The application name (optional, default is "app")')
options = parser.parse_args()
# read the configuration
get_app(options.iniconfig, options.app_name)
from c2cgeoportal.models import DBSession, Interface, OGCServer, Theme, LayerGroup, LayerWMS
session = DBSession()
interfaces = session.query(Interface).all()
ogc_server = session.query(OGCServer).filter(OGCServer.name == u"source for image/png").one()
layer_borders = LayerWMS(u"Borders", u"borders")
layer_borders.interfaces = interfaces
layer_borders.ogc_server = ogc_server
layer_density = LayerWMS(u"Density", u"density")
layer_density.interfaces = interfaces
layer_density.ogc_server = ogc_server
group = LayerGroup(u"Demo")
group.children = [layer_borders, layer_density]
theme = Theme(u"Demo")
theme.children = [group]
theme.interfaces = interfaces
transaction.commit()
示例3: main
def main():
parser = argparse.ArgumentParser(
description="This script will rename all the theme elements to removes duplicated elements."
)
parser.add_argument(
'-i', '--iniconfig',
default='production.ini',
help='project .ini config file',
)
parser.add_argument(
'-n', '--app-name',
default="app",
help='The application name (optional, default is "app")',
)
options = parser.parse_args()
# read the configuration
get_app(options.iniconfig, options.app_name)
from c2cgeoportal.models import DBSession, LayerV1, LayerWMS, LayerWMTS, LayerGroup, Theme
for class_ in [LayerV1, LayerWMS, LayerWMTS, LayerGroup, Theme]:
names = []
for item in DBSession.query(class_).all():
if item.name in names:
i = 2
while "{}-{}".format(item.name, i) in names:
i += 1
item.name = "{}-{}".format(item.name, i)
names.append(item.name)
transaction.commit()
示例4: export_talk_preferences
def export_talk_preferences(**kw):
parser = ArgumentParser(description='Export talk preferences to CSV')
parser.add_argument('-c', '--config', type=str, help='app configuration',
default='development.ini')
args = vars(parser.parse_args(**kw))
get_app(args['config']).registry.settings
from .models import TalkPreference
for preference in TalkPreference.query:
print ','.join([str(talk_id) for talk_id in preference.talk_ids])
示例5: add_user
def add_user(**kw):
parser = ArgumentParser(description="Create user account")
parser.add_argument("-c", "--config", type=str, default="production.ini", help="app configuration file")
parser.add_argument("email", type=str, help="email of the user")
parser.add_argument("-f", "--firstname", type=str, help="first name of the user")
parser.add_argument("-l", "--lastname", type=str, help="last name of the user")
parser.add_argument("-p", "--password", type=str, help="password of the user (will be encrypted)")
parser.add_argument("-a", "--active", type=bool, default=True, help="is the user active")
parser.add_argument("-r", "--global_roles", nargs="*", type=str, help="one or more global roles")
data = vars(parser.parse_args(**kw))
get_app(abspath(data.pop("config"))) # setup application
Principal(**data)
commit()
示例6: main
def main(): # pragma: no cover
parser = ArgumentParser(
prog=sys.argv[0], add_help=True,
description="Tool used to migrate your old layers from the old structure to the new one.",
)
parser.add_argument(
"-i", "--app-config",
default="production.ini",
dest="app_config",
help="the application .ini config file (optional, default is 'production.ini')"
)
parser.add_argument(
"-n", "--app-name",
default="app",
dest="app_name",
help="the application name (optional, default is 'app')"
)
options = parser.parse_args()
app_config = options.app_config
app_name = options.app_name
if app_name is None and "#" in app_config:
app_config, app_name = app_config.split("#", 1)
get_app(app_config, name=app_name)
# must be done only once we have loaded the project config
from c2cgeoportal.models import DBSession, \
ServerOGC, LayerWMS, LayerWMTS, LayerV1
session = DBSession()
table_list = [LayerWMTS, LayerWMS, ServerOGC]
for table in table_list:
print "Emptying table %s." % str(table.__table__)
# must be done exactly this way othewise the cascade config in the
# models are not used
for t in session.query(table).all():
session.delete(t)
# list and create all distinct server_ogc
server_ogc(session)
print "Converting layerv1."
for layer in session.query(LayerV1).all():
layer_v1tov2(session, layer)
transaction.commit()
示例7: setUp
def setUp(self):
'''Create the app'''
test_path = os.path.abspath(os.path.dirname(__file__))
testpath_command = "setglobal test_path " + test_path
twill.execute_string(testpath_command)
fixtures = os.path.join(test_path, 'fixtures')
for to_delete in [fname for fname in os.listdir(fixtures)
if fname.startswith('Data.fs') or fname in ['blobs']]:
_rm(os.path.join(fixtures, to_delete))
os.mkdir(os.path.join(fixtures, 'blobs'))
wsgi_app = get_app(os.path.join(test_path, 'fixtures', 'karl.ini'),
'main')
def build_app():
return wsgi_app
twill.add_wsgi_intercept('localhost', 6543, build_app)
# XXX How do we suppress the annoying "AT LINE: " output?
twill.set_output(open('/dev/null', 'wb'))
twill.execute_string("extend_with karl.twillcommands")
# mostly the same as karl3.conf without extending with flunc
# and few other adjustments.
twill.execute_string("runfile '" +
os.path.abspath(os.path.dirname(__file__)) +
"/test_twill_wsgi_karl3.conf'")
示例8: main
def main():
import argparse
parser = argparse.ArgumentParser(
description="Move attachment blobs to S3", epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--app-name', help="Pyramid app name in configfile")
parser.add_argument('--abort', action='store_true', help="Rollback transaction")
parser.add_argument('config_uri', help="path to configfile")
args = parser.parse_args()
logging.basicConfig()
app = get_app(args.config_uri, args.app_name)
# Loading app will have configured from config file. Reconfigure here:
logging.getLogger('encoded').setLevel(logging.DEBUG)
raised = False
try:
run(app)
except:
raised = True
raise
finally:
if raised or args.abort:
transaction.abort()
logger.info('Rolled back.')
else:
transaction.commit()
示例9: main
def main():
''' Indexes app data loaded to elasticsearch '''
import argparse
parser = argparse.ArgumentParser(
description="Index data in Elastic Search", epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--item-type', action='append', help="Item type")
parser.add_argument('--record', default=False, action='store_true', help="Record the xmin in ES meta")
parser.add_argument('--app-name', help="Pyramid app name in configfile")
parser.add_argument('config_uri', help="path to configfile")
args = parser.parse_args()
logging.basicConfig()
options = {
'embed_cache.capacity': '5000',
'indexer': 'true',
'mpindexer': 'true',
}
app = get_app(args.config_uri, args.app_name, options)
# Loading app will have configured from config file. Reconfigure here:
logging.getLogger('encoded').setLevel(logging.DEBUG)
return run(app, args.item_type, args.record)
示例10: setUp
def setUp(self):
"""Launch app using webtest with test settings"""
self.appconf = get_app(test_ini)
self.app = TestApp(self.appconf)
#All auth via BasicAuth - never return the session cookie.
self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[]))
# This sets global var "engine" - in the case of SQLite this is a fresh RAM
# DB each time. If we only did this on class instantiation the database would
# be dirty and one test could influence another.
# TODO - add a test that tests this.
server.choose_engine("SQLite")
# Punch in new user account with direct server call
# This will implicitly generate the tables.
user_id = self.create_user("testuser")
#Here is what the user should look like when inspected
self.user_json = { "name" : "testuser testuser",
"handle" : "[email protected]",
"id" : 1,
"credits" : 0,
"username": "testuser"}
#print("user_id is %s" % str(user_id))
#print("user_from_db_is %s" % server.get_user_id_from_name("testuser"))
server.touch_to_add_password(user_id, "asdf")
# And log in as this user for all tests (via BasicAuth)
# FIXME - switch to token auth to speed up the tests.
self.app.authorization = ('Basic', ('testuser', 'asdf'))
示例11: main
def main():
import argparse
parser = argparse.ArgumentParser(
description="Migrate files to AWS", epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--app-name', help="Pyramid app name in configfile")
parser.add_argument('--abort', action='store_true', help="Rollback transaction")
parser.add_argument('files_processed', type=argparse.FileType('rb'), help="path to json file")
parser.add_argument('config_uri', help="path to configfile")
args = parser.parse_args()
logging.basicConfig()
app = get_app(args.config_uri, args.app_name)
# Loading app will have configured from config file. Reconfigure here:
logging.getLogger('encoded').setLevel(logging.DEBUG)
files_processed = json.load(args.files_processed)
good_files = {v['uuid']: v for v in files_processed
if 'errors' not in v and 'blacklisted' not in v}
raised = False
try:
run(app, good_files)
except:
raised = True
raise
finally:
if raised or args.abort:
transaction.abort()
logger.info('Rolled back.')
else:
transaction.commit()
示例12: fetch_talks
def fetch_talks(**kw):
parser = ArgumentParser(description='Fetch talks from frab')
parser.add_argument('-c', '--config', type=str, help='app configuration',
default='development.ini')
args = vars(parser.parse_args(**kw))
settings = get_app(args['config']).registry.settings
sess = requests.Session()
new_session_page = sess.get(settings['talks_new_session_url'])
tree = etree.HTML(new_session_page.text)
auth_token = tree.xpath("//meta[@name='csrf-token']")[0].get("content")
login_data = dict()
login_data['user[email]'] = settings['talks_user']
login_data['user[password]'] = settings['talks_password']
login_data['user[remember_me]'] = 1
login_data['authenticity_token'] = auth_token
sess.post(settings['talks_login_url'], login_data, verify=False)
talks_json = sess.get(settings['talks_url'], verify=False, stream=True)
talks_full = ''
with open(settings['talks_full'], 'wb') as fd:
for chunk in talks_json.iter_content(1024):
fd.write(chunk)
talks_full += chunk
talks_full = json.loads(talks_full)
talks_filtered = [{ key: x[key] for key in [ 'event_id', 'track_id', 'room_id', 'duration', 'start_time', 'title', 'abstract', 'language', 'speaker_names', 'language' ] } for x in talks_full ]
with open(settings['talks_local'], 'wb') as fd:
json.dump(talks_filtered, fd)
示例13: main
def main():
from pyramid.paster import get_app
from pyramid.scripting import get_root
from ..resources import BlogEntry
parser = OptionParser(description=__doc__, usage='usage: %prog [options]')
parser.add_option('-c', '--config', dest='config',
help='Specify a paster config file.')
parser.add_option('-n', '--name', dest='name', default='main',
help='The paster config file section indicating the app.')
parser.add_option('-i', '--num', dest='num', default='10000',
help='Specify the number of blog entries to add.')
options, args = parser.parse_args()
config = options.config
name = options.name
num = int(options.num)
if config is None:
raise ValueError('must supply config file name')
config = os.path.abspath(os.path.normpath(config))
app = get_app(config, name)
root, closer = get_root(app)
for n in range(0, num):
print ("adding", n)
entry = BlogEntry('title %s' % n, 'entry %s' % n,
'html', datetime.date.today())
id = 'blogentry_%s' % n
root[id] = entry
if n % 10000 == 0:
print ('committing')
transaction.commit()
print ('committing')
transaction.commit()
root._p_jar._db.close()
closer()
示例14: main
def main():
if len(sys.argv) != 3:
sys.exit("Usage: python -m test4.scripts.create_db INI_FILE OUT_FILE")
ini_file = sys.argv[1]
out_path = sys.argv[2]
if os.path.exists(out_path):
raise Exception("%s already exists" % out_path)
logging.config.fileConfig(ini_file)
log = logging.getLogger(__name__)
app = get_app(ini_file, "PersonalGallery")
settings = app.registry.settings
config.config = settings
s = models.DBSession()
if not out_path.endswith(".tar.bz2"):
raise Exception("Only .tar.bz2 archives supported")
out_name = os.path.basename(out_path)
out_name = out_name[:-len(".tar.bz2")]
tmpdir = tempfile.mkdtemp()
try:
q = s.query(Album).filter_by(id = 1)
a = q.one()
backup_album(tmpdir, s, a)
t = tarfile.open(out_path, "w:bz2")
t.add(tmpdir, out_name, recursive = True)
t.close()
finally:
shutil.rmtree(tmpdir)
示例15: main
def main():
parser = argparse.ArgumentParser(
description="Create Elasticsearch mapping on deployment", epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('config_uri', help="path to configfile")
parser.add_argument('--app-name', help="Pyramid app name in configfile")
args = parser.parse_args()
app = get_app(args.config_uri, args.app_name)
# Loading app will have configured from config file. Reconfigure here:
set_logging(in_prod=app.registry.settings.get('production'), level=logging.DEBUG)
# set_logging(app.registry.settings.get('elasticsearch.server'), app.registry.settings.get('production'), level=logging.DEBUG)
# check if staging
try:
data_env = whodaman()
env = app.registry.settings.get('env.name')
if 'webprod' in env:
if data_env != env:
log.info("looks like we are on staging, run create mapping without check first")
run_create_mapping(app, check_first=False)
return
# handle mastertest ... by blowing away all data first
if 'mastertest' in env:
log.info("looks like we are on mastertest, run create mapping without check first")
run_create_mapping(app, check_first=False, purge_queue=True)
return
log.info("looks like we are NOT on staging or mastertest so run create mapping with check first")
except Exception:
import traceback
log.warning("error checking whodaman: %s " % traceback.format_exc())
log.warning("couldn't get wodaman, so assuming NOT staging")
log.info("... using default create mapping case")
run_create_mapping(app, check_first=True, purge_queue=True)