Skip to content

Commit

Permalink
Merge pull request #2618 from camptocamp/backport/2617-to-master
Browse files Browse the repository at this point in the history
[Backport master] Add message for the use in legeng and hash generation
  • Loading branch information
sbrunner authored Nov 30, 2024
2 parents e16c82c + 084bdc2 commit 901597b
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tilecloud_chain/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
- **`name`** _(string)_: The name used in the admin interface.
- **`allowed_commands`** _(array)_: The allowed commands (main configuration). Default: `["generate-tiles", "generate-controller", "generate-cost"]`.
- **Items** _(string)_
- **`allowed_arguments`** _(array)_: The allowed arguments (main configuration). Default: `["--layer", "--get-hash", "--generate-legend-images", "--get-bbox", "--help", "--ignore-errors", "--bbox", "--zoom", "--test", "--near", "--time", "--measure-generation-time", "--no-geom", "--dimensions"]`.
- **`allowed_arguments`** _(array)_: The allowed arguments (main configuration). Default: `["--layer", "--get-hash", "--generate-legend-images", "--get-bbox", "--help", "--ignore-error", "--bbox", "--zoom", "--test", "--near", "--time", "--measure-generation-time", "--no-geom", "--dimensions"]`.
- **Items** _(string)_
- **`admin_footer`** _(string)_: The footer of the admin interface.
- **`admin_footer_classes`** _(string)_: The CSS classes used on the footer of the admin interface.
Expand Down
3 changes: 2 additions & 1 deletion tilecloud_chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,8 @@ def __call__(self, tile: Tile) -> Tile:
if ref is None:
ref = px
elif px != ref:
_LOGGER.error("Error: image is not uniform.")
print("Error: image is not uniform.")
_LOGGER.debug("Error: image is not uniform.")
sys.exit(1)

