Skip to content

Commit b65c563

Browse files
committed
Add pathtools.derive_out_dir()
1 parent 92b9b2f commit b65c563

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/imcflibs/pathtools.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from os import sep
55
import os.path
66

7+
from .log import LOG as log
8+
79

810
def parse_path(path):
911
"""Parse a path into its components.
@@ -150,6 +152,34 @@ def gen_name_from_orig(path, orig_name, tag, suffix):
150152
return name
151153

152154

155+
def derive_out_dir(in_dir, out_dir):
156+
"""Derive `out_dir` from its own value and the value of `in_dir`.
157+
158+
In case the supplied value of `out_dir` is one of '-' or 'NONE', the
159+
returned value will be set to `in_dir`. Otherwise the value of `out_dir`
160+
will be returned unchanged.
161+
162+
Parameters
163+
----------
164+
in_dir : str
165+
The full path to the input directory.
166+
out_dir : str
167+
Either the full path to an output directory or one of '-' or 'NONE'.
168+
169+
Returns
170+
-------
171+
str
172+
The full path to the directory to be used for output and temp files.
173+
"""
174+
if out_dir in ["-", "NONE"]:
175+
out_dir = in_dir
176+
log.info("No output directory given, using input dir [%s].", out_dir)
177+
else:
178+
log.info("Using directory [%s] for results and temp files.", out_dir)
179+
180+
return out_dir
181+
182+
153183
# pylint: disable-msg=C0103
154184
# we use the variable name 'exists' in its common spelling (lowercase), so
155185
# removing this workaround will be straightforward at a later point

0 commit comments

Comments
 (0)