def init_taurus_args(parser=None, args=None, values=None): """Parses the command line using :func:`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. :param parser: an option parser or None (default) to create a new parser :type parser: :class:`optparse.OptionParser` :param args: the list of arguments to process (default is None meaning: sys.argv[1:]) :type args: seq<str> :param values: a :class:`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 :return: a tuple of three elements: parser, options, args :rtype: :class:`optparse.OptionParser`, :class:`optparse.Values`, seq<str> """ import taurus parser, options, args = parse_taurus_args(parser=parser, args=args, values=values) # initialize taurus log level log_level_str = options.taurus_log_level.capitalize() if hasattr(taurus, log_level_str): log_level = getattr(taurus, log_level_str) taurus.setLogLevel(log_level) # initialize tango host if options.tango_host is not None: tango_factory = taurus.Factory("tango") tango_host = options.tango_host tango_factory.set_default_tango_host(tango_host) # initialize taurus polling period if options.taurus_polling_period is not None: taurus.Manager().changeDefaultPollingPeriod( options.taurus_polling_period) # initialize taurus serialization mode if options.taurus_serialization_mode is not None: import taurus.core.taurusbasetypes SerMode = taurus.core.taurusbasetypes.TaurusSerializationMode m = options.taurus_serialization_mode.capitalize() if hasattr(SerMode, m): m = getattr(SerMode, m) taurus.Manager().setSerializationMode(m) # initialize remote console port if options.remote_console_port is not None: try: import rfoo.utils.rconsole rfoo.utils.rconsole.spawn_server(port=options.remote_console_port) taurus.info( "rconsole started. You can connect to it by typing: rconsole -p %d", options.remote_console_port) except Exception, e: taurus.warning("Cannot spawn debugger. Reason: %s", str(e))
def taurus_cmd(log_level, polling_period, serialization_mode, rconsole_port, default_formatter): """The main taurus command""" # set log level taurus.setLogLevel(getattr(taurus, log_level)) # set polling period if polling_period is not None: taurus.changeDefaultPollingPeriod(polling_period) # set serialization mode if serialization_mode is not None: from taurus.core.taurusbasetypes import TaurusSerializationMode m = getattr(TaurusSerializationMode, serialization_mode) taurus.Manager().setSerializationMode(m) # enable the remote console port if rconsole_port is not None: try: import rfoo.utils.rconsole rfoo.utils.rconsole.spawn_server(port=rconsole_port) taurus.info(("rconsole started. " + "You can connect to it by typing: rconsole -p %d"), rconsole_port) except Exception as e: taurus.warning("Cannot spawn debugger. Reason: %s", e) # set the default formatter if default_formatter is not None: from taurus import tauruscustomsettings setattr(tauruscustomsettings, 'DEFAULT_FORMATTER', default_formatter)
def isValid(self, name=None, expected=True, elementType=None, strict=True, skip=False, skipmsg='Test explicitly disabled'): '''Helper method to test validity or invalidity of taurus URIs''' if skip: self.skipTest(skipmsg) if elementType is None: elementName = '<any>' else: elementName = TaurusElementType.whatis(elementType) elementType = [elementType] manager = taurus.Manager() scheme = manager.getScheme(name) supportedSchemes = manager.getPlugins().keys() if scheme not in supportedSchemes: self.skipTest('"%s" scheme not supported' % scheme) returned = taurus.isValidName(name, etypes=elementType, strict=strict) msg = ( 'isValidName returns %s (expected %s for name=%s and etype=%s)' % (returned, expected, name, elementName)) self.assertEqual(returned, expected, msg)
def addAttribute(self, attribute, auto_start=True): """Registers the attribute in this polling. :param attribute: (taurus.core.taurusattribute.TaurusAttribute) the attribute to be added :param auto_start: (bool) if True (default) it tells the polling timer that it should startup as soon as there is at least one attribute registered. """ with self.lock: dev, attr_name = attribute.getParentObj(), attribute.getSimpleName( ) attr_dict = self.dev_dict.get(dev) if attr_dict is None: if attribute.factory().caseSensitive: self.dev_dict[ dev] = attr_dict = weakref.WeakValueDictionary() else: self.dev_dict[dev] = attr_dict = CaselessWeakValueDict() if attr_name not in attr_dict: attr_dict[attr_name] = attribute self.attr_nb += 1 if self.attr_nb == 1 and auto_start: self.start() else: import taurus taurus.Manager().enqueueJob(attribute.poll)
def get_object(self, name=None, klass=None): '''check if Authority returns the expected type''' if klass is None: klass = TaurusAuthority manager = taurus.Manager() scheme = manager.getScheme(name) supportedSchemes = manager.getPlugins().keys() if scheme not in supportedSchemes: self.skipTest('"%s" scheme not supported' % scheme) a = taurus.Authority(name) msg = ('%s("%s") is not an instance of %s (it is %s)' % (taurus.Authority.__name__, name, klass.__name__, a.__class__.__name__)) self.assertTrue(isinstance(a, klass), msg)
def clean_up(): taurus.Manager().cleanUp()