本文整理汇总了Python中pyramid.paster.setup_logging函数的典型用法代码示例。如果您正苦于以下问题:Python setup_logging函数的具体用法?Python setup_logging怎么用?Python setup_logging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setup_logging函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv=sys.argv):
# Usage and configuration
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
config = Configurator(settings=settings)
config.include('pyramid_sqlalchemy')
# Make the database with schema and default data
with transaction.manager:
metadata.create_all()
root = RootFolder(name='',
title='Moonbase Demo',
__acl__=[
['Allow', ['paul'], 'view']
]
)
Session.add(root)
f1 = root['f1'] = Folder(
title='Folder 1',
__acl__=[
['Allow', ['shane'], 'view']
]
)
f1['da'] = Document(title='Document 1A')
示例2: main
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
mkdir(settings['static_files'])
# Create Ziggurat tables
alembic_ini_file = 'alembic.ini'
if not os.path.exists(alembic_ini_file):
alembic_ini = ALEMBIC_CONF.replace('{{db_url}}',
settings['sqlalchemy.url'])
f = open(alembic_ini_file, 'w')
f.write(alembic_ini)
f.close()
bin_path = os.path.split(sys.executable)[0]
alembic_bin = os.path.join(bin_path, 'alembic')
command = '%s upgrade head' % alembic_bin
os.system(command)
os.remove(alembic_ini_file)
# Insert data
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
init_model()
create_schemas(engine)
Base.metadata.create_all(engine)
initial_data.insert()
transaction.commit()
示例3: bootstrap_script
def bootstrap_script(argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
return settings
示例4: 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()
示例5: main
def main(argv=sys.argv):
global logger, settings, ca, ri, aws_access, aws_secret, thekey
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
# TODO: need to add settings to define where the files will be
logger = logging.getLogger('scripts')
# make configurable?
site_blacklist = set(['MedPass', 'Bridge'])
print "# Stack to site info generated by build_ini_info script"
stackmap = tools.parse_sites()
for stack, sites in stackmap.items():
clean = set(sites) - site_blacklist
print "stacks.%s = %s" % (stack, ', '.join(clean))
print "# RDS to site info generated by build_ini_info script"
rdsmap = tools.parse_rds()
# dbs.a4.gentivalink = a4-css-sup-cleanup-rds
for stack, sites in rdsmap.items():
for site, rdses in sites.items():
for rds in rdses:
print "dbs.%s.%s = %s" % (stack, site, rds)
示例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.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)
示例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, name="testscaffold", options=options)
engine = get_engine(settings)
session_factory = get_session_factory(engine)
dbsession = get_tm_session(session_factory, transaction.manager)
with transaction.manager:
user = User(user_name="admin", email="[email protected]")
UserService.set_password(user, "admin")
admin_object = Group(group_name="Administrators")
group_permission = GroupPermission(perm_name="root_administration")
dbsession.add(admin_object)
admin_object.permissions.append(group_permission)
admin_object.users.append(user)
test_group = Group(group_name="Other group")
dbsession.add(test_group)
for x in range(1, 25):
user = User(user_name="test{}".format(x), email="foo{}@localhost".format(x))
UserService.set_password(user, "test")
test_group.users.append(user)
示例8: __call__
def __call__(self, argv=sys.argv):
self.configure_parser()
args = self.parser.parse_args(argv[1:])
if self.requires_config:
self.config_uri = args.config_uri
setup_logging(self.config_uri)
self.run(args)
示例9: main
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.', echo=False)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
# populate databases
with transaction.manager:
print('\ninit_setpoint_interpolations:\n')
init_setpoint_interpolations(DBSession)
print('\ninit_parameter_types:\n')
init_parameter_types(DBSession)
print('\ninit_device_types:\n')
init_device_types(DBSession)
print('\ninit_periphery_controllers:\n')
DBSession.flush()
init_periphery_controllers(DBSession)
DBSession.flush()
print('\ninit_parameters:\n')
init_parameters(DBSession)
print('\ninit_devices:\n')
init_devices(DBSession)
print('\ninit_field_settings:\n')
init_field_settings(DBSession)
print('\ninit_regulators:\n')
DBSession.flush()
init_regulators(DBSession)
init_log_diagrams(DBSession)
示例10: main
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, "sqlalchemy.")
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
user = User()
user.set_password("wolfvo8491")
user.user_name = "wolfv"
user.email = "[email protected]"
user.status = 1 # Not verified yet
DBSession.add(user)
with transaction.manager:
user = User()
user.user_name = "wolf"
user.email = "[email protected]"
user.set_password("wolf")
user.status = 1
DBSession.add(user)
user = User()
user.user_name = "peter"
user.email = "[email protected]"
user.set_password("p")
user.status = 1
DBSession.add(user)
示例11: main
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
if config_uri not in ["jenkins.ini"]:
print "You are not initialising using a testing URI"
print "Edit init_testingdb.py if you really want to do this"
sys.exit(0)
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, "sqlalchemy.")
meta.Session.configure(bind=engine)
Base.metadata.bind = engine
# Create Everythin
print "Dropping Tables"
Base.metadata.drop_all(engine)
print "Creating Tables"
Base.metadata.create_all(engine)
# We also want any alembic scripts to be executed
alembic_cfg = Config(config_uri) # TODO: WARNING RELATIVE PATH
command.stamp(alembic_cfg, "head")
DBSession = meta.Session()
# DBSession.configure(bind=engine)
populateData.init_data(DBSession)
populateUser()
populatedata()
示例12: listuserinfo
def listuserinfo():
arguments = listuserparser.parse_args()
if not arguments.config or not arguments.username:
listuserparser.print_usage()
else:
config_uri = arguments.config
setup_logging(config_uri)
try:
settings = get_appsettings(config_uri, 'factored')
except LookupError:
settings = get_appsettings(config_uri, 'main')
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session = DBSession()
users = session.query(User).filter_by(
username=arguments.username).all()
if len(users) > 0:
user = users[0]
print 'username:%s, secret: %s' % (
user.username, user.secret)
print 'bar code url:', get_barcode_image(user.username,
user.secret,
settings['appname'])
else:
print '"%s" user not found' % arguments.username
示例13: main
def main(argv=sys.argv): #pragma NOCOVER
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
password = hashlib.md5('secret'.encode()).hexdigest()
user = User(name='distractionbike', password_md5=password)
DBSession.add(user)
user2 = User(name='otherguy', password_md5=password)
DBSession.add(user2)
journal = Journal(name='distractionbike')
DBSession.add(journal)
post = Post(journal_name='distractionbike',
title='First Post',
lede='Why do we love first posts so much?',
text='This is the <i>very first post</i>.')
DBSession.add(post)
post.add_comment(text='Yay!', user_id='ezra')
示例14: 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)
#Delete old data
Base.metadata.drop_all(engine)
#Create data
Base.metadata.create_all(engine)
with transaction.manager:
nb_sensors = 5
nb_readings = 500
minutes_between_readings = 10;
for i in range(nb_sensors):
sensor = Sensor(id=i+1,type='Moisture')
DBSession.add(sensor)
first_dttm = datetime.datetime.now()
for j in range(nb_readings,0,-1):
reading = Reading(
sensor_id=sensor.id,
timestamp=first_dttm - datetime.timedelta(minutes=minutes_between_readings*j),
value=random.randrange(1023)
)
DBSession.add(reading)
示例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)