Esempio n. 1
0
def _second() -> None:
    from c2cwsgiutils import coverage_setup, sentry, broadcast, stats, redis_stats,\
        stats_pyramid, debug
    coverage_setup.init()
    sentry.init()
    broadcast.init()
    stats.init_backends()
    redis_stats.init()
    stats_pyramid.init_db_spy()
    debug.init_daemon()
Esempio n. 2
0
def init(config_file: str = "c2c:///app/production.ini") -> None:
    """Initialize the non-WSGI application, for backward compatibility."""
    loader = get_config_loader(config_file)
    loader.setup_logging(None)
    settings = loader.get_settings()
    config = pyramid.config.Configurator(settings=settings)
    coverage_setup.includeme()
    sentry.includeme(config)
    broadcast.includeme(config)
    stats.init_backends(settings)
    redis_stats.includeme(config)
    sql_profiler.includeme(config)
Esempio n. 3
0
def init(config: pyramid.config.Configurator) -> None:
    """
    Initialize the whole stats module.

    :param config: The Pyramid config
    """
    stats.init_backends(config.get_settings())
    if stats.BACKENDS:  # pragma: nocover
        if 'memory' in stats.BACKENDS:  # pragma: nocover
            from . import _views
            _views.init(config)
        from . import _pyramid_spy
        _pyramid_spy.init(config)
        init_db_spy()
Esempio n. 4
0
def main():
    stats.init_backends({})
    parser = ArgumentParser(
        description=
        'Used to generate the contextual file like the capabilities, the legends, '
        'the Apache and MapCache configuration',
        prog=sys.argv[0])
    add_comon_options(parser, tile_pyramid=False, no_geom=False)
    parser.add_argument('--status',
                        default=False,
                        action="store_true",
                        help='Display the SQS queue status and exit')
    parser.add_argument('--capabilities',
                        '--generate-wmts-capabilities',
                        default=False,
                        action='store_true',
                        help='Generate the WMTS Capabilities')
    parser.add_argument('--legends',
                        '--generate-legend-images',
                        default=False,
                        action='store_true',
                        dest='legends',
                        help='Generate the legend images')
    parser.add_argument('--openlayers',
                        '--generate-openlayers-testpage',
                        default=False,
                        action='store_true',
                        dest='openlayers',
                        help='Generate openlayers test page')
    parser.add_argument('--mapcache',
                        '--generate-mapcache-config',
                        default=False,
                        action='store_true',
                        dest='mapcache',
                        help='Generate MapCache configuration file')
    parser.add_argument('--apache',
                        '--generate-apache-config',
                        default=False,
                        action='store_true',
                        dest='apache',
                        help='Generate Apache configuration file')
    parser.add_argument(
        '--dump-config',
        default=False,
        action='store_true',
        help='Dump the used config with default values and exit')

    options = parser.parse_args()
    gene = TileGeneration(options.config, options, layer_name=options.layer)

    if options.status:  # pragma: no cover
        status(gene)
        sys.exit(0)

    if options.cache is None:
        options.cache = gene.config['generation']['default_cache']

    if options.dump_config:
        for layer in gene.config['layers'].values():
            gene.init_layer(layer, options)
        _validate_generate_wmts_capabilities(gene.caches[options.cache], True)
        for grid in gene.config['grids'].values():
            if 'obj' in grid:
                del grid['obj']
        print(yaml.dump(gene.config))
        sys.exit(0)

    if options.legends:
        _generate_legend_images(gene)

    if options.capabilities:
        _generate_wmts_capabilities(gene)

    if options.mapcache:
        _generate_mapcache_config(gene)

    if options.apache:
        _generate_apache_config(gene)

    if options.openlayers:
        _generate_openlayers(gene)
Esempio n. 5
0
def main() -> None:
    """Run the tiles generation."""
    try:
        stats.init_backends({})
        parser = ArgumentParser(description="Used to generate the tiles", prog=sys.argv[0])
        add_common_options(parser, dimensions=True)
        parser.add_argument(
            "--get-hash", metavar="TILE", help="get the empty tiles hash, use the specified TILE z/x/y"
        )
        parser.add_argument(
            "--get-bbox",
            metavar="TILE",
            help="get the bbox of a tile, use the specified TILE z/x/y, or z/x/y:+n/+n for metatiles",
        )
        parser.add_argument(
            "--role",
            default="local",
            choices=("local", "master", "slave"),
            help="local/master/slave, master to file the queue and slave to generate the tiles",
        )
        parser.add_argument(
            "--local-process-number", default=None, help="The number of process that we run in parallel"
        )
        parser.add_argument(
            "--detach", default=False, action="store_true", help="run detached from the terminal"
        )
        parser.add_argument(
            "--daemon", default=False, action="store_true", help="run continuously as a daemon"
        )
        parser.add_argument(
            "--tiles",
            metavar="FILE",
            help="Generate the tiles from a tiles file, use the format z/x/y, or z/x/y:+n/+n for metatiles",
        )

        options = parser.parse_args()

        if options.detach:
            detach()

        gene = TileGeneration(
            config_file=options.config, options=options, multi_thread=options.get_hash is None
        )

        if (
            options.get_hash is None
            and options.get_bbox is None
            and options.config is not None
            and "authorised_user" in gene.get_main_config().config.get("generation", {})
            and gene.get_main_config().config["generation"]["authorised_user"] != getuser()
        ):
            logger.error(
                "not authorised, authorised user is: %s.",
                gene.get_main_config().config["generation"]["authorised_user"],
            )
            sys.exit(1)

        if options.config:
            config = gene.get_config(options.config)

            if options.cache is None and options.config:
                options.cache = config.config["generation"]["default_cache"]

        if options.tiles is not None and options.role not in ["local", "master"]:
            logger.error("The --tiles option work only with role local or master")
            sys.exit(1)

        try:
            generate = Generate(options, gene)
            if options.role == "slave":
                generate.gene()
            elif options.layer:
                generate.gene(options.layer)
            elif options.get_bbox:
                logger.error("With --get-bbox option you need to specify a layer")
                sys.exit(1)
            elif options.get_hash:
                logger.error("With --get-hash option you need to specify a layer")
                sys.exit(1)
            else:
                if options.config:
                    for layer in config.config["generation"].get(
                        "default_layers", config.config["layers"].keys()
                    ):
                        generate.gene(layer)
        except tilecloud.filter.error.TooManyErrors:
            logger.exception("Too many errors")
            sys.exit(1)
        finally:
            gene.close()
    except SystemExit:
        raise
    except:  # pylint: disable=bare-except
        logger.exception("Exit with exception")
        if os.environ.get("TESTS", "false").lower() == "true":
            raise
        sys.exit(1)
Esempio n. 6
0
def main():
    stats.init_backends({})
    parser = ArgumentParser(description="Used to generate the tiles",
                            prog=sys.argv[0])
    add_comon_options(parser, dimensions=True)
    parser.add_argument(
        "--get-hash",
        metavar="TILE",
        help="get the empty tiles hash, use the specified TILE z/x/y")
    parser.add_argument(
        "--get-bbox",
        metavar="TILE",
        help=
        "get the bbox of a tile, use the specified TILE z/x/y, or z/x/y:+n/+n for metatiles",
    )
    parser.add_argument(
        "--role",
        default="local",
        choices=("local", "master", "slave"),
        help=
        "local/master/slave, master to file the queue and slave to generate the tiles",
    )
    parser.add_argument("--local-process-number",
                        default=None,
                        help="The number of process that we run in parallel")
    parser.add_argument("--detach",
                        default=False,
                        action="store_true",
                        help="run detached from the terminal")
    parser.add_argument("--daemon",
                        default=False,
                        action="store_true",
                        help="run continuously as a daemon")
    parser.add_argument(
        "--tiles",
        metavar="FILE",
        help=
        "Generate the tiles from a tiles file, use the format z/x/y, or z/x/y:+n/+n for metatiles",
    )

    options = parser.parse_args()

    if options.detach:
        detach()  # pragma: no cover

    gene = TileGeneration(options.config,
                          options,
                          multi_thread=options.get_hash is None)

    if (options.get_hash is None and options.get_bbox is None
            and "authorised_user" in gene.config["generation"]
            and gene.config["generation"]["authorised_user"] != getuser()):
        sys.exit("not authorised, authorised user is: {}.".format(
            gene.config["generation"]["authorised_user"]))

    if options.cache is None:
        options.cache = gene.config["generation"]["default_cache"]

    if options.tiles is not None and options.role not in [
            "local", "master"
    ]:  # pragma: no cover
        sys.exit("The --tiles option work only with role local or master")

    try:
        generate = Generate(options, gene)
        if options.role == "slave":
            generate.gene()
        elif options.layer:
            generate.gene(gene.layers[options.layer])
        elif options.get_bbox:  # pragma: no cover
            sys.exit("With --get-bbox option you need to specify a layer")
        elif options.get_hash:  # pragma: no cover
            sys.exit("With --get-hash option you need to specify a layer")
        elif options.tiles:  # pragma: no cover
            sys.exit("With --tiles option you need to specify a layer")
        else:
            for layer in gene.config["generation"].get("default_layers",
                                                       gene.layers.keys()):
                generate.gene(gene.layers[layer])
    finally:
        gene.close()
