Esempio n. 1
0
    def setUp(self):
        initialize_database(":memory:", reset=True)

        self.source = BaseBootstrapSource()

        def lookup_host(hostname):
            return {
                'the.host': {
                    'hostname': 'the.host',
                    'uses_ssl': True,
                    'cdn': 'thecdn'
                },
                'missingcdn.host': {
                    'hostname': 'missingcdn.host',
                    'cdn': 'missingcdn'
                },
                'invalid.host': {
                    'hostname': 'invalid.host',
                    'uses_ssl': True,
                },
                'mismatch.host': {
                    'hostname': 'the.host',
                    'uses_ssl': True,
                    'cdn': 'thecdn'
                },
                'badcdn.host': {
                    'hostname': 'badcdn.host',
                    'cdn': 'invalidcdn'
                }
            }.get(hostname, None)

        def lookup_cdn(cdn_id):
            return {
                'thecdn': {
                    'id': 'thecdn',
                    'name': 'The CDN',
                    'edge_server': '1.2.3.4'
                },
                'invalidcdn': {
                    'name': 'The CDN',
                    'edge_server': '1.2.3.4'
                },
            }.get(cdn_id, None)

        self.source.lookup_host = lookup_host
        self.source.lookup_cdn = lookup_cdn

        self.bootstrapper = Bootstrapper()
        self.bootstrapper.add_source(self.source)
Esempio n. 2
0
def cachebrowser(click_context, config, verbose, reset_db, dev, **kwargs):
    settings = DevelopmentSettings() if dev else ProductionSettings()

    if config is None and os.path.isfile(settings.data_path('config.yaml')):
        config = open(settings.data_path('config.yaml'))

    try:
        settings.update_with_settings_file(config)
        settings.update_with_args(kwargs)
        settings.validate()
    except SettingsValidationError as e:
        print("Error parsing settings")
        print(e.message)
        sys.exit(1)

    initialize_logging(verbose)

    if not dev:
        check_data_files(settings)

    logger.debug("Initializing database {}".format(settings.database))
    initialize_database(settings.database, reset_db)

    logger.debug("Initializing bootstrapper")
    bootstrapper = Bootstrapper(settings)

    context = Context()
    context.bootstrapper = bootstrapper
    context.settings = settings
    context.click = click_context

    click_context.obj = context

    if click_context.invoked_subcommand is None:
        logger.debug("No command specified, starting CacheBrowser server")
        click_context.invoke(start_cachebrowser_server)