本文整理匯總了Python中pyramid.scripts.common.parse_vars方法的典型用法代碼示例。如果您正苦於以下問題:Python common.parse_vars方法的具體用法?Python common.parse_vars怎麽用?Python common.parse_vars使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyramid.scripts.common
的用法示例。
在下文中一共展示了common.parse_vars方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
model = MyModel(name='one', value=1)
dbsession.add(model)
示例2: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
# model = MyModel(name='one', value=1)
# dbsession.add(model)
示例3: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
model = Customer(name='sample',
email='[email protected]',
contract_type='One Time',
customer_type='Direct')
dbsession.add(model)
示例4: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
def main(argv=sys.argv):
"""Initialize database, optionally with settings from config uri."""
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)
if not settings.get('sqlalchemy.url'):
try:
settings['sqlalchemy.url'] = os.environ['MARS_DATABASE_URL']
except KeyError:
print('Required MARS_DATABASE_URL not set in global os environ.')
sys.exit()
try:
settings['nasa_api_key'] = os.environ['NASA_API_KEY']
except KeyError:
print('Required NASA_API_KEY not set in global os environment.')
sys.exit()
populate_rovers_cameras()
示例5: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
def main(argv=sys.argv):
if len(argv) < 4:
usage(argv)
username = argv[1]
password = argv[2]
config_uri = argv[3]
options = parse_vars(argv[4:])
setup_logging(config_uri)
settings = get_appsettings(config_uri)
settings.update(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)
user = User(name=username, role='editor')
user.set_password(password)
dbsession.add(user)
示例6: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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.drop_all(engine)
Base.metadata.create_all(engine)
session_factory = get_session_factory(engine)
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
示例7: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
示例8: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
settings['sqlalchemy.url'] = os.environ.get('DATABASE_URL')
engine = get_engine(settings)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
session_factory = get_session_factory(engine)
tweet_list = []
models = []
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
HERE = os.path.dirname(__file__)
with open(os.path.join(HERE, '../models/realdonaldtrump_short.json'), 'r', encoding='utf-8') as json_file:
json_data = json.load(json_file)
for tweet_item in json_data:
one_tweet = html.unescape(tweet_item['text'])
new_tweet = Tweet(
tweet=one_tweet
)
models.append(new_tweet)
tweet_list.append(one_tweet)
# fourgrams(tweet_list)
dbsession.add_all(models)
# gen_markov()
示例9: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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:
DBSession.execute("ALTER TABLE users MODIFY id INT AUTO_INCREMENT")
model = User(first_name='Bruce', last_name='Wayne',
created_at=datetime.datetime.now())
DBSession.add(model)
示例10: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
示例11: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = dict()
options.update(defaults)
options.update(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)
with open(settings['default.users']) as f:
users = []
for i, line in enumerate(f):
line = line.strip().split(',')
if i == 0:
header = line
continue
u = {k: v for k, v in zip(header, line)}
users.append(u)
added = 0
for u in users:
name = u['name']
if dbsession.query(User).filter_by(name=name).count() == 0:
new_user = User(name=name, role='editor')
new_user.set_password(u['password'])
dbsession.add(new_user)
added += 1
print("Added {} users. Skipped {}.".format(added, len(users) - added))
示例12: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
settings["sqlalchemy.url"] = os.environ["DATABASE_URL"]
engine = get_engine(settings)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
session_factory = get_session_factory(engine)
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
model = Job(
city='Seattle',
title='Windows UWP/Phone Developer, Seattle WA',
company='Interloc Solutions',
description="""Our Products & Technology group in Seattle has an immediate need for an experienced Windows developer (Windows 10/Windows Surface) to support our Informer mobile solution products. This position will contribute heavily to product builds, so prior mobile application development experience is essential. Experience with Windows 10/Windows Surface 3+ years demonstrated experience in .NET and C# development Strong knowledge of the .NET framework, C#, with component extensions Prior mobile application development SQLite (highly desired, but not required) Full SDLC experience, including release to operations and production This is a great opportunity to work with our progressive mobile team!""",
url="www.interlocsolutions.com",
language='C#'
)
dbsession.add(model)
示例13: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
示例14: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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)
init_social(get_settings(app_settings), Base, DBSession)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
示例15: main
# 需要導入模塊: from pyramid.scripts import common [as 別名]
# 或者: from pyramid.scripts.common import parse_vars [as 別名]
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.drop_all(engine)
Base.metadata.create_all(engine)
# EVERYTHING BEFORE THIS POINT IS NEEDED TO SET UP YOUR TABLES
# ============ NOTHING AFTER THIS POINT IS NECESSARY AT ALL =========
session_factory = get_session_factory(engine)
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
expense = Expense(
title='Really Expensive Pizza',
price=5000,
paid_date=datetime.datetime.now(),
description="I know it's expensive, but dammit I want gold shavings on my pizza"
)
dbsession.add(expense)