mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-24 14:36:25 +02:00
Fix logging.
This commit is contained in:
parent
82691b6c5c
commit
6fd2c81235
5 changed files with 19 additions and 31 deletions
|
@ -29,7 +29,7 @@ from roentgen.osm_getter import get_osm
|
||||||
from roentgen.osm_reader import Map, OSMReader, OverpassReader
|
from roentgen.osm_reader import Map, OSMReader, OverpassReader
|
||||||
from roentgen.point import Point
|
from roentgen.point import Point
|
||||||
from roentgen.scheme import LineStyle, Scheme
|
from roentgen.scheme import LineStyle, Scheme
|
||||||
from roentgen.ui import error, parse_options
|
from roentgen.ui import parse_options
|
||||||
from roentgen.util import MinMax
|
from roentgen.util import MinMax
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ def main(options) -> None:
|
||||||
else:
|
else:
|
||||||
content = get_osm(options.boundary_box, cache_path)
|
content = get_osm(options.boundary_box, cache_path)
|
||||||
if not content:
|
if not content:
|
||||||
error("cannot download OSM data")
|
logging.fatal("Cannot download OSM data.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
input_file_names = [cache_path / f"{options.boundary_box}.osm"]
|
input_file_names = [cache_path / f"{options.boundary_box}.osm"]
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ from svgwrite.container import Group
|
||||||
from svgwrite.path import Path as SvgPath
|
from svgwrite.path import Path as SvgPath
|
||||||
|
|
||||||
from roentgen.color import is_bright
|
from roentgen.color import is_bright
|
||||||
from roentgen.ui import error
|
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
@ -241,7 +240,7 @@ class ShapeExtractor:
|
||||||
configuration, path, point, id_, name
|
configuration, path, point, id_, name
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
error(f"not standard ID {id_}")
|
logging.error(f"Not standard ID {id_}.")
|
||||||
|
|
||||||
def get_shape(self, id_: str) -> Optional[Shape]:
|
def get_shape(self, id_: str) -> Optional[Shape]:
|
||||||
"""
|
"""
|
||||||
|
@ -294,7 +293,9 @@ class ShapeSpecification:
|
||||||
if "shape" in structure:
|
if "shape" in structure:
|
||||||
shape = extractor.get_shape(structure["shape"])
|
shape = extractor.get_shape(structure["shape"])
|
||||||
else:
|
else:
|
||||||
error("invalid shape specification: 'shape' key expected")
|
logging.error(
|
||||||
|
"Invalid shape specification: `shape` key expected."
|
||||||
|
)
|
||||||
if "color" in structure:
|
if "color" in structure:
|
||||||
color = scheme.get_color(structure["color"])
|
color = scheme.get_color(structure["color"])
|
||||||
if "offset" in structure:
|
if "offset" in structure:
|
||||||
|
|
|
@ -7,10 +7,9 @@ import urllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
import logging
|
||||||
import urllib3
|
import urllib3
|
||||||
|
|
||||||
from roentgen.ui import error
|
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ def get_osm(
|
||||||
)
|
)
|
||||||
|
|
||||||
if not matcher:
|
if not matcher:
|
||||||
error("invalid boundary box")
|
logging.fatal("Invalid boundary box.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -46,17 +45,17 @@ def get_osm(
|
||||||
right = float(matcher.group("right"))
|
right = float(matcher.group("right"))
|
||||||
top = float(matcher.group("top"))
|
top = float(matcher.group("top"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
error("parsing boundary box")
|
logging.fatal("Invalid boundary box.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if left >= right:
|
if left >= right:
|
||||||
error("negative horizontal boundary")
|
logging.fatal("Negative horizontal boundary.")
|
||||||
return None
|
return None
|
||||||
if bottom >= top:
|
if bottom >= top:
|
||||||
error("negative vertical boundary")
|
logging.error("Negative vertical boundary.")
|
||||||
return None
|
return None
|
||||||
if right - left > 0.5 or top - bottom > 0.5:
|
if right - left > 0.5 or top - bottom > 0.5:
|
||||||
error("box too big")
|
logging.error("Boundary box is too big.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
content = get_data(
|
content = get_data(
|
||||||
|
|
|
@ -20,7 +20,6 @@ from roentgen.mapper import Painter
|
||||||
from roentgen.osm_getter import get_osm
|
from roentgen.osm_getter import get_osm
|
||||||
from roentgen.osm_reader import Map, OSMReader
|
from roentgen.osm_reader import Map, OSMReader
|
||||||
from roentgen.scheme import Scheme
|
from roentgen.scheme import Scheme
|
||||||
from roentgen.ui import error
|
|
||||||
from roentgen.util import MinMax
|
from roentgen.util import MinMax
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ class Tile:
|
||||||
)
|
)
|
||||||
content = get_osm(boundary_box, Path("cache"))
|
content = get_osm(boundary_box, Path("cache"))
|
||||||
if not content:
|
if not content:
|
||||||
error("cannot download OSM data")
|
logging.error("Cannot download OSM data.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return OSMReader().parse_osm_file(cache_path / (boundary_box + ".osm"))
|
return OSMReader().parse_osm_file(cache_path / (boundary_box + ".osm"))
|
||||||
|
@ -120,13 +119,17 @@ class Tile:
|
||||||
f"https://tile.openstreetmap.org/{self.scale}/{self.x}/{self.y}.png"
|
f"https://tile.openstreetmap.org/{self.scale}/{self.x}/{self.y}.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw(self, directory_name: Path, cache_path: Path):
|
def draw(self, directory_name: Path, cache_path: Path) -> None:
|
||||||
"""
|
"""
|
||||||
Draw tile to SVG file.
|
Draw tile to SVG file.
|
||||||
|
|
||||||
:param directory_name: output directory to storing tiles
|
:param directory_name: output directory to storing tiles
|
||||||
|
:param cache_path: directory to store temporary files
|
||||||
"""
|
"""
|
||||||
map_ = self.load_map(cache_path)
|
map_ = self.load_map(cache_path)
|
||||||
|
if map_ is None:
|
||||||
|
logging.fatal("No map to draw.")
|
||||||
|
return
|
||||||
|
|
||||||
lat1, lon1 = self.get_coordinates()
|
lat1, lon1 = self.get_coordinates()
|
||||||
lat2, lon2 = Tile(self.x + 1, self.y + 1, self.scale).get_coordinates()
|
lat2, lon2 = Tile(self.x + 1, self.y + 1, self.scale).get_coordinates()
|
||||||
|
@ -181,8 +184,7 @@ def ui(options) -> None:
|
||||||
scale, x, y = map(int, options.tile.split("/"))
|
scale, x, y = map(int, options.tile.split("/"))
|
||||||
tile = Tile(x, y, scale)
|
tile = Tile(x, y, scale)
|
||||||
else:
|
else:
|
||||||
logging.fatal("specify either --coordinates, or --tile")
|
logging.fatal("Specify either --coordinates, or --tile.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
tile.draw(directory, Path(options.cache))
|
tile.draw(directory, Path(options.cache))
|
||||||
print(tile.get_carto_address())
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ Command-line user interface.
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
|
@ -185,15 +183,3 @@ def progress_bar(
|
||||||
f"{int(length - fill_length - 1) * ' '}▏{text}"
|
f"{int(length - fill_length - 1) * ' '}▏{text}"
|
||||||
)
|
)
|
||||||
sys.stdout.write("\033[F")
|
sys.stdout.write("\033[F")
|
||||||
|
|
||||||
|
|
||||||
def error(message: Optional[str] = None):
|
|
||||||
"""
|
|
||||||
Print error message.
|
|
||||||
|
|
||||||
:param message: message to print.
|
|
||||||
"""
|
|
||||||
if message:
|
|
||||||
print(f"Error: {message}.")
|
|
||||||
else:
|
|
||||||
print("Error.")
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue