Beispiel #1
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)
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
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()