mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-21 04:56:24 +02:00
Add cache argument for server command.
This commit is contained in:
parent
be0420b53d
commit
0f7665d3fd
3 changed files with 17 additions and 3 deletions
|
@ -226,7 +226,7 @@ if __name__ == "__main__":
|
|||
elif options.command == "element":
|
||||
draw_element(options)
|
||||
elif options.command == "server":
|
||||
server.ui()
|
||||
server.ui(options)
|
||||
elif options.command == "taginfo":
|
||||
from roentgen.taginfo import write_taginfo_project_file
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
|
||||
def __init__(self, request, client_address, server):
|
||||
super().__init__(request, client_address, server)
|
||||
self.cache: Path = Path("cache")
|
||||
|
||||
def write(self, message):
|
||||
if isinstance(message, bytes):
|
||||
|
@ -35,7 +36,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
if not png_path.exists():
|
||||
if not svg_path.exists():
|
||||
tile = Tile(x, y, zoom)
|
||||
tile.draw(tile_path)
|
||||
tile.draw(tile_path, self.cache)
|
||||
rasterize(svg_path, png_path)
|
||||
if zoom != 18:
|
||||
return
|
||||
|
@ -48,11 +49,12 @@ class Handler(BaseHTTPRequestHandler):
|
|||
return
|
||||
|
||||
|
||||
def ui():
|
||||
def ui(options):
|
||||
server: Optional[HTTPServer] = None
|
||||
try:
|
||||
port: int = 8080
|
||||
server = HTTPServer(("", port), Handler)
|
||||
server.cache_path = Path(options.cache)
|
||||
server.serve_forever()
|
||||
logging.info(f"Server started on port {port}.")
|
||||
finally:
|
||||
|
|
|
@ -31,9 +31,11 @@ def parse_options(args) -> argparse.Namespace:
|
|||
subparser.add_parser("taginfo")
|
||||
tile = subparser.add_parser("tile")
|
||||
element = subparser.add_parser("element")
|
||||
server = subparser.add_parser("server")
|
||||
|
||||
add_render_arguments(render)
|
||||
add_tile_arguments(tile)
|
||||
add_server_arguments(server)
|
||||
|
||||
element.add_argument("-n", "--node")
|
||||
element.add_argument("-w", "--way")
|
||||
|
@ -74,6 +76,16 @@ def add_tile_arguments(tile) -> None:
|
|||
)
|
||||
|
||||
|
||||
def add_server_arguments(tile) -> None:
|
||||
"""Add arguments for server command."""
|
||||
tile.add_argument(
|
||||
"--cache",
|
||||
help="path for temporary OSM files",
|
||||
default="cache",
|
||||
metavar="<path>",
|
||||
)
|
||||
|
||||
|
||||
def add_render_arguments(render) -> None:
|
||||
"""Add arguments for render command."""
|
||||
render.add_argument(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue