本文整理汇总了Python中anyblok.blok.BlokManager类的典型用法代码示例。如果您正苦于以下问题:Python BlokManager类的具体用法?Python BlokManager怎么用?Python BlokManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlokManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createdb
def createdb(application, configuration_groups, **kwargs):
""" Create a database and install blok from config
:param application: name of the application
:param configuration_groups: list configuration groupe to load
:param \**kwargs: ArgumentParser named arguments
"""
format_configuration(configuration_groups,
'create_db', 'install-bloks',
'install-or-update-bloks')
load_init_function_from_entry_points()
Configuration.load(application, configuration_groups=configuration_groups,
**kwargs)
BlokManager.load()
db_name = Configuration.get('db_name')
db_template_name = Configuration.get('db_template_name', None)
url = Configuration.get('get_url')(db_name=db_name)
create_database(url, template=db_template_name)
registry = RegistryManager.get(db_name)
if registry is None:
return
if Configuration.get('install_all_bloks'):
bloks = registry.System.Blok.list_by_state('uninstalled')
else:
install_bloks = Configuration.get('install_bloks') or []
iou_bloks = Configuration.get('install_or_update_bloks') or []
bloks = list(set(install_bloks + iou_bloks))
registry.upgrade(install=bloks)
registry.commit()
registry.close()
示例2: anyblok_createdb
def anyblok_createdb():
"""Create a database and install blok from config"""
load_init_function_from_entry_points()
Configuration.load('createdb')
configuration_post_load()
BlokManager.load()
db_name = get_db_name()
db_template_name = Configuration.get('db_template_name', None)
url = Configuration.get('get_url')(db_name=db_name)
create_database(url, template=db_template_name)
registry = RegistryManager.get(db_name)
if registry is None:
return
if Configuration.get('install_all_bloks'):
bloks = registry.System.Blok.list_by_state('uninstalled')
else:
install_bloks = Configuration.get('install_bloks') or []
iou_bloks = Configuration.get('install_or_update_bloks') or []
bloks = list(set(install_bloks + iou_bloks))
registry.upgrade(install=bloks)
registry.commit()
registry.close()
示例3: test_get_invalid_blok
def test_get_invalid_blok(self):
try:
BlokManager.load()
BlokManager.get('invalid blok')
self.fail('No exception when get invalid blok')
except BlokManagerException:
pass
示例4: load
def load(self):
BlokManager.load()
preload_databases()
config = Configurator()
config.include_from_entry_point()
config.load_config_bloks()
return config.make_wsgi_app()
示例5: anyblok_wsgi
def anyblok_wsgi(application, configuration_groups, **kwargs):
"""
:param application: name of the application
:param configuration_groups: list configuration groupe to load
:param \**kwargs: ArgumentParser named arguments
"""
format_configuration(configuration_groups, 'preload', 'pyramid-debug',
'wsgi')
load_init_function_from_entry_points()
Configuration.load(application,
configuration_groups=configuration_groups, **kwargs)
BlokManager.load()
config = Configurator()
config.include_from_entry_point()
config.load_config_bloks()
wsgi_host = Configuration.get('wsgi_host')
wsgi_port = int(Configuration.get('wsgi_port'))
app = config.make_wsgi_app()
server = make_server(wsgi_host, wsgi_port, app)
preload_databases()
logger.info("Serve forever on %r:%r" % (wsgi_host, wsgi_port))
server.serve_forever()
示例6: load_registry
def load_registry(self):
if self.enabled and self.registryLoaded is False:
# Load the registry here not in configuration,
# because the configuration are not load in order of score
self.registryLoaded = True
BlokManager.load()
load_init_function_from_entry_points(unittest=True)
Configuration.load_config_for_test()
Configuration.parse_options(self.AnyBlokOptions, ('bloks',))
db_name = Configuration.get('db_name')
if not db_name:
raise Exception("No database defined to run Test")
registry = RegistryManager.get(db_name)
if registry:
installed_bloks = registry.System.Blok.list_by_state(
"installed")
selected_bloks = Configuration.get('selected_bloks')
if not selected_bloks:
selected_bloks = installed_bloks
unwanted_bloks = Configuration.get('unwanted_bloks')
if unwanted_bloks is None:
unwanted_bloks = []
self.bloks_path = [BlokManager.getPath(x)
for x in BlokManager.ordered_bloks]
self.authoried_bloks_test_files = [
path for blok in installed_bloks
if blok in selected_bloks and blok not in unwanted_bloks
for path in [join(BlokManager.getPath(blok), 'tests')]
if exists(path)]
registry.close() # free the registry to force create it again
示例7: setUp
def setUp(self):
super(TestBlok, self).setUp()
self.__class__.init_configuration_manager()
self.__class__.createdb(keep_existing=False)
BlokManager.load(entry_points=('bloks', 'test_bloks'))
registry = RegistryManager.get(Configuration.get('db_name'))
registry.commit()
registry.close()
示例8: test_set_two_time
def test_set_two_time(self):
blok_name = 'ABlok'
BlokManager.set(blok_name, Blok)
try:
BlokManager.set(blok_name, Blok)
self.fail("No watch dog for set two time the same blok")
except BlokManagerException:
pass
示例9: tearDown
def tearDown(self):
""" Clear the registry, unload the blok manager and drop the database
"""
if self.registry:
self.registry.close()
RegistryManager.clear()
BlokManager.unload()
super(DBTestCase, self).tearDown()
示例10: tearDown
def tearDown(self):
""" Clear the registry, unload the blok manager and drop the database
"""
registry = RegistryManager.get(Configuration.get('db_name'))
registry.close()
RegistryManager.clear()
BlokManager.unload()
clear_mappers()
self.__class__.dropdb()
super(TestBlok, self).tearDown()
示例11: test_reload
def test_reload(self):
BlokManager.load()
BlokManager.set('invalid blok', None)
BlokManager.get('invalid blok')
BlokManager.reload()
try:
BlokManager.get('invalid blok')
self.fail("Reload classmethod doesn't reload the bloks")
except BlokManagerException:
pass
示例12: setUpClass
def setUpClass(cls):
""" Intialialise the configuration manager """
super(DBTestCase, cls).setUpClass()
cls.init_configuration_manager()
if cls.createdb(keep_existing=True):
BlokManager.load(entry_points=('bloks', 'test_bloks'))
registry = cls.getRegistry()
registry.commit()
registry.close()
BlokManager.unload()
示例13: test_start_function
def test_start_function(self):
BlokManager.unload()
db_name = Configuration.get('db_name') or 'test_anyblok'
db_driver_name = Configuration.get('db_driver_name') or 'postgresql'
testargs = ['default', '--db-name', db_name, '--db-driver-name',
db_driver_name]
with patch.object(sys, 'argv', testargs):
registry = start('default')
self.assertIsNotNone(registry)
示例14: get_logo
def get_logo(self):
"""fget of ``logo`` return the path in the blok of the logo
:rtype: absolute path or None if unexiste logo
"""
blok = BlokManager.get(self.name)
blok_path = BlokManager.getPath(blok.name)
file_path = join(blok_path, blok.logo)
if isfile(file_path):
return file_path
return None
示例15: get_templates_from
def get_templates_from(attr):
tmpl = Template(forclient=True)
for blok_name in BlokManager.ordered_bloks:
blok = BlokManager.get(blok_name)
if hasattr(blok, attr):
bpath = BlokManager.getPath(blok_name)
for template in getattr(blok, attr):
with open(join(bpath, template), 'r') as fp:
tmpl.load_file(fp)
tmpl.compile()
return tmpl.get_all_template()