pyemu.utils.os_utils
Operating system utilities in the PEST(++) realm
Module Contents
Functions
|
Function found from: |
|
remove readonly dirs, apparently only a windows issue |
|
an OS agnostic function to execute a command line |
|
|
|
|
|
start a group of pest(++) workers on the local machine |
Attributes
- pyemu.utils.os_utils.ext = ''
- pyemu.utils.os_utils.bin_path
- pyemu.utils.os_utils.bin_path
- pyemu.utils.os_utils.bin_path
- pyemu.utils.os_utils._istextfile(filename, blocksize=512)
Function found from: https://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python Returns True if file is most likely a text file Returns False if file is most likely a binary file Uses heuristics to guess whether the given file is text or binary, by reading a single block of bytes from the file. If more than 30% of the chars in the block are non-text, or there are NUL (’') bytes in the block, assume this is a binary file.
- pyemu.utils.os_utils._remove_readonly(func, path, excinfo)
remove readonly dirs, apparently only a windows issue add to all rmtree calls: shutil.rmtree(**,onerror=remove_readonly), wk
- pyemu.utils.os_utils.run(cmd_str, cwd='.', verbose=False)
an OS agnostic function to execute a command line
- Parameters:
cmd_str (str) – the str to execute with os.system()
cwd (str, optional) – the directory to execute the command in. Default is “.”.
verbose (bool, optional) – flag to echo to stdout the cmd_str. Default is False.
Notes
uses platform to detect OS and adds .exe suffix or ./ prefix as appropriate if os.system returns non-zero, an exception is raised
Example:
pyemu.os_utils.run("pestpp-ies my.pst",cwd="template")
- pyemu.utils.os_utils._try_remove_existing(d, forgive=False)
- pyemu.utils.os_utils._try_copy_dir(o_d, n_d)
- pyemu.utils.os_utils.start_workers(worker_dir, exe_rel_path, pst_rel_path, num_workers=None, worker_root='..', port=4004, rel_path=None, local=True, cleanup=True, master_dir=None, verbose=False, silent_master=False, reuse_master=False, restart=False)
start a group of pest(++) workers on the local machine
- Parameters:
worker_dir (str) – the path to a complete set of input files need by PEST(++). This directory will be copied to make worker (and optionally the master) directories
exe_rel_path (str) – the relative path to and name of the pest(++) executable from within the worker_dir. For example, if the executable is up one directory from worker_dir, the exe_rel_path would be os.path.join(“..”,”pestpp-ies”)
pst_rel_path (str) – the relative path to and name of the pest control file from within worker_dir.
num_workers (int, optional) – number of workers to start. defaults to number of cores
worker_root (str, optional) – the root directory to make the new worker directories in. Default is “..” (up one directory from where python is running).
rel_path (str, optional) – the relative path to where pest(++) should be run from within the worker_dir, defaults to the uppermost level of the worker dir. This option is usually not needed unless you are one of those crazy people who spreads files across countless subdirectories.
local (bool, optional) – flag for using “localhost” instead of actual hostname/IP address on worker command line. Default is True. local can also be passed as an str, in which case local is used as the hostname (for example local=”192.168.10.1”)
cleanup (bool, optional) – flag to remove worker directories once processes exit. Default is True. Set to False for debugging issues
master_dir (str) – name of directory for master instance. If master_dir exists, then it will be REMOVED!!! If master_dir, is None, no master instance will be started. If not None, a copy of worker_dir will be made into master_dir and the PEST(++) executable will be started in master mode in this directory. Default is None
verbose (bool, optional) – flag to echo useful information to stdout. Default is False
silent_master (bool, optional) – flag to pipe master output to devnull and instead print a simple message to stdout every few seconds. This is only for pestpp Travis testing so that log file sizes dont explode. Default is False
reuse_master (bool) – flag to use an existing master_dir as is - this is an advanced user option for cases where you want to construct your own master_dir then have an async process started in it by this function.
restart (bool) – flag to add a restart flag to the master start. If True, this will include /r in the master call string.
Notes
If all workers (and optionally master) exit gracefully, then the worker dirs will be removed unless cleanup is False
Example:
# start 10 workers using the directory "template" as the base case and # also start a master instance in a directory "master". pyemu.helpers.start_workers("template","pestpp-ies","pest.pst",10,master_dir="master", worker_root=".")