本文整理汇总了Python中pyramid.scripts.common.parse_vars函数的典型用法代码示例。如果您正苦于以下问题:Python parse_vars函数的具体用法?Python parse_vars怎么用?Python parse_vars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_vars函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
model = Task(taskname='Learn 101 of telekinesis', status=False)
DBSession.add(model)
model = Task(taskname='Bend 20 forks', status=True)
DBSession.add(model)
model = Task(taskname='Become master in levitation', status=True)
DBSession.add(model)
model = Task(taskname='Go home flying', status=True)
DBSession.add(model)
with transaction.manager:
admin = User(name=u'admin', password=u'admin')
DBSession.add(admin)
admin = User(name=u'demo', password=u'demo')
DBSession.add(admin)
示例2: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
#with transaction.manager:
# model = MyModel(name='one', value=1)
# DBSession.add(model)
with transaction.manager:
with open('agencies.csv','r') as f:
agencies = f.read().split('\n')
for agency in agencies:
if agency.strip() != '':
# agencyid, shortname, longname, type, description, websiteurl
parts = agency.split('\t')
agency_type = AgencyTypes.get_from_code(DBSession, parts[3])
a = Agencies(
agency_code = parts[1],
agency_name = parts[2],
type_id = agency_type.id,
description = parts[4],
website = parts[5],
)
DBSession.add(a)
transaction.commit()
示例3: run
def run(self):
if len(self.args) < 2:
self.out('Command requires a config file arg and a url arg')
return 2
config_uri = self.args[0]
url = self.args[1]
if not url.startswith('/'):
url = '/%s' % url
request = Request.blank(url)
env = self.bootstrap[0](config_uri, options=parse_vars(self.args[2:]),
request=request)
view = self._find_view(request)
self.out('')
self.out("URL = %s" % url)
self.out('')
if view is not None:
self.out(" context: %s" % view.__request_attrs__['context'])
self.out(" view name: %s" % view.__request_attrs__['view_name'])
if IMultiView.providedBy(view):
for dummy, view_wrapper, dummy in view.views:
self.output_view_info(view_wrapper)
if IMultiView.providedBy(view_wrapper):
for dummy, mv_view_wrapper, dummy in view_wrapper.views:
self.output_view_info(mv_view_wrapper, level=2)
else:
if view is not None:
self.output_view_info(view)
else:
self.out(" Not found.")
self.out('')
env['closer']()
return 0
示例4: get_options
def get_options(self):
if len(self.args) > 1 and self.args[1] in self.possible_subcommands:
restvars = self.args[2:]
else:
restvars = self.args[1:]
return parse_vars(restvars)
示例5: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
with transaction.manager:
model2 = Genre(id = 0,name='HipHop', info='Nigger ma fucker',year_of_found = 1990)
DBSession.add(model2)
model = Genre(id = 1,name='GlitchHop', info='Nu vaaassheee',year_of_found = 2014, parent_genre = model2)
DBSession.add(model)
model3 = Genre(id = 2,name='Grime', info='Zhostkiy rap',year_of_found = 2006, parent_genre = model2)
DBSession.add(model3)
model4 = Genre(id = 3,name='Dark Grime', info='Tyomniy Zhostkiy rap',year_of_found = 2009, parent_genre = model3)
DBSession.add(model4)
music1 = Music(author = 'Simplex_Method', title = 'Of Literal Data', year = 2015,genre = model3)
DBSession.add(music1)
示例6: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
application_pdf_doc_type = DocumentTypes.add(
name="Adobe PDF",
description="Adobe PDF file",
mime_type="application/pdf",
)
system_owner = Users.add(
first="SYSTEM",
last="USERS",
email="[email protected]",
password="password",
)
default_scraper = Scrapers.add(
name="Default Scraper",
description="CivicDocs.IO loads with a single, defualt scraper.",
owner_id=system_owner.id,
)
print("DEFAULT SCRAPER ID:\r\n{0}\r\n".format(default_scraper.id))
示例7: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
with transaction.manager:
user = User(username='admin', password='apass', email=settings.get('admin_mail'), activated=True,
groups='admin')
DBSession.add(user)
DBSession.flush()
for k, v in Settings.settings.iteritems():
if type(v) == dict:
DBSession.add(Settings(key=unicode(k), value=unicode(v['value'])))
else:
if isinstance(v, basestring) and v.startswith('app_config.'):
v = settings.get(v[len('app_config.'):])
DBSession.add(Settings(key=unicode(k), value=unicode(v)))
DBSession.flush()
示例8: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
#model = MyModel(name='one', value=1)
#DBSession.add(model)
megan_user = Users.create_user(
session = DBSession,
username = 'megan',
password = 'password',
name = 'Megan',
)
DBSession.add(megan_user)
tim_user = Users.create_user(
session = DBSession,
username = 'tim',
password = 'password',
name = 'Tim',
)
DBSession.add(tim_user)
transaction.commit()
示例9: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = get_engine(settings)
dbmaker = get_dbmaker(engine)
dbsession = get_session(transaction.manager, dbmaker)
Base.metadata.create_all(engine)
acl1 = [(Allow, Everyone, "view")]
acl2 = [(Allow, "editor", "view")]
acl3 = [(Allow, "admin", "view")]
with transaction.manager:
root = RootFolder(name="", title="sqltraversal Demo")
dbsession.add(root)
f1 = root["f1"] = Folder(
title="Folder 1"
# no persistent acl
)
root["f2"] = Folder(title="Folder 2 All", acl=acl1)
root["f3"] = Folder(title="Folder 3 Editor", acl=acl2)
root["f4"] = Folder(title="Folder 4 Admin", acl=acl3)
root["f5"] = Folder(title="Folder 5 Editor", acl=acl2)
root["f6"] = Folder(title="Folder 6 Admin", acl=acl3)
f1["d1"] = Document(title="Document 1")
示例10: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
#model = MyModel(name='one', value=1)
#DBSession.add(model)
perm_item_manage = Permission()
perm_item_manage.name = 'item'
DBSession.add(perm_item_manage)
perm_user_manage = Permission()
perm_user_manage.name = 'user'
DBSession.add(perm_user_manage)
perm_order_manage = Permission()
perm_order_manage.name = 'order'
DBSession.add(perm_order_manage)
gadmin = Group()
gadmin.name = 'Administrators'
gadmin.permissions.append(perm_item_manage)
gadmin.permissions.append(perm_order_manage)
gadmin.permissions.append(perm_user_manage)
DBSession.add(gadmin)
admin = User()
admin.name = 'admin'
admin.password = 'admin'
admin.email = '[email protected]'
admin.group = gadmin
DBSession.add(admin)
cat_food = Category()
cat_food.name = 'Food'
DBSession.add(cat_food)
cat_fruit = Category()
cat_fruit.name = 'Fruit'
cat_fruit.parent = cat_food
DBSession.add(cat_fruit)
cat_vegetable = Category()
cat_vegetable.name = 'Vegetable'
cat_vegetable.parent = cat_food
DBSession.add(cat_vegetable)
iapple = Item()
iapple.name = 'Apple'
iapple.description = '<h2>This is a <span style="color:red;">red</span> apple</h2>'
iapple.price = 1.3
iapple.category = cat_fruit
DBSession.add(iapple)
示例11: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
# configure connections for Postgres, ElasticSearch and Redis
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
Session = sessionmaker() # noqa
Session.configure(bind=engine)
configure_es_from_config(settings)
queue_config = get_queue_config(settings)
batch_size = int(settings.get('elasticsearch.batch_size.syncer', 1000))
with queue_config.connection:
try:
worker = SyncWorker(
queue_config.connection, queue_config.queue, batch_size,
session_factory=Session)
log.info('Syncer started, running initial sync')
worker.sync()
log.info('Waiting on messages')
worker.run()
except KeyboardInterrupt:
log.info('Syncer stopped')
示例12: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
#Generate fake statistics for 1 year
DAYS = 365 * 1
#Init database with example list of cities
with transaction.manager:
for c in CITIES:
city = City(name=c, owm_id=CITIES[c])
DBSession.add(city)
DBSession.flush()
print("Added city: " + city.name)
prev_y = datetime.datetime.now() - datetime.timedelta(DAYS)
for d in (prev_y + datetime.timedelta(n) for n in range(DAYS)):
is_clear = bool(random.getrandbits(1))
wr = WeatherRecord(city=city.id, date=d, is_clear=is_clear)
DBSession.add(wr)
print("Added weather record: " + str(wr.date) + " " + str(wr.is_clear))
DBSession.flush()
示例13: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = get_engine(settings)
Base.metadata.create_all(engine)
session_factory = get_session_factory(engine)
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
submitter = Submitter(name='tester')
dbsession.add(submitter)
transaction.commit()
sub_id = dbsession.query(Submitter.id). \
filter(Submitter.name == 'tester').scalar()
post = Post(title="job title",
company="the testing company",
post_date="13-Apr-2016Z201530",
description="this is a really short description",
submitter=sub_id)
dbsession.add(post)
示例14: main
def main(argv=sys.argv):
from ..src import User, Address
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
Session.configure(bind=engine)
BaseModel.metadata.create_all(engine)
with transaction.manager:
brendan = User(name='Brendan', age=18)
Session.add(brendan)
Session.flush()
brendan_address = Address(city='Paris', owner_id=brendan.id)
Session.add(brendan_address)
Session.flush()
john = User(name='John', age=19, best_friend_id=brendan.id)
Session.add(john)
Session.flush()
antoine = User(name='Antoine', age=20)
Session.add(antoine)
Session.flush()
示例15: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
connect_string = settings['sqlalchemy.url']\
.replace('DBUser', os.environ['DBUSER'])\
.replace('DBPassword', os.environ['DBPASSWORD'])
settings['sqlalchemy.url'] = connect_string
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
store_data = json.loads(open('emporium/scripts/store_data.json').
read())
suppliers = {}
for item in store_data['suppliers']:
supplier = Supplier(name=item['name'], tax_id=item['tax_id'])
suppliers[supplier.name] = supplier
DBSession.add(supplier)
for item in store_data['bargains']:
bargain = Bargain(
sku=item['sku'],
price=item['price'],
supplier=suppliers[item['supplier_name']]
)
bargain.info = item['info']
DBSession.add(bargain)