Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Aug 12, 2024
1 parent ce2e4d4 commit dc7e828
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/uwtools/api/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from iotaa import Asset

from uwtools.file import Copier, DirectoryStager, Linker
from uwtools.file import Copier, Linker, MkDir
from uwtools.utils.api import ensure_data_source as _ensure_data_source


Expand Down Expand Up @@ -99,7 +99,7 @@ def mkdir(
:param stdin_ok: OK to read from ``stdin``?
:return: ``True`` if all directories were made.
"""
stager = DirectoryStager(
stager = MkDir(
target_dir=Path(target_dir) if target_dir else None,
config=_ensure_data_source(config, stdin_ok),
cycle=cycle,
Expand All @@ -111,4 +111,4 @@ def mkdir(
return all(asset.ready() for asset in assets)


__all__ = ["Copier", "DirectoryStager", "Linker", "copy", "link", "mkdir"]
__all__ = ["Copier", "Linker", "MkDir", "copy", "link", "mkdir"]
64 changes: 32 additions & 32 deletions src/uwtools/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,6 @@ def _validate(self) -> None:
validate_internal(schema_name=self._schema, config=self._config)


class DirectoryStager(Stager):
"""
Make directories.
"""

@tasks
def go(self):
"""
Make directories.
"""
yield "Directories"
yield [
directory(path=Path(self._target_dir / p if self._target_dir else p))
for p in self._config[STR.mkdir]
]

@property
def _dst_paths(self) -> list[str]:
"""
Returns the paths to directories to create.
"""
paths: list[str] = self._config[STR.mkdir]
return paths

@property
def _schema(self) -> str:
"""
Returns the name of the schema to use for config validation.
"""
return "mkdir"


class FileStager(Stager):
"""
Stage files.
Expand Down Expand Up @@ -194,3 +162,35 @@ def go(self):
linkname = lambda k: Path(self._target_dir / k if self._target_dir else k)
yield "File links"
yield [symlink(target=Path(v), linkname=linkname(k)) for k, v in self._config.items()]


class MkDir(Stager):
"""
Make directories.
"""

@tasks
def go(self):
"""
Make directories.
"""
yield "Directories"
yield [
directory(path=Path(self._target_dir / p if self._target_dir else p))
for p in self._config[STR.mkdir]
]

@property
def _dst_paths(self) -> list[str]:
"""
Returns the paths to directories to create.
"""
paths: list[str] = self._config[STR.mkdir]
return paths

@property
def _schema(self) -> str:
"""
Returns the name of the schema to use for config validation.
"""
return "mkdir"

0 comments on commit dc7e828

Please sign in to comment.