utils.system

Collection of system-related utilities.

ximpol.utils.system_.cleanup(dir_path)[source]

Remove all the files in a given folder.

ximpol.utils.system_.cmd(cmd, verbose=False, log_file_path=None, log_file_mode='w', dry_run=False)[source]

Exec a system command.

This uses subprocess internally and returns the subprocess status code (if the dry_run option is true the function will just print the command out through the logger and returns happily).

By default the stdout and the stderr are redirected into subprocess pipes so that the output can be effectively used by the logger. It the log_file_path parameter is different from None the stdout is redirected to file instead. The rules are:

  • if verbose is True the command output is logged onto the terminal one line at a time;
  • if the status code is zero we just aknowledge that before returning it;
  • upon error we try and log out both the error code and the error message.