PyFoam.Basics.FoamOptionParser module

Parse options for the PyFoam-Scripts

class PyFoam.Basics.FoamOptionParser.FoamHelpFormatter(indent_increment=0, max_help_position=24, width=None, short_first=0)[source]

Bases: optparse.TitledHelpFormatter

For description and epilog preserve double newlines as one newline

__module__ = 'PyFoam.Basics.FoamOptionParser'
format_description(description)[source]
format_epilog(epilog)[source]
class PyFoam.Basics.FoamOptionParser.FoamOptionParser(args=None, usage=None, version=None, description=None, epilog=None, examples=None, interspersed=False)[source]

Bases: optparse.OptionParser

Wrapper to the usual OptionParser to honor the conventions of OpenFOAM-utilities

Options that are not used by the script are passed to the OpenFOAM-application

__init__(args=None, usage=None, version=None, description=None, epilog=None, examples=None, interspersed=False)[source]
Parameters
  • usage – usage string. If missing a default is used

  • version – if missing the PyFoam-version is used

  • description – description of the utility

  • epilog – Text to be displayed in the help after the options

  • examples – Usage examples to be displayed after the epilog

  • interspersed – needs to be false if options should be passed to an OpenFOAM-utility

  • args – Command line arguments. If unset sys.argv[1:] is used.

Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered)

__module__ = 'PyFoam.Basics.FoamOptionParser'
_buildKeyordArgumentList()[source]

Go through the lists of options and build a dictionary of keyword arguments (in CamelCase)

casePath()[source]

Returns the path to the case (if applicable)

getApplication()[source]

Return the OpenFOAM-Application to be run

getArgs()[source]

Return the arguments left after parsing

getOptions()[source]

Return the options

parse(nr=None, exactNr=True)[source]

parse the options :param nr: minimum number of arguments that are to be passed to the application 3 is default for pre-1.5 versions of OpenFOAM

processKeywordArguments(kw)[source]
restoreEnvironment()[source]

Restore the environment to its old glory… if it was changed

class PyFoam.Basics.FoamOptionParser.Subcommand(name, parser=None, help='', aliases=(), nr=None, exactNr=None)[source]

Bases: object

A subcommand of a root command-line application that may be invoked by a SubcommandOptionParser. Taken from https://gist.github.com/sampsyo/462717

__dict__ = mappingproxy({'__module__': 'PyFoam.Basics.FoamOptionParser', '__doc__': 'A subcommand of a root command-line application that may be\n invoked by a SubcommandOptionParser.\n Taken from https://gist.github.com/sampsyo/462717\n ', '__init__': <function Subcommand.__init__>, '__dict__': <attribute '__dict__' of 'Subcommand' objects>, '__weakref__': <attribute '__weakref__' of 'Subcommand' objects>})
__init__(name, parser=None, help='', aliases=(), nr=None, exactNr=None)[source]

Creates a new subcommand. name is the primary way to invoke the subcommand; aliases are alternate names. parser is an OptionParser responsible for parsing the subcommand’s options. help is a short description of the command. If no parser is given, it defaults to a new, empty OptionParser.

__module__ = 'PyFoam.Basics.FoamOptionParser'
__weakref__

list of weak references to the object (if defined)

class PyFoam.Basics.FoamOptionParser.SubcommandFoamOptionParser(args=None, usage=None, version=None, epilog=None, examples=None, description=None, subcommands=[])[source]

Bases: PyFoam.Basics.FoamOptionParser.FoamOptionParser

Subclass of the regular option parser that allows setting subcommands Inspired by https://gist.github.com/sampsyo/462717

_HelpSubcommand = <PyFoam.Basics.FoamOptionParser.Subcommand object>
__init__(args=None, usage=None, version=None, epilog=None, examples=None, description=None, subcommands=[])[source]
Parameters
  • usage – usage string. If missing a default is used

  • version – if missing the PyFoam-version is used

  • description – description of the utility

  • subcommands – list with subcommands to prepopulate the parser

  • args – Command line arguments. If unset sys.argv[1:] is used.

Can be a string: it will be splitted then unsing the spaces (very primitive), or a list of strings (prefered)

__module__ = 'PyFoam.Basics.FoamOptionParser'
_subcommand_for_name(name)[source]

Return the subcommand in self.subcommands matching the given name. The name may either be the name of a subcommand or an alias. If no subcommand matches, returns None.

addSubcommand(cmd, usage=None)[source]
format_help(formatter=None)[source]

Taken from https://gist.github.com/sampsyo/462717

getArgs()[source]

Return the arguments left after parsing

parse(nr=None, exactNr=None)[source]

Do the parsing of a subcommand