def test_add_application_properties_and_load_it(self): Configuration.add_application_properties( 'test_add_application_properties', ['logging']) parser = MockArgumentParser() # add twice to check doublon Configuration.add('logging', function_=add_logging, label='Logging') Configuration.add('logging', function_=add_logging, label='Logging') Configuration.add('database', function_=add_database, label='Database') Configuration.add('config', function_=add_configuration_file) Configuration.add('install-bloks', function_=add_install_bloks) Configuration._load(parser, ['config', 'database', 'logging'])
def test_add_application_properties_and_load_it(self): Configuration.add_application_properties( 'test_add_application_properties', ['logging']) parser = MockArgumentParser() # add twice to check doublon Configuration.add('logging', function_=add_logging, label='Logging') Configuration.add('logging', function_=add_logging, label='Logging') Configuration.add('database', function_=add_database, label='Database') Configuration.add('config', function_=add_configuration_file) Configuration.add('install-bloks', function_=add_install_bloks) Configuration._load(parser, ['config', 'database', 'logging'])
def test_add_application_properties(self): self.assertIsNone( Configuration.applications.get('test_add_application_properties')) Configuration.add_application_properties( 'test_add_application_properties', ['logging'], description='Just a test') self.assertIsNotNone( Configuration.applications.get('test_add_application_properties')) self.assertEqual( Configuration.applications['test_add_application_properties'], { 'configuration_groups': ['config', 'database', 'logging'], 'description': 'Just a test' })
def test_add_application_properties(self): self.assertIsNone( Configuration.applications.get('test_add_application_properties')) Configuration.add_application_properties( 'test_add_application_properties', ['logging'], description='Just a test') self.assertIsNotNone( Configuration.applications.get('test_add_application_properties')) self.assertEqual( Configuration.applications['test_add_application_properties'], { 'configuration_groups': ['config', 'database', 'logging'], 'description': 'Just a test' })
def test_add_application_properties(self): assert Configuration.applications.get( 'test_add_application_properties') is None Configuration.add_application_properties( 'test_add_application_properties', ['logging'], description='Just a test') assert Configuration.applications.get( 'test_add_application_properties') is not None assert ( Configuration.applications['test_add_application_properties'] == { 'configuration_groups': ['config', 'database', 'plugins', 'logging'], 'description': 'Just a test' })
# This file is a part of the AnyBlok / Pyramid project # # Copyright (C) 2016 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration, AnyBlokPlugin, get_db_name as gdb from .release import version import os Configuration.add_application_properties( 'pyramid', ['logging', 'pyramid-debug', 'wsgi', 'auth', 'preload'], prog='AnyBlok simple wsgi app, version %r' % version, description="WSGI for test your AnyBlok / Pyramid app", ) Configuration.add_application_properties( 'gunicorn', [], prog='AnyBlok simple wsgi app, version %r' % version, description="WSGI for test your AnyBlok / Pyramid app", configuration_groups=['logging', 'pyramid-debug', 'auth', 'preload', 'gunicorn', 'database'], ) Configuration.add_application_properties('nose', ['auth']) def get_db_name(request): return gdb()
from anyblok.config import Configuration from anyblok.registry import RegistryManager from anyblok import load_init_function_from_entry_points from dramatiq import Worker from .broker import prepare_broker import signal import time from logging import getLogger from .release import version logger = getLogger(__name__) Configuration.add_application_properties( 'dramatiq', ['dramatiq-broker', 'dramatiq-consumer', 'logging'], prog='Dramatiq app for AnyBlok, version %r' % version, description='Distributed actor for AnyBlok' ) def worker_process(worker_id, logging_fd): """consume worker to process messages and execute the actor""" # TODO preload registries db_name = Configuration.get('db_name') try: logging_pipe = os.fdopen(logging_fd, "w") broker = prepare_broker(withmiddleware=True) broker.emit_after("process_boot") BlokManager.load() registry = RegistryManager.get(db_name, loadwithoutmigration=True) if registry is None:
# This file is a part of the AnyBlok / FuretUI project # # Copyright (C) 2020 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from .release import version Configuration.add_application_properties( 'furetui-user', ['logging', 'furetui_user'], prog='Add user or update password, version %r' % version, description="User manager", ) Configuration.add_application_properties( 'export-i18n', ['logging', 'export-i18n'], prog='Export POT file of a module, version %r' % version, description="Export i18n POT file", ) @Configuration.add('furetui_user', label="User management for FuretUI") def define_wsgi_option(group): group.add_argument('--furetui-user-login') group.add_argument('--furetui-user-password') group.add_argument('--furetui-user-roles', nargs="+")
from os.path import join from logging import getLogger from os import walk from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) logger = getLogger(__name__) Configuration.add_application_properties( 'createdb', [ 'unittest', 'logging', 'create_db', 'install-bloks', 'install-or-update-bloks', ], prog='AnyBlok create database, version %r' % version, description="Create a database and install bloks to populate it" ) Configuration.add_application_properties( 'updatedb', [ 'unittest', 'logging', 'install-bloks', 'uninstall-bloks', 'update-bloks', 'install-or-update-bloks',
from os.path import join from os import walk from argparse import RawDescriptionHelpFormatter from textwrap import dedent from sqlalchemy_utils.functions import create_database from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) Configuration.add_application_properties( 'createdb', [ 'unittest', 'logging', 'create_db', 'install-bloks', 'install-or-update-bloks', ], prog='AnyBlok create database, version %r' % version, description="Create a database and install bloks to populate it" ) Configuration.add_application_properties( 'updatedb', [ 'unittest', 'logging', 'install-bloks', 'uninstall-bloks', 'update-bloks', 'install-or-update-bloks',
# # Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. import anyblok from anyblok.blok import BlokManager from anyblok.registry import RegistryManager from anyblok.config import Configuration, get_url from logging import getLogger from sqlalchemy_utils.functions import database_exists, create_database logger = getLogger(__name__) Configuration.add_application_properties( 'update-project', ['logging'], prog='AnyBlok update project, version') def update_project(): anyblok.load_init_function_from_entry_points() Configuration.load('update-project') anyblok.configuration_post_load() BlokManager.load() db_name = Configuration.get('db_name') logger.info("update project: db_name=%r", db_name) to_install = [] to_update = [] to_uninstall = [] url = get_url()
# This file is a part of the AnyBlok / Attachment api project # # Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration Configuration.add_application_properties('createdb', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('updatedb', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('nose', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('interpreter', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('pyramid', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('gunicorn', ['attachment-wkhtml2pdf']) Configuration.add_application_properties('dramatiq', ['attachment-wkhtml2pdf']) @Configuration.add('attachment-wkhtml2pdf', label="WkHtml2Pdf - options", must_be_loaded_by_unittest=True) def define_attachment_wkhtml2pdf(group): group.add_argument('--wkhtml2pdf-unquiet', action="store_false", default=True, help="Be more verbose") group.add_argument('--wkhtml2pdf-debug-javascript', action="store_true",
import signal import time from anyblok import load_init_function_from_entry_points from anyblok.config import Configuration from anyblok.blok import BlokManager from anyblok.registry import RegistryManager from .worker import Worker from .release import version from logging import getLogger logger = getLogger(__name__) Configuration.add_application_properties( 'bus', ['logging', 'bus'], prog='Bus app for AnyBlok, version %r' % version, description='Bus for AnyBlok', ) def bus_worker_process(worker_id, logging_fd): """consume worker to process messages and execute the actor""" # TODO preload registries db_name = Configuration.get('db_name') profile = Configuration.get('bus_profile') try: logging_pipe = os.fdopen(logging_fd, "w") BlokManager.load() registry = RegistryManager.get(db_name, loadwithoutmigration=True) if registry is None: logger.critical("No registry found for %s", db_name)
# This file is a part of the AnyBlok / Pyramid / Beaker project # # Copyright (C) 2016 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from anyblok_pyramid import config # noqa for update config Configuration.add_application_properties('pyramid', ['beaker']) Configuration.add_application_properties('gunicorn', ['beaker']) def get_db_name(request): dbname = request.session.get('dbname') if not dbname: dbname = Configuration.get('db_name') return dbname @Configuration.add('beaker', label="Beaker session") def define_beaker_option(group): group.add_argument('--beaker-data-dir', dest='beaker.session.data_dir', help="Used with any back-end that stores its data in " "physical files, such as the dbm or file-based " "back-ends. This path should be an absolute path "
# This file is a part of the AnyBlok / Pyramid project # # Copyright (C) 2016 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration, AnyBlokPlugin, get_db_name as gdb from .release import version import os Configuration.add_application_properties( 'pyramid', ['logging', 'pyramid-debug', 'wsgi', 'auth', 'preload'], prog='AnyBlok simple wsgi app, version %r' % version, description="WSGI for test your AnyBlok / Pyramid app", ) Configuration.add_application_properties( 'gunicorn', [], prog='AnyBlok simple wsgi app, version %r' % version, description="WSGI for test your AnyBlok / Pyramid app", configuration_groups=[ 'logging', 'pyramid-debug', 'auth', 'preload', 'gunicorn', 'database' ], ) Configuration.add_application_properties('nose', ['auth']) def get_db_name(request):
from os import environ from typing import TYPE_CHECKING from anyblok.config import Configuration from anyblok.config import get_db_name as gdb from starlette.requests import Request if TYPE_CHECKING: from anyblok.config import AnyBlokArgumentGroup Configuration.add_application_properties( "uvicorn", ["logging", "uvicorn", "plugins"], prog="AnyBlok asgi app, version", description="ASGI AnyBlok / uvicorn / Starlette / FastAPI app", ) Configuration.add_application_properties( "gunicorn", [], prog="AnyBlok gunicorn asgi app", description="WSGI for test your AnyBlok / Pyramid app", configuration_groups=["logging", "gunicorn", "database", "plugins"], ) def get_db_name(request: Request) -> str: return gdb() @Configuration.add("uvicorn", label="Uvicorn")
# Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. import anyblok from anyblok_delivery.release import version from anyblok.config import Configuration from logging import getLogger logger = getLogger(__name__) Configuration.add_application_properties( 'update_labels_status', [ 'logging', 'dramatiq-broker', ], prog='AnyBlok update label status, version %r' % version, description="Update label status") status = ['label', 'transit', 'exception'] def update_labels_status(): """Execute a script or open an interpreter """ registry = anyblok.start('update_labels_status') if registry: Shipment = registry.Delivery.Shipment query = Shipment.query() query = query.filter(Shipment.status.in_(status))
from os.path import join from os import walk from argparse import RawDescriptionHelpFormatter from textwrap import dedent from sqlalchemy_utils.functions import create_database from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) Configuration.add_application_properties( 'createdb', [ 'unittest', 'logging', 'create_db', 'install-bloks', 'install-or-update-bloks', ], prog='AnyBlok create database, version %r' % version, description="Create a database and install bloks to populate it" ) Configuration.add_application_properties( 'updatedb', [ 'unittest', 'logging', 'install-bloks', 'uninstall-bloks', 'update-bloks', 'install-or-update-bloks',
# This file is a part of the AnyBlok / Dramatiq project # # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration, AnyBlokPlugin import os Configuration.add_application_properties('createdb', ['dramatiq-broker']) Configuration.add_application_properties('updatedb', ['dramatiq-broker']) Configuration.add_application_properties('nose', ['dramatiq-broker']) Configuration.add_application_properties('interpreter', ['dramatiq-broker']) Configuration.add_application_properties('default', ['dramatiq-broker']) Configuration.add_application_properties('pyramid', ['dramatiq-broker']) Configuration.add_application_properties('gunicorn', ['dramatiq-broker'], add_default_group=False) @Configuration.add('dramatiq-consumer', label="Dramatiq - consumer options", must_be_loaded_by_unittest=True) def define_dramatiq_consumer(group): group.add_argument('--dramatiq-processes', type=int, default=os.environ.get('ANYBLOK_DRAMATIQ_PROCESSES', 4), help="Number of process") group.add_argument('--dramatiq-threads',
# This file is a part of the AnyBlok / Pyramid / Beaker project # # Copyright (C) 2016 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from anyblok_pyramid import config # noqa for update config Configuration.add_application_properties('pyramid', ['beaker']) Configuration.add_application_properties('gunicorn', ['beaker']) def get_db_name(request): dbname = request.session.get('dbname') if not dbname: dbname = Configuration.get('db_name') return dbname @Configuration.add('beaker', label="Beaker session") def define_beaker_option(group): group.add_argument('--beaker-data-dir', dest='beaker.session.data_dir', help="Used with any back-end that stores its data in " "physical files, such as the dbm or file-based " "back-ends. This path should be an absolute path " "to the directory that stores the files.")
from anyblok.release import version from .stations import ( update_or_create as stations_populate, update_station_file as stations_file_update, ) from .reduction_cards import update_or_create as reduction_cards_populate Configuration.add_application_properties( "populate_stations", ["logging"], prog="Trainwarner anyblok_populate_stations, version %r" % version, description="""Trainwarner populate_stations script. This script can be used to perform a complete population of Model.Station table using data/stations.csv file. This is mainly intented for development purposes, in case of update of CSV parsing methods, in order to be able to run a full population with having to update completely database. [NOTE] This can be ran on production server to update Model.Station table.""", ) Configuration.add_application_properties( "populate_reduction_cards", ["logging"], prog="Trainwarner anyblok_populate_reduction_cards, version %r" % version, description="""Trainwarner populate_reduction_cards script. This script can be used to perform a complete population of Model.ReductionCard table.