PyFoam.RunDictionary.FileBasis module

Basis for the handling of OpenFOAM-files

Transparently accepts gnuzipped files

class PyFoam.RunDictionary.FileBasis.CleanCharactersFile(name, charsToRemove)[source]

Bases: PyFoam.RunDictionary.FileBasis.FileBasis

Read file and remove characters from the content

parse(cnt)[source]
class PyFoam.RunDictionary.FileBasis.FileBasis(name, createZipped=True, useBinary=False)[source]

Bases: PyFoam.Basics.Utilities.Utilities

Base class for the other OpenFOAM–file-classes

addedString = '//PyFoamAdded'

Comment for lines that were added by PyFoam-routines

baseName()[source]

Returns the basic file name (without .gz)

closeFile()[source]

closes the file

copyRest(l, out)[source]

Copy the rest of the file

Parameters:
  • l – a LineReader object
  • out – filehandle to echo the lines to
encode(txt)[source]

Encode a string to byte if necessary (for Python3)

getCaseDir()[source]

Return the path to the case of this file (if any valid case is found). Else return None

goMatch(l, exp, out=None, stop=None)[source]

Read lines until a regular expression is matched

Parameters:
  • l – a LineReader object
  • exp – the expression to look for
  • out – filehandle to echo the lines to
  • stop – pattern that indicates that exp will never be found
Returns:

match-object if exp is found, the line if stop is found and None if the end of the file is reached

goTo(l, s, out=None, echoLast=False, stop=None)[source]

Read lines until a token is found

Parameters:
  • l – a LineReader object
  • s – the string to look for
  • out – filehandle to echo the lines to
  • stop – pattern that indicates that exp will never be found (only passed through to goMatch)
  • echoLast – echo the line with the string
makeTemp()[source]

creates a temporary file

openFile(keepContent=False, mode='r')[source]

opens the file. To be overloaded by derived classes

parse(cnt)[source]

Parse a string that is to be the content, to be overriden by the sub-classes

purgeFile()[source]

Undo all the manipulations done by PyFOAM

Goes through the file and removes all lines that were added

readFile()[source]

read the whole File into memory

realName()[source]

The full filename with appended .gz (if zipped)

removedString = '//PyFoamRemoved: '

Comment for lines that were overwritten by PyFoam-routines

writeEncoded(out, txt)[source]

Convert the text to ‘bytes’ is we encounter a zipped file

writeFile(content=None)[source]

write the whole File from memory :param content: content that should replace the old content

writeFileAs(name)[source]

Writes a copy of the file. Extends with .gz if the original is zipped :param name: Name under which the file is written

class PyFoam.RunDictionary.FileBasis.FileBasisBackup(name, backup=False, createZipped=True, useBinary=False)[source]

Bases: PyFoam.RunDictionary.FileBasis.FileBasis

A file with a backup-copy

counter = {}
restore()[source]

if a backup-copy was made the file is restored from this

PyFoam.RunDictionary.FileBasis.exists(name)[source]