PyFoam.Basics.Utilities module

Utility functions

Can be used via a class or as functions

class PyFoam.Basics.Utilities.Utilities[source]

Bases: object

Class with utility methods

Can be inherited without side effects by classes that need these methods

__dict__ = dict_proxy({'copyfile': <function copyfile>, '__module__': 'PyFoam.Basics.Utilities', 'humanReadableDuration': <function humanReadableDuration>, 'rmtree': <function rmtree>, 'copytree': <function copytree>, '__dict__': <attribute '__dict__' of 'Utilities' objects>, 'humanReadableSize': <function humanReadableSize>, '__weakref__': <attribute '__weakref__' of 'Utilities' objects>, 'find': <function find>, 'excludeNames': ['^.svn$', '~$'], 'writeDictionaryHeader': <function writeDictionaryHeader>, 'execute': <function execute>, 'findFileInDir': <function findFileInDir>, 'remove': <function remove>, 'listDirectory': <function listDirectory>, '__init__': <function __init__>, 'which': <function which>, 'diskUsage': <function diskUsage>, '__doc__': 'Class with utility methods\n\n Can be inherited without side effects by classes that need these\n methods'})
__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'PyFoam.Basics.Utilities'
__weakref__

list of weak references to the object (if defined)

copyfile(src, dst)[source]

Encapsulates the shutil copyfile and provides an alternative for old Python-version

copytree(src, dst, symlinks=False, force=False)[source]

Encapsulates the shutil copytree and provides an alternative for old Python-version

diskUsage(fpath)[source]

Calculate the disk space used at the specified path in bytes

excludeNames = ['^.svn$', '~$']
execute(cmd, debug=False, workdir=None, echo=None, outfile=None, getReturnCode=False)[source]

Execute the command cmd. If specified change the working directory

Currently no error-handling is done :return: A list with all the output-lines of the execution

find(pattern, path, directoriesToo=True)[source]

Find all files whose names match :param pattern: glob-style pattern :param path: path under which this files are to be searched :param directoriesToo: also match directories?

findFileInDir(dName, fName)[source]

Find file in a directory (search recursively) :param dName: name of the directory :param fName: name of the file to look force :return: the complete path. Directory and path joined if nothing is found

humanReadableDuration(num)[source]

Creates a string that prints a duration in an easily readable form. Easily readable means that the two highest non-zero values will be printed

humanReadableSize(num)[source]

Lifted from http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size Gets a number in bytes and returns a human readable string

listDirectory(d)[source]

Lists the files in a directory, but excludes certain names and files with certain endings :param d: The directory to list :return: List of the found files and directories

remove(f)[source]

Remove a file if it exists.

rmtree(dst, ignore_errors=False)[source]

Encapsulates the shutil rmtree and provides an alternative for old Python-version

which(progname)[source]

Get the full path. Return None if not found

writeDictionaryHeader(f)[source]

Writes a dummy header so OpenFOAM accepts the file as a dictionary :param f: The file to write to :type f: file

PyFoam.Basics.Utilities.copyfile(src, dest)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.copytree(src, dest, symlinks=False, force=False)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.diskUsage(fpath)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.execute(cmd, debug=False, workdir=None, echo=None, outfile=None, getReturnCode=False)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.find(pattern, path, directoriesToo=True)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.findFileInDir(d, f)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.humanReadableDuration(num)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.humanReadableSize(num)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.listDirectory(d)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.remove(f)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.rmtree(path, ignore_errors=False)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.which(prog)[source]

Calls the method of the same name from the Utilites class

PyFoam.Basics.Utilities.writeDictionaryHeader(f)[source]

Calls the method of the same name from the Utilites class