mirror of
https://github.com/enzet/map-machine.git
synced 2025-04-29 18:27:19 +02:00
Issue #140: check for an empty scheme file.
This commit is contained in:
parent
a6955c7d22
commit
cb1bdceedb
2 changed files with 12 additions and 5 deletions
|
@ -267,7 +267,9 @@ def render_map(arguments: argparse.Namespace) -> None:
|
||||||
if scheme_path is None:
|
if scheme_path is None:
|
||||||
fatal(f"Scheme `{arguments.scheme}` not found.")
|
fatal(f"Scheme `{arguments.scheme}` not found.")
|
||||||
|
|
||||||
scheme: Scheme = Scheme.from_file(scheme_path)
|
scheme: Optional[Scheme] = Scheme.from_file(scheme_path)
|
||||||
|
if scheme is None:
|
||||||
|
fatal(f"Failed to load scheme from `{arguments.scheme}`.")
|
||||||
|
|
||||||
configuration: MapConfiguration = MapConfiguration.from_options(
|
configuration: MapConfiguration = MapConfiguration.from_options(
|
||||||
scheme, arguments, float(arguments.zoom)
|
scheme, arguments, float(arguments.zoom)
|
||||||
|
|
|
@ -363,15 +363,20 @@ class Scheme:
|
||||||
self.cache: dict[str, tuple[IconSet, int]] = {}
|
self.cache: dict[str, tuple[IconSet, int]] = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, file_name: Path) -> "Scheme":
|
def from_file(cls, file_name: Path) -> Optional["Scheme"]:
|
||||||
"""
|
"""
|
||||||
:param file_name: name of the scheme file with tags, colors, and tag key
|
:param file_name: name of the scheme file with tags, colors, and tag key
|
||||||
specification
|
specification
|
||||||
"""
|
"""
|
||||||
with file_name.open(encoding="utf-8") as input_file:
|
with file_name.open(encoding="utf-8") as input_file:
|
||||||
|
try:
|
||||||
content: dict[str, Any] = yaml.load(
|
content: dict[str, Any] = yaml.load(
|
||||||
input_file.read(), Loader=yaml.FullLoader
|
input_file.read(), Loader=yaml.FullLoader
|
||||||
)
|
)
|
||||||
|
except yaml.YAMLError:
|
||||||
|
return None
|
||||||
|
if not content:
|
||||||
|
return cls({})
|
||||||
return cls(content)
|
return cls(content)
|
||||||
|
|
||||||
def get_color(self, color: str) -> Color:
|
def get_color(self, color: str) -> Color:
|
||||||
|
|
Loading…
Add table
Reference in a new issue