Refactor workspace usage.

This commit is contained in:
Sergey Vartanov 2021-08-09 09:44:34 +10:00
parent 2487e24c90
commit f9409e2f47
8 changed files with 65 additions and 72 deletions

View file

@ -12,7 +12,7 @@ import logging
import numpy as np import numpy as np
import svgwrite import svgwrite
from roentgen import workspace from roentgen.workspace import workspace
from roentgen import server, tile from roentgen import server, tile
from roentgen.constructor import Constructor from roentgen.constructor import Constructor
from roentgen.flinger import Flinger from roentgen.flinger import Flinger

View file

@ -10,7 +10,7 @@ import numpy as np
from colour import Color from colour import Color
from svgwrite import Drawing from svgwrite import Drawing
from roentgen import workspace from roentgen.workspace import workspace
from roentgen.icon import Icon, Shape, ShapeExtractor, ShapeSpecification from roentgen.icon import Icon, Shape, ShapeExtractor, ShapeSpecification
from roentgen.scheme import NodeMatcher, Scheme from roentgen.scheme import NodeMatcher, Scheme
@ -199,13 +199,9 @@ def draw_icons() -> None:
Draw all possible icon shapes combinations as grid in one SVG file and as Draw all possible icon shapes combinations as grid in one SVG file and as
individual SVG files. individual SVG files.
""" """
out_path: Path = workspace.get_output_path()
icons_by_id_path: Path = workspace.get_icons_by_id_path() icons_by_id_path: Path = workspace.get_icons_by_id_path()
icons_by_name_path: Path = workspace.get_icons_by_name_path() icons_by_name_path: Path = workspace.get_icons_by_name_path()
for path in (out_path, icons_by_id_path, icons_by_name_path):
path.mkdir(parents=True, exist_ok=True)
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH) scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
extractor: ShapeExtractor = ShapeExtractor( extractor: ShapeExtractor = ShapeExtractor(
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH

View file

@ -7,7 +7,7 @@ from typing import List, Optional, Dict
import logging import logging
from colour import Color from colour import Color
from roentgen import workspace from roentgen.workspace import workspace
from roentgen.grid import IconCollection from roentgen.grid import IconCollection
from roentgen.icon import ShapeExtractor from roentgen.icon import ShapeExtractor
from roentgen.osm_reader import STAGES_OF_DECAY from roentgen.osm_reader import STAGES_OF_DECAY

View file

@ -7,7 +7,7 @@ from abc import ABC
from moire.moire import Tag from moire.moire import Tag
from moire.default import Default, DefaultHTML, DefaultMarkdown, DefaultWiki from moire.default import Default, DefaultHTML, DefaultMarkdown, DefaultWiki
from roentgen import workspace from roentgen.workspace import workspace
from roentgen.icon import ShapeExtractor from roentgen.icon import ShapeExtractor
from pathlib import Path from pathlib import Path
from typing import Dict, List, Any, Union from typing import Dict, List, Any, Union

View file

@ -3,7 +3,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from roentgen import workspace from roentgen.workspace import workspace
from roentgen.raster import rasterize from roentgen.raster import rasterize
from roentgen.tile import Tile from roentgen.tile import Tile

View file

@ -10,7 +10,7 @@ from typing import List
import logging import logging
from roentgen import workspace from roentgen.workspace import workspace
from roentgen import ( from roentgen import (
__doc_url__, __doc_url__,
__project__, __project__,

View file

@ -12,7 +12,7 @@ from typing import List, Optional, Tuple
import numpy as np import numpy as np
import svgwrite import svgwrite
from roentgen import workspace from roentgen.workspace import workspace
from roentgen.constructor import Constructor from roentgen.constructor import Constructor
from roentgen.flinger import Flinger from roentgen.flinger import Flinger
from roentgen.icon import ShapeExtractor from roentgen.icon import ShapeExtractor

View file

@ -3,26 +3,6 @@ File and directory path in the project.
""" """
from pathlib import Path from pathlib import Path
# Project directories and files, that are the part of the repository.
SCHEME_PATH: Path = Path("scheme")
DEFAULT_SCHEME_PATH: Path = SCHEME_PATH / "default.yml"
ICONS_PATH: Path = Path("icons/icons.svg")
ICONS_CONFIG_PATH: Path = Path("icons/config.json")
GITHUB_TEST_PATH: Path = Path(".github/workflows/test.yml")
DATA_PATH: Path = Path("data")
MAPCSS_PART_FILE_PATH: Path = DATA_PATH / "roentgen_icons_part.mapcss"
# Generated directories and files.
_OUTPUT_PATH: Path = Path("out")
_ICONS_BY_ID_PATH: Path = _OUTPUT_PATH / "icons_by_id"
_ICONS_BY_NAME_PATH: Path = _OUTPUT_PATH / "icons_by_name"
_MAPCSS_PATH: Path = _OUTPUT_PATH / "roentgen_icons_mapcss"
_TILE_PATH: Path = _OUTPUT_PATH / "tiles"
MAPCSS_ICONS_DIRECTORY_NAME: str = "icons"
def check_and_create(directory: Path) -> Path: def check_and_create(directory: Path) -> Path:
"""Create directory if it doesn't exist and return it.""" """Create directory if it doesn't exist and return it."""
@ -31,46 +11,63 @@ def check_and_create(directory: Path) -> Path:
return directory return directory
def get_output_path() -> Path: class Workspace:
"""Path for generated files.""" # Project directories and files, that are the part of the repository.
return check_and_create(_OUTPUT_PATH)
SCHEME_PATH: Path = Path("scheme")
DEFAULT_SCHEME_PATH: Path = SCHEME_PATH / "default.yml"
ICONS_PATH: Path = Path("icons/icons.svg")
ICONS_CONFIG_PATH: Path = Path("icons/config.json")
GITHUB_TEST_PATH: Path = Path(".github/workflows/test.yml")
DATA_PATH: Path = Path("data")
MAPCSS_PART_FILE_PATH: Path = DATA_PATH / "roentgen_icons_part.mapcss"
# Generated directories and files.
MAPCSS_ICONS_DIRECTORY_NAME: str = "icons"
def __init__(self, output_path: Path):
self.output_path: Path = output_path
check_and_create(output_path)
self._icons_by_id_path: Path = output_path / "icons_by_id"
self._icons_by_name_path: Path = output_path / "icons_by_name"
self._mapcss_path: Path = output_path / "roentgen_icons_mapcss"
self._tile_path: Path = output_path / "tiles"
def get_icons_by_id_path(self) -> Path:
"""Directory for the icon files named by identifiers."""
return check_and_create(self._icons_by_id_path)
def get_icons_by_name_path(self) -> Path:
"""Directory for the icon files named by human-readable names."""
return check_and_create(self._icons_by_name_path)
def get_tile_path(self) -> Path:
"""Directory for tiles."""
return check_and_create(self._tile_path)
def get_mapcss_path(self) -> Path:
"""Directory for MapCSS files."""
return check_and_create(self._mapcss_path)
def get_mapcss_file_path(self) -> Path:
"""Directory for MapCSS files."""
return self.get_mapcss_path() / "roentgen_icons.mapcss"
def get_mapcss_icons_path(self) -> Path:
"""Directory for icons used by MapCSS file."""
return check_and_create(
self.get_mapcss_path() / self.MAPCSS_ICONS_DIRECTORY_NAME
)
def get_icon_grid_path(self) -> Path:
"""Icon grid path."""
return self.output_path / "icon_grid.svg"
def get_taginfo_file_path(self) -> Path:
"""Path to file with project information for Taginfo."""
return self.output_path / "roentgen_taginfo.json"
def get_icons_by_id_path() -> Path: workspace = Workspace(Path("out"))
"""Directory for the icon files named by identifiers."""
return check_and_create(_ICONS_BY_ID_PATH)
def get_icons_by_name_path() -> Path:
"""Directory for the icon files named by human-readable names."""
return check_and_create(_ICONS_BY_NAME_PATH)
def get_tile_path() -> Path:
"""Directory for tiles."""
return check_and_create(_TILE_PATH)
def get_mapcss_path() -> Path:
"""Directory for MapCSS files."""
return check_and_create(_MAPCSS_PATH)
def get_mapcss_file_path() -> Path:
"""Directory for MapCSS files."""
return get_mapcss_path() / "roentgen_icons.mapcss"
def get_mapcss_icons_path() -> Path:
"""Directory for icons used by MapCSS file."""
return check_and_create(get_mapcss_path() / MAPCSS_ICONS_DIRECTORY_NAME)
def get_icon_grid_path() -> Path:
"""Icon grid path."""
return get_output_path() / "icon_grid.svg"
def get_taginfo_file_path() -> Path:
"""Path to file with project information for Taginfo."""
return get_output_path() / "roentgen_taginfo.json"