Esempio n. 7
0
def main():
    stats.init_backends({})
    parser = ArgumentParser(description='Used to generate the tiles',
                            prog=sys.argv[0])
    add_comon_options(parser, dimensions=True)
    parser.add_argument(
        '--get-hash',
        metavar="TILE",
        help='get the empty tiles hash, use the specified TILE z/x/y')
    parser.add_argument(
        '--get-bbox',
        metavar="TILE",
        help=
        'get the bbox of a tile, use the specified TILE z/x/y, or z/x/y:+n/+n for metatiles'
    )
    parser.add_argument(
        '--role',
        default='local',
        choices=('local', 'master', 'slave'),
        help='local/master/slave, master to file the queue and '
        'slave to generate the tiles')
    parser.add_argument("--local-process-number",
                        default=None,
                        help="The number of process that we run in parallel")
    parser.add_argument('--detach',
                        default=False,
                        action="store_true",
                        help='run detached from the terminal')
    parser.add_argument('--daemon',
                        default=False,
                        action="store_true",
                        help='run continuously as a daemon')
    parser.add_argument(
        '--tiles',
        metavar="FILE",
        help=
        'Generate the tiles from a tiles file, use the format z/x/y, or z/x/y:+n/+n for metatiles'
    )

    options = parser.parse_args()

    if options.detach:
        detach()  # pragma: no cover

    gene = TileGeneration(options.config, options)

    if options.get_hash is None and options.get_bbox is None and \
            'authorised_user' in gene.config['generation'] and \
            gene.config['generation']['authorised_user'] != getuser():
        exit('not authorised, authorised user is: {}.'.format(
            gene.config['generation']['authorised_user']))

    if options.cache is None:
        options.cache = gene.config['generation']['default_cache']

    if options.tiles is not None and options.role not in [
            'local', 'master'
    ]:  # pragma: no cover
        exit("The --tiles option work only with role local or master")

    try:
        generate = Generate(options, gene)
        if options.role == 'slave':
            generate.gene()
        elif options.layer:
            generate.gene(gene.layers[options.layer])
        elif options.get_bbox:  # pragma: no cover
            exit("With --get-bbox option we needs to specify a layer")
        elif options.get_hash:  # pragma: no cover
            exit("With --get-hash option we needs to specify a layer")
        elif options.tiles:  # pragma: no cover
            exit("With --tiles option we needs to specify a layer")
        else:
            for layer in gene.config['generation'].get('default_layers',
                                                       gene.layers.keys()):
                generate.gene(gene.layers[layer])
    finally:
        gene.close()
Esempio n. 8
0
def main():
    stats.init_backends({})
    parser = ArgumentParser(description='Used to generate the tiles', prog=sys.argv[0])
    add_comon_options(parser, dimensions=True)
    parser.add_argument(
        '--get-hash', metavar="TILE",
        help='get the empty tiles hash, use the specified TILE z/x/y'
    )
    parser.add_argument(
        '--get-bbox', metavar="TILE",
        help='get the bbox of a tile, use the specified TILE z/x/y, or z/x/y:+n/+n for metatiles'
    )
    parser.add_argument(
        '--role', default='local', choices=('local', 'master', 'slave'),
        help='local/master/slave, master to file the queue and '
        'slave to generate the tiles'
    )
    parser.add_argument(
        "--local-process-number", default=None,
        help="The number of process that we run in parallel"
    )
    parser.add_argument(
        '--detach', default=False, action="store_true",
        help='run detached from the terminal'
    )
    parser.add_argument(
        '--daemon', default=False, action="store_true",
        help='run continuously as a daemon'
    )
    parser.add_argument(
        '--tiles', metavar="FILE",
        help='Generate the tiles from a tiles file, use the format z/x/y, or z/x/y:+n/+n for metatiles'
    )

    options = parser.parse_args()

    if options.detach:
        detach()  # pragma: no cover

    gene = TileGeneration(options.config, options)

    if options.get_hash is None and options.get_bbox is None and \
            'authorised_user' in gene.config['generation'] and \
            gene.config['generation']['authorised_user'] != getuser():
        exit('not authorised, authorised user is: {}.'.format(gene.config['generation']['authorised_user']))

    if options.cache is None:
        options.cache = gene.config['generation']['default_cache']

    if options.tiles is not None and options.role not in ['local', 'master']:  # pragma: no cover
        exit("The --tiles option work only with role local or master")

    try:
        generate = Generate(options, gene)
        if options.role == 'slave':
            generate.gene()
        elif options.layer:
            generate.gene(gene.layers[options.layer])
        elif options.get_bbox:  # pragma: no cover
            exit("With --get-bbox option you need to specify a layer")
        elif options.get_hash:  # pragma: no cover
            exit("With --get-hash option you need to specify a layer")
        elif options.tiles:  # pragma: no cover
            exit("With --tiles option you need to specify a layer")
        else:
            for layer in gene.config['generation'].get('default_layers', gene.layers.keys()):
                generate.gene(gene.layers[layer])
    finally:
        gene.close()
