def includeme(config): # import needs to be here, otherwise ImportError happens during setup.py install (modules not yet installed) # pylint: disable=C0415 from pyramid.events import NewRequest from pyramid.tweens import EXCVIEW from cowbird.api import generic as ag from cowbird.constants import get_constant from cowbird.utils import fully_qualified_name, get_logger, log_exception_tween, log_request mod_dir = get_constant("COWBIRD_MODULE_DIR", config) logger = get_logger(__name__) logger.info("Adding COWBIRD_MODULE_DIR='%s' to path.", mod_dir) sys.path.insert(0, mod_dir) config.add_exception_view(ag.internal_server_error) config.add_notfound_view(RemoveSlashNotFoundViewFactory( ag.not_found_or_method_not_allowed), append_slash=True) tween_position = fully_qualified_name(ag.apply_response_format_tween) config.add_tween(tween_position, over=EXCVIEW) if get_constant("COWBIRD_LOG_REQUEST", config): config.add_subscriber(log_request, NewRequest) if get_constant("COWBIRD_LOG_EXCEPTION", config): tween_name = fully_qualified_name(log_exception_tween) config.add_tween(tween_name, under=tween_position) tween_position = tween_name config.add_tween(fully_qualified_name(ag.validate_accept_header_tween), under=tween_position) config.include("cornice") config.include("cornice_swagger") config.include("cowbird.api") config.include("cowbird.database")
def includeme(config): logger = get_logger(__name__) logger.info("Adding swagger...") config.add_route(**s.service_api_route_info(s.SwaggerAPI)) config.add_route(**s.service_api_route_info(s.SwaggerGenerator)) config.add_view(api_schema, route_name=s.SwaggerGenerator.name, request_method="GET", renderer="json", permission=NO_PERMISSION_REQUIRED) config.add_view(api_swagger, route_name=s.SwaggerAPI.name, renderer="templates/swagger_ui.mako", permission=NO_PERMISSION_REQUIRED)
def includeme(config): """ Include API sub-modules. Each should defined an ``includeme`` function with further sub-modules to include, and every one of their relative views and routes. """ logger = get_logger(__name__) logger.info("Adding API routes...") cur_dir = os.path.dirname(__file__) for mod_name in os.listdir(cur_dir): mod_path = os.path.join(cur_dir, mod_name) mod_init = os.path.join(mod_path, "__init__.py") if os.path.isdir(mod_path) and os.path.isfile(mod_init): config.include("cowbird.api.{}".format(mod_name))
from cowbird.api import schemas as s from cowbird.utils import get_logger LOGGER = get_logger(__name__) def includeme(config): LOGGER.info("Adding API base routes...") config.add_route(**s.service_api_route_info(s.VersionAPI)) config.add_route(**s.service_api_route_info(s.HomepageAPI)) config.scan()
def includeme(config): logger = get_logger(__name__) logger.info("Adding webhooks base routes...") config.add_route(**s.service_api_route_info(s.UserWebhookAPI)) config.add_route(**s.service_api_route_info(s.PermissionWebhookAPI)) config.scan()
import argparse import importlib import os import sys from typing import TYPE_CHECKING from cowbird import __meta__ from cowbird.cli.utils import get_logger_parser, subparser_help from cowbird.utils import get_logger if TYPE_CHECKING: from cowbird.cli.utils import ParserMaker, ParserRunner LOGGER = get_logger(__name__, message_format="%(asctime)s - %(levelname)s - %(message)s", datetime_format="%d-%b-%y %H:%M:%S", force_stdout=False) def main(args=None): """ Automatically groups all sub-helper CLI listed in :py:mod:`cowbird.cli` as a common ``cowbird`` CLI entrypoint. Dispatches the provided arguments to the appropriate sub-helper CLI as requested. Each sub-helper CLI must implement functions ``make_parser`` and ``main`` to generate the arguments and dispatch them to the corresponding caller. """ parser = argparse.ArgumentParser( description="Execute {} CLI operations.".format(__meta__.__package__)) parser.add_argument("--version", action="version", version="%(prog)s {}".format(__meta__.__version__),