The commandline module

A collection of tools for interacting with the command line.

Notes

The contents of this module have not been tested in Windows.

Classes

Environment

class src.tools.commandline.Environment[source]

A class representing a shell session.

In its present implementation, this class can only be expected to work properly in Linux.

Methods

changeDirectory(directory)[source]

Change the working directory.

Parameters :

directory : str

The new working directory as a string.

communicate(command, shell=True)[source]

Send a command and read the response.

Parameters :

command : str

The command to execute.

shell : bool

Whether to run in the system shell.

Returns :

str :

The standard output (STDOUT) for the process.

copy(source, target, recursive=True)[source]

Copy a file or folder.

Parameters :

source : str

The path of the file or folder to copy.

target : str

The path to which the file should be copied.

recursive : bool

If source is a folder, whether to copy all of its contents recursively.

Notes

If recursive is not set and source is a folder with contents, the operation will fail.

extendPath(name, value, start=True, forceReplace=False)[source]

Extend a path-like environment variable.

Parameters :

name : str

The name of the environment variable to extend. In this application, it will often be “PYTHONPATH”.

value : str

The value to append to the path.

start : bool

Whether to prepend the new component to the variable. If False, the new component will be appended.

forceReplace : bool

Whether to change the variable if it already has a value set.

classmethod isWindows()[source]

Determine whether the operating system is Windows.

move(source, target, force=False)[source]

Move a file or folder.

Parameters :

source : str

The path of the file or folder to move.

target : str

Where the file or folder should be moved.

force : bool

Whether to overwrite files without prompting or failing. The default is False.

moveDirectoryContents(source, target, force=False)[source]

Move the contents of a directory from one location to another.

Parameters :

source : str

The path of the folder whose contents should be moved.

target : str

The path of the folder into which the files should be moved.

force : bool

Whether to automatically overwrite file conflicts. The default is False.

remove(fileName)[source]

Remove a regular file.

Parameters :

fileName : str

The path of the file to delete.

removeDirectory(directory, recursive=True)[source]

Remove a directory.

Parameters :

directory : str

The path of the directory to remove.

recursive : bool

Whether to recursively remove all sub-materials.

removeDirectoryContents(directory, filesOnly=True, ignoreHidden=True)[source]

Remove the contents of a directory.

Parameters :

directory : str

The path of the directory whose contents should be removed.

filesOnly : bool

Whether to delete only regular files (i.e. ignore subfolders). The default is True.

ignoreHidden : bool

Whether to ignore hidden files and folders. The default is True.

setPath(name, value)[source]

Set a path-like variable.

Parameters :

name : str

The name of the environment variable to extend. In this application, it will often be “PYTHONPATH”.

value : str

The value to append to the path.

Table Of Contents

Previous topic

The expt_loader module

Next topic

The instrospection module

This Page