seisflows.tools.unix
Unix functions wrapped in Python3. Used to simplify function calling and provide a uniform look to SeisFlows source code. These Python functions are meant to mimic commonly-used shell commands.
Module Contents
Functions
|
Make an argument iterable. Allows for more generalized inputs to these |
|
Concatenate files and print to standard output or write to file |
|
Change directory to path |
|
Copy files |
|
Check the system's hostname |
|
Make a symbolic link between files |
|
List directory contents, option to show hidden files |
|
Make directory or directories |
|
Move contents from src to dst |
|
Rename multiple files |
|
Remove files or directories |
|
Monitor file descriptors, waiting for one or more descriptor to be "ready" |
|
Update timestamps on files |
|
Shows the full path of shell commands and executables |
|
Get the number of processors available. Same as calling 'nproc' from |
- seisflows.tools.unix._iterable(arg)
Make an argument iterable. Allows for more generalized inputs to these unix-style functions.
- Parameters
arg (anything) – an argument to make iterable
- Return type
list
- Returns
iterable argument
- seisflows.tools.unix.cat(src, dst=None)
Concatenate files and print to standard output or write to file
- Parameters
src (str) – file to read
dst (str) – file to write contents to
- seisflows.tools.unix.cd(path)
Change directory to path
- Parameters
path (str) – path to change directory to
- seisflows.tools.unix.cp(src, dst)
Copy files
- Parameters
src (str or list or tuple) – source to copy from
dst (str) – destination to copy to
- seisflows.tools.unix.hostname()
Check the system’s hostname
- Return type
str
- Returns
system hostname
- seisflows.tools.unix.ln(src, dst)
Make a symbolic link between files
>>> from seisflows.tools.unix import ln >>> ln(“example_file”, “path/to/sylink/new_filename”) >>> # OR >>> ln(“example_file”, “path/to/sylink/”)
- Parameters
src (str) – path to file or directory to symlink
dst (str) – path or file to symlink src to
- seisflows.tools.unix.ls(path=os.getcwd(), show_all=False)
List directory contents, option to show hidden files
- Parameters
path (str) – path to list directory contents
- Param
if True, shows hidden files (starting with ‘.’), same as the -a or –all in shell ls command
- seisflows.tools.unix.mkdir(dirs)
Make directory or directories
Note
Random wait times to prevent overloading disk when multiple subprocesses are running mkdir
- Parameters
dirs (str or list) – pathnames to make
- seisflows.tools.unix.mv(src, dst)
Move contents from src to dst
- Parameters
src (str or list or tuple) – input file(s) to move
dst (str) – location to move path to
- seisflows.tools.unix.rename(old, new, names)
Rename multiple files
- Parameters
old (str) – expression to replace
new (str) – replacement expression
names (list) – files to replace expressions in
- seisflows.tools.unix.rm(path)
Remove files or directories
- seisflows.tools.unix.select(items, prompt='')
Monitor file descriptors, waiting for one or more descriptor to be “ready”
- seisflows.tools.unix.touch(filename, times=None)
Update timestamps on files
- Parameters
filename (str) – file to touch
times (None or (atime, mtime)) – if None, set time to current time, otherwise (accesstime, modifiedtime) need to be set
- seisflows.tools.unix.which(name)
Shows the full path of shell commands and executables
- Parameters
name (str) – name of shell command to check
- seisflows.tools.unix.nproc()
Get the number of processors available. Same as calling ‘nproc’ from Linux command line.
TODO replace all instances of nproc() with os.cpu_count()
- Return type
int
- Returns
number of processors
- Raises
EnvironmentError – if nproc cannot be determined