Esempio n. 9
0
def main() -> None:
    """Generate the contextual file like the legends."""
    try:
        stats.init_backends({})
        parser = ArgumentParser(
            description=
            "Used to generate the contextual file like the capabilities, the legends, "
            "the OpenLayers example",
            prog=sys.argv[0],
        )
        add_common_options(parser, tile_pyramid=False, no_geom=False)
        parser.add_argument("--status",
                            default=False,
                            action="store_true",
                            help="Display the SQS queue status and exit")
        parser.add_argument(
            "--legends",
            "--generate-legend-images",
            default=False,
            action="store_true",
            dest="legends",
            help="Generate the legend images",
        )
        parser.add_argument(
            "--dump-config",
            default=False,
            action="store_true",
            help="Dump the used config with default values and exit",
        )

        options = parser.parse_args()
        gene = TileGeneration(options.config,
                              options,
                              layer_name=options.layer)
        assert gene.config_file
        config = gene.get_config(gene.config_file)

        if options.status:
            status(gene)
            sys.exit(0)

        if options.cache is None:
            options.cache = config.config["generation"]["default_cache"]

        if options.dump_config:
            _validate_generate_wmts_capabilities(
                config.config["caches"][options.cache], options.cache, True)
            yaml = ruamel.yaml.YAML()  # type: ignore
            out = StringIO()
            yaml.dump(config.config, out)
            print(out.getvalue())
            sys.exit(0)

        if options.legends:
            _generate_legend_images(gene)

    except SystemExit:
        raise
    except:  # pylint: disable=bare-except
        logger.exception("Exit with exception")
        if os.environ.get("TESTS", "false").lower() == "true":
            raise
        sys.exit(1)
Esempio n. 10
0
def main():
    stats.init_backends({})
    parser = ArgumentParser(
        description="Used to generate the contextual file like the capabilities, the legends, "
        "the Apache and MapCache configuration",
        prog=sys.argv[0],
    )
    add_comon_options(parser, tile_pyramid=False, no_geom=False)
    parser.add_argument(
        "--status", default=False, action="store_true", help="Display the SQS queue status and exit"
    )
    parser.add_argument(
        "--capabilities",
        "--generate-wmts-capabilities",
        default=False,
        action="store_true",
        help="Generate the WMTS Capabilities",
    )
    parser.add_argument(
        "--legends",
        "--generate-legend-images",
        default=False,
        action="store_true",
        dest="legends",
        help="Generate the legend images",
    )
    parser.add_argument(
        "--openlayers",
        "--generate-openlayers-testpage",
        default=False,
        action="store_true",
        dest="openlayers",
        help="Generate openlayers test page",
    )
    parser.add_argument(
        "--mapcache",
        "--generate-mapcache-config",
        default=False,
        action="store_true",
        dest="mapcache",
        help="Generate MapCache configuration file",
    )
    parser.add_argument(
        "--mapcache-version", default="1.4", choices=("1.4", "1.6"), help="The used version of MapCache"
    )
    parser.add_argument(
        "--apache",
        "--generate-apache-config",
        default=False,
        action="store_true",
        dest="apache",
        help="Generate Apache configuration file",
    )
    parser.add_argument(
        "--dump-config",
        default=False,
        action="store_true",
        help="Dump the used config with default values and exit",
    )

    options = parser.parse_args()
    gene = TileGeneration(options.config, options, layer_name=options.layer)

    if options.status:  # pragma: no cover
        status(gene)
        sys.exit(0)

    if options.cache is None:
        options.cache = gene.config["generation"]["default_cache"]

    if options.dump_config:
        for layer in gene.config["layers"].values():
            gene.init_layer(layer, options)
        _validate_generate_wmts_capabilities(gene.caches[options.cache], True)
        for grid in gene.config["grids"].values():
            if "obj" in grid:
                del grid["obj"]
        print(yaml.dump(gene.config))
        sys.exit(0)

    if options.legends:
        _generate_legend_images(gene)

    if options.capabilities:
        _generate_wmts_capabilities(gene)

    if options.mapcache:
        _generate_mapcache_config(gene, options.mapcache_version)

    if options.apache:
        _generate_apache_config(gene)

    if options.openlayers:
        _generate_openlayers(gene)