Skip to content

Commit 596910f

Browse files
committed
Issue #140: find scheme by identifier or path.
1 parent edb69c9 commit 596910f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

map_machine/workspace.py

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
__author__ = "Sergey Vartanov"
55
__email__ = "[email protected]"
66

7+
from typing import Optional
8+
79
HERE: Path = Path(__file__).parent
810

911

@@ -40,6 +42,33 @@ def __init__(self, output_path: Path) -> None:
4042
self._mapcss_path: Path = output_path / "map_machine_mapcss"
4143
self._tile_path: Path = output_path / "tiles"
4244

45+
def find_scheme_path(self, identifier: str) -> Optional[Path]:
46+
"""
47+
Find map scheme file by its identifier.
48+
49+
:param identifier: scheme identifier or file path.
50+
:returns:
51+
- default scheme file `default.yml` if identifier is not specified,
52+
- `<identifier>.yml` from the default scheme directory (`scheme`) if
53+
exists,
54+
- path if identifier is a relative or absolute path to a scheme file.
55+
- `None` otherwise.
56+
57+
See `Scheme`.
58+
"""
59+
if not identifier:
60+
return self.DEFAULT_SCHEME_PATH
61+
62+
path: Path = self.SCHEME_PATH / (identifier + ".yml")
63+
if path.is_file():
64+
return path
65+
66+
path = Path(identifier)
67+
if path.is_file():
68+
return path
69+
70+
return None
71+
4372
def get_icons_by_id_path(self) -> Path:
4473
"""Directory for the icon files named by identifiers."""
4574
return check_and_create(self._icons_by_id_path)

0 commit comments

Comments
 (0)