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:
--helpprints the total number of available options--taurus-log-levelsets the taurus log level--tango-hostsets the default tango host--taurus-polling-periodsets the default taurus global polling period (milliseconds)--taurus-serialization-modesets the default taurus serialization mode--remote-console-portenables 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.OptionParserinitialized with aoptparse.OptionGroupcontainning 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 parserReturns: 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.Valuesobject 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>- parser (
-
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 executingoptparse.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.Valuesobject 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>- parser (
-
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>>
- parser (