drivecasa.utils - Miscellaneous subroutines

drivecasa.utils.byteify(input)[source]

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.)

cf http://stackoverflow.com/a/13105359/725650

drivecasa.utils.derive_out_path(in_paths, out_dir, out_extension='', strip_in_extension=True, out_prefix=None)[source]

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.

input_dir/basename.in -> output_dir/basename.out

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.

in_dir/base1.in + in_dir/base2.in
-> out_dir/base1_base2.out

If the resulting output path is identical to any input path, this raises an exception.

NB the extension should be supplied including the ‘.’ prefix.

drivecasa.utils.ensure_dir(dirname)[source]

Ensure directory exists.

Roughly equivalent to mkdir -p

drivecasa.utils.listify(x)[source]

Ensure x is a (non-string) iterable; if not, enclose in a list.

Returns:x or [x], accordingly.
drivecasa.utils.save_script(script, filename)[source]

Save a list of casa commands as a text file