assert tile.data
Expand Down
4 changes: 2 additions & 2 deletions tilecloud_chain/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"--generate-legend-images",
"--get-bbox",
"--help",
"--ignore-errors",
"--ignore-error",
"--bbox",
"--zoom",
"--test",
Expand Down Expand Up @@ -2527,7 +2527,7 @@ class Server(TypedDict, total=False):
- --generate-legend-images
- --get-bbox
- --help
- --ignore-errors
- --ignore-error
- --bbox
- --zoom
- --test
Expand Down
73 changes: 70 additions & 3 deletions tilecloud_chain/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,83 @@ def _generate_legend_images(gene: TileGeneration) -> None:
resolution,
url,
)
response = session.get(url)
try:
response = session.get(url)
except Exception as e: # pylint: disable=broad-exception-caught
print(
"\n".join(
[
f"Unable to get legend image for layer '{layer_name}'-'{wmslayer}', resolution '{resolution}'",
url,
str(e),
]
)
)
_LOGGER.debug(
"Unable to get legend image for layer '%s'-'%s', resolution '%s'",
layer_name,
wmslayer,
resolution,
exc_info=True,
)
continue
if response.status_code != 200:
print(
"\n".join(
[
f"Unable to get legend image for layer '{layer_name}'-'{wmslayer}', resolution '{resolution}'",
url,
f"status code: {response.status_code}: {response.reason}",
response.text,
]
)
)
_LOGGER.debug(
"Unable to get legend image for layer '%s'-'%s', resolution '%s': %s",
layer_name,
wmslayer,
resolution,
response.text,
)
continue
if not response.headers["Content-Type"].startswith(layer["legend_mime"].split("/")[0]):
print(
"\n".join(
[
f"Unable to get legend image for layer '{layer_name}'-'{wmslayer}', resolution '{resolution}'",
url,
f"Content-Type: {response.headers['Content-Type']}",
response.text,
]
)
)
_LOGGER.debug(
"Unable to get legend image for layer '%s'-'%s', resolution '%s', content-type: %s: %s",
layer_name,
wmslayer,
resolution,
response.headers["Content-Type"],
response.text,
)
continue
try:
legends.append(Image.open(BytesIO(response.content)))
except Exception: # pylint: disable=broad-exception-caught
_LOGGER.warning(
print(
"\n".join(
[
f"Unable to read legend image for layer '{layer_name}'-'{wmslayer}', resolution '{resolution}'",
url,
response.text,
]
)
)
_LOGGER.debug(
"Unable to read legend image for layer '%s'-'%s', resolution '%s': %s",
layer_name,
wmslayer,
resolution,
response.content,
response.text,
exc_info=True,
)
width = max(1, max(i.size[0] for i in legends) if legends else 0)
Expand Down
2 changes: 1 addition & 1 deletion tilecloud_chain/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@
"--generate-legend-images",
"--get-bbox",
"--help",
"--ignore-errors",
"--ignore-error",
"--bbox",
"--zoom",
"--test",
Expand Down
39 changes: 39 additions & 0 deletions tilecloud_chain/templates/admin_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,45 @@ <h2>Launch generation</h2>
<span id="result"></span>
%endif

<!---->
%if request.identity.is_auth:
<h3>Usage</h3>
<h4><code>generate-tiles</code></h4>
<p>Generate the tiles.</p>
<p>Arguments:</p>
<ul>
<li>
<code>--layer=NAME</code>: the layer name to generate, it not specified all the layers are generated.
</li>
<li>
<code>--get-hash=Z/X/Y</code>: get the hash configuration for the layer (requires
<code>--layer</code>).
</li>
<li>
<code>--get-bbox=Z/X/Y[:-N/+N]</code>: get the bbox of a tile, use the specified tile
<code>Z/X/Y</code>, or <code>Z/X/Y:+N/+N</code> for metatiles (requires <code>--layer</code>).
</li>
<li>
<code>--dimensions DIMENSION=VALUE [DIMENSION=VALUE ...]</code>: overwrite the dimensions values
specified in the config file.
</li>
<li>
<code>--zoom=ZOOM</code> restrict to specified zoom level, or a zooms range (2-5), or a zooms list
(2,4,5).
</li>
<li><code>--bbox MINX MINY MAXX MAXY</code>: restrict to specified bounding box.</li>
<li>
<code>--near X Y</code>: This option is a good replacement of <code>--bbox</code>, to used with
<code>--time</code> or <code>--test</code> and <code>--zoom</code>, implies <code>--no-geom</code>. It
automatically measure a bbox around the X Y position that corresponds to the metatiles.
</li>
<li><code>--test N</code>: test with generating N tiles.</li>
</ul>

<h4><code>generate-controller --generate-legend-images</code></h4>
<p>Generate the legend images.</p>
%endif

<h2>Test</h2>
<p>See the result in <a href="/${admin_path}/test">the test page</a>.</p>

Expand Down
Binary file modified tilecloud_chain/tests/index.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions tilecloud_chain/tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ def test_get_hash(self) -> None:

def test_get_wrong_hash(self) -> None:
for d in ("-d", "-q"):
with LogCapture("tilecloud_chain", level=30) as log_capture:
with LogCapture("tilecloud_chain") as log_capture:
self.assert_cmd_exit_equals(
cmd=f".build/venv/bin/generate_tiles {d} --get-hash 0/7/5 "
"-c tilegeneration/test.yaml -l all",
main_func=generate.main,
)
log_capture.check(
log_capture.check_present(
(
"tilecloud_chain",
"ERROR",
"DEBUG",
"Error: image is not uniform.",
)
),
)

def test_get_bbox(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tilecloud_chain/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_should_not_commit():
[
pytest.param("http://application:8080/admin/", "not-login", 250, 800, id="not-login"),
pytest.param("http://application:8080/admin/test", "test", 800, 800, id="test-not-login"),
pytest.param("http://app_test_user:8080/admin", "index", 500, 1000, id="index"),
pytest.param("http://app_test_user:8080/admin", "index", 1000, 1000, id="index"),
pytest.param("http://app_test_user:8080/admin/test", "test", 800, 800, id="test"),
],
)
Expand Down

0 comments on commit 901597b

Please sign in to comment.