taurus.core.util.argparse

Helper command line parser for taurus based on optparse. Suppose you have an application file:

import sys
from PyQt4 import Qt


class GUI(Qt.QMainWindow):
    pass


def main():
    import taurus.core.util.argparse as argparse

    parser, options, args = argparse.init_taurus_args()

    app = Qt.QApplication(sys.argv)
    w = GUI()
    w.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

The call to taurus.core.util.argparse.init_taurus_args() will initialize taurus environment based on the command line options given by the user. Currently, the known options are:

  1. --help prints the total number of available options

  2. --taurus-log-level sets the taurus log level

  3. --tango-host sets the default tango host

  4. --taurus-polling-period sets the default taurus global polling period (milliseconds)

  5. --taurus-serialization-mode sets the default taurus serialization mode

  6. --remote-console-port enables remote debugging using the given port

You can easily extend the taurus options with your application specific options. Suppose you want to add an option like --model=<model name>:

def main():
    import taurus.core.util.argparse as argparse
    parser = argparse.get_taurus_parser(parser=parser)
    parser.set_usage("%prog [options] <special item>")
    parser.set_description("my own GUI application")
    parser.add_option("--model")

    parser, options, args = argparse.init_taurus_args(parser=parser)

    app = Qt.QApplication(sys.argv)
    w = GUI()
    w.show()
    sys.exit(app.exec_())

Functions

get_taurus_parser(parser=None)[source]

Returns a optparse.OptionParser initialized with a optparse.OptionGroup containning some taurus options. If a parser is given as parameter then it uses this parser instead of creating a new one.

Parameters

parser (optparse.OptionParser) – an option parser or None (default) to create a new parser

Returns

an option parser or the given parser if it is not None

Return type

optparse.OptionParser

init_taurus_args(parser=None, args=None, values=None)[source]

Parses the command line using taurus.core.util.argparse.parse_taurus_args().

After the command line is parsed, actions are taken on each recognized parameter. For example, the taurus log level and the default tango host are set accordingly.

Parameters
  • parser (optparse.OptionParser) – an option parser or None (default) to create a new parser

  • args (seq<str>) – the list of arguments to process (default is None meaning: sys.argv[1:])

  • values – a optparse.Values object to store option arguments in (default is None meaning: a new instance of Values) - if you give an existing object, the option defaults will not be initialized on it

Returns

a tuple of three elements: parser, options, args

Return type

optparse.OptionParser, optparse.Values, seq<str>

parse_taurus_args(parser=None, args=None, values=None)[source]

Parses the command line. If parser is not given, then a new parser is created. In any case, the parser is initialized using the taurus.core.util.argparse.get_taurus_parser(). args and values are the optional parameters that will be given when executing optparse.OptionParser.parse_args().

Parameters
  • parser (optparse.OptionParser) – an option parser or None (default) to create a new parser

  • args (seq<str>) – the list of arguments to process (default is None meaning: sys.argv[1:])

  • values – a optparse.Values object to store option arguments in (default is None meaning: a new instance of Values) - if you give an existing object, the option defaults will not be initialized on it

Returns

a tuple of three elements: parser, options, args

Return type

optparse.OptionParser, optparse.Values, seq<str>

split_taurus_args(parser, args=None)[source]

Splits arguments into valid parser arguments and non valid parser arguments.

Parameters
  • parser (optparse.OptionParser) – an option parser

  • args (seq<str>) – the list of arguments to process (default is None meaning: sys.argv)

Returns

a tuple of two elements: parser args, non parser args

Return type

seq<seq<str>, seq<str>>