mirror of
https://github.com/enzet/map-machine.git
synced 2025-04-29 02:08:03 +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:
|
||||
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(
|
||||
scheme, arguments, float(arguments.zoom)
|
||||
|
|
|
@ -363,15 +363,20 @@ class Scheme:
|
|||
self.cache: dict[str, tuple[IconSet, int]] = {}
|
||||
|
||||
@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
|
||||
specification
|
||||
"""
|
||||
with file_name.open(encoding="utf-8") as input_file:
|
||||
content: dict[str, Any] = yaml.load(
|
||||
input_file.read(), Loader=yaml.FullLoader
|
||||
)
|
||||
try:
|
||||
content: dict[str, Any] = yaml.load(
|
||||
input_file.read(), Loader=yaml.FullLoader
|
||||
)
|
||||
except yaml.YAMLError:
|
||||
return None
|
||||
if not content:
|
||||
return cls({})
|
||||
return cls(content)
|
||||
|
||||
def get_color(self, color: str) -> Color:
|
||||
|
|
Loading…
Add table
Reference in a new issue