drivecasa.utils - Miscellaneous subroutines¶
Co-erce unicode to ‘bytestring’
(or string containing unicode, or dict containing unicode) Useful when e.g. importing filenames from JSON (CASA sometimes breaks if passed Unicode strings.)
derive_out_path(in_paths, out_dir, out_extension='', strip_in_extension=True, out_prefix=None)¶
Derives an ‘output’ path given some ‘input’ paths and an output directory.
In the simple case that only a single path is supplied, this is simply the pathname resulting from replacing extension suffix and moving dir, e.g.
If the out_dir is specified as ‘None’ then it is assumed that the new file should be located in the same directory as the first input path.
In the case that multiple input paths are supplied, their basenames are concatenated, e.g.
If the resulting output path is identical to any input path, this raises an exception.
NB the extension should be supplied including the ‘.’ prefix.
Ensure directory exists.
Roughly equivalent to mkdir -p
Ensure x is a (non-string) iterable; if not, enclose in a list.
Returns: x or [x], accordingly.
Save a list of casa commands as a text file