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

_iterable(arg)

Make an argument iterable. Allows for more generalized inputs to these

cat(src[, dst])

Concatenate files and print to standard output or write to file

cd(path)

Change directory to path

cp(src, dst)

Copy files

hostname()

Check the system's hostname

ln(src, dst)

Make a symbolic link between files

ls([path, show_all])

List directory contents, option to show hidden files

mkdir(dirs)

Make directory or directories

mv(src, dst)

Move contents from src to dst

rename(old, new, names)

Rename multiple files

rm(path)

Remove files or directories

select(items[, prompt])

Monitor file descriptors, waiting for one or more descriptor to be "ready"

touch(filename[, times])

Update timestamps on files

which(name)

Shows the full path of shell commands and executables

nproc()

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