コード例 #1
0
def main():
    import taurus.qt.qtgui.application
    Application = taurus.qt.qtgui.application.TaurusApplication

    app = Application.instance()
    owns_app = app is None

    if owns_app:
        app = Application(app_name="Logging demo",
                          app_version="1.0",
                          org_domain="Taurus",
                          org_name="Taurus community")

    taurus.setLogLevel(taurus.Trace)
    taurus.disableLogOutput()
    w = QLoggingWidget()

    taurus.trace("trace message")
    taurus.debug("debug message")
    taurus.info("Hello world")
    taurus.warning("Warning message")
    taurus.error("error message")
    taurus.critical("critical message")
    w.setMinimumSize(1200, 600)
    w.show()
    app.exec_()
    w.stop_logging()
コード例 #2
0
ファイル: qlogtable.py プロジェクト: cmft/taurus
def main():
    import taurus.qt.qtgui.application
    Application = taurus.qt.qtgui.application.TaurusApplication

    app = Application.instance()
    owns_app = app is None

    if owns_app:
        app = Application(app_name="Logging demo", app_version="1.0",
                          org_domain="Taurus", org_name="Taurus community")

    taurus.setLogLevel(taurus.Trace)
    taurus.disableLogOutput()
    w = QLoggingWidget()

    taurus.trace("trace message")
    taurus.debug("debug message")
    taurus.info("Hello world")
    taurus.warning("Warning message")
    taurus.error("error message")
    taurus.critical("critical message")
    w.setMinimumSize(1200, 600)
    w.show()
    app.exec_()
    w.stop_logging()
コード例 #3
0
    def _getBackgroundColor(self):
        try:
            return self.plot_item.scene().parent().backgroundBrush().color()
        except Exception:
            import taurus

            taurus.debug("Cannot get plot background. Revert to 'default'")
            return "default"
コード例 #4
0
ファイル: evalvalidator.py プロジェクト: cmft/taurus
 def _expandRefNames(self, attrname):
     """Expand the refs in an eval name to their full names"""
     name = attrname
     for ref in self.getRefs(attrname, ign_quoted=True):
         manager = taurus.core.TaurusManager()
         scheme = manager.getScheme(ref)
         _f = taurus.Factory(scheme)
         attrNameValidator = _f.getAttributeNameValidator()
         full_name, _, _ = attrNameValidator.getNames(ref)
         if full_name is None:
             debug('Cannot expand the fullname of %s' % ref)
             return None
         name = self.replaceUnquotedRef(name, '{%s}' % ref,
                                        '{%s}' % full_name)
     return name
コード例 #5
0
 def _expandRefNames(self, attrname):
     """Expand the refs in an eval name to their full names"""
     name = attrname
     for ref in self.getRefs(attrname, ign_quoted=True):
         manager = taurus.core.TaurusManager()
         scheme = manager.getScheme(ref)
         _f = taurus.Factory(scheme)
         attrNameValidator = _f.getAttributeNameValidator()
         full_name, _, _ = attrNameValidator.getNames(ref)
         if full_name is None:
             debug('Cannot expand the fullname of %s' % ref)
             return None
         name = self.replaceUnquotedRef(name, '{%s}' % ref,
                                        '{%s}' % full_name)
     return name
コード例 #6
0
ファイル: evalvalidator.py プロジェクト: cmft/taurus
    def isValid(self, name, matchLevel=None, strict=None):
        '''reimplemented from :class:`TaurusAttributeNameValidator` to do extra
        check on references validity (recursive)
        '''
        # Standard implementation
        if matchLevel is not None:
            groups = self._isValidAtLevel(name, matchLevel=matchLevel)
        else:
            groups = self.getUriGroups(name, strict=strict)
        if groups is None:
            return False

        # now check the references
        for ref in groups['_evalrefs']:
            if not isValidName(ref, etypes=(TaurusElementType.Attribute,),
                               strict=strict):
                debug('"%s" is invalid because ref "%s" is not a ' +
                      'valid attribute', name, ref)
                return False
        return True
コード例 #7
0
ファイル: sardemoenv.py プロジェクト: rhomspuron/sardana
def getElements(elem_type="all", fallback_name="element_not_defined",
                fallback_elements_len=5):
    if fallback_name is None:
        fallback_name = elem_type + "_not_defined"
    try:
        elements = SarDemoEnv().getElements(elem_type)
    except RuntimeError:
        import taurus
        from sardana import sardanacustomsettings
        door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME',
                            'UNDEFINED')
        taurus.warning("The door %s is not running. " % (door_name) +
                       "Ignore this message if you are building the documentation.")
        elements = [fallback_name] * fallback_elements_len
    except Exception, e:
        import taurus
        taurus.debug(e)
        taurus.warning("It was not possible to retrieve the element. " +
                       "Ignore this message if you are building the documentation.")
        elements = [fallback_name] * fallback_elements_len
コード例 #8
0
    def isValid(self, name, matchLevel=None, strict=None):
        '''reimplemented from :class:`TaurusAttributeNameValidator` to do extra
        check on references validity (recursive)
        '''
        # Standard implementation
        if matchLevel is not None:
            groups = self._isValidAtLevel(name, matchLevel=matchLevel)
        else:
            groups = self.getUriGroups(name, strict=strict)
        if groups is None:
            return False

        # now check the references
        for ref in groups['_evalrefs']:
            if not isValidName(ref,
                               etypes=(TaurusElementType.Attribute, ),
                               strict=strict):
                debug(
                    '"%s" is invalid because ref "%s" is not a ' +
                    'valid attribute', name, ref)
                return False
        return True
コード例 #9
0
ファイル: sardemoenv.py プロジェクト: quanpower/sardana
def getElements(elem_type="all",
                fallback_name="element_not_defined",
                fallback_elements_len=5):
    if fallback_name is None:
        fallback_name = elem_type + "_not_defined"
    try:
        elements = SarDemoEnv().getElements(elem_type)
    except RuntimeError:
        import taurus
        from sardana import sardanacustomsettings
        door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME',
                            'UNDEFINED')
        taurus.warning(
            "The door %s is not running. " % (door_name) +
            "Ignore this message if you are building the documentation.")
        elements = [fallback_name] * fallback_elements_len
    except Exception, e:
        import taurus
        taurus.debug(e)
        taurus.warning(
            "It was not possible to retrieve the element. " +
            "Ignore this message if you are building the documentation.")
        elements = [fallback_name] * fallback_elements_len
コード例 #10
0
ファイル: util.py プロジェクト: victorfong28/sardana
def prepare_rconsole(options, args, tango_args):
    port = options.rconsole_port
    if port is None or port is 0:
        return
    taurus.debug("Setting up rconsole on port %d...", port)
    try:
        import rfoo.utils.rconsole
        rfoo.utils.rconsole.spawn_server(port=port)
        taurus.debug("Finished setting up rconsole")
    except:
        taurus.debug("Failed to setup rconsole", exc_info=1)
コード例 #11
0
ファイル: util.py プロジェクト: cmft/sardana
def prepare_rconsole(options, args, tango_args):
    port = options.rconsole_port
    if port is None or port is 0:
        return
    taurus.debug("Setting up rconsole on port %d...", port)
    try:
        import rfoo.utils.rconsole
        rfoo.utils.rconsole.spawn_server(port=port)
        taurus.debug("Finished setting up rconsole")
    except:
        taurus.debug("Failed to setup rconsole", exc_info=1)
コード例 #12
0
ファイル: util.py プロジェクト: victorfong28/sardana
def prepare_logging(options,
                    args,
                    tango_args,
                    start_time=None,
                    log_messages=None):
    taurus.setLogLevel(taurus.Debug)
    root = Logger.getRootLog()

    # output logger configuration
    log_output_level = options.log_level
    log_level_map = {
        "0": taurus.Critical,
        "critical": taurus.Critical,
        "1": taurus.Error,
        "error": taurus.Error,
        "2": taurus.Warning,
        "warning": taurus.Warning,
        "3": taurus.Info,
        "info": taurus.Info,
        "4": taurus.Debug,
        "debug": taurus.Debug,
        "5": taurus.Trace,
        "trace": taurus.Trace,
    }
    log_output_level = log_level_map[log_output_level]
    root.handlers[0].setLevel(log_output_level)

    if not options.without_log_file:
        log_file_level = options.log_file_level
        log_file_level = log_level_map[log_file_level]

        # Create a file handler
        if options.log_file_name is None:
            _, ds_name = os.path.split(args[0])
            ds_name, _ = os.path.splitext(ds_name)
            ds_instance = args[-1].lower()
            import getpass
            try:
                # include the user name to avoid permission errors
                tangodir = 'tango-%s' % getpass.getuser()
            except:
                tangodir = 'tango' % getpass.getuser()
            path = os.path.join(os.sep, "tmp", tangodir, ds_name, ds_instance)
            log_file_name = os.path.join(path, 'log.txt')
        else:
            log_file_name = options.log_file_name
        path = os.path.dirname(log_file_name)

        # because some versions of python have a bug in logging.shutdown (this
        # function is not protected against deleted handlers) we store the
        # handlers we create to make sure a strong reference exists when the
        # logging.shutdown is called
        taurus._handlers = handlers = []
        try:
            if not os.path.exists(path):
                os.makedirs(path, 0777)

            from sardana import sardanacustomsettings
            maxBytes = getattr(sardanacustomsettings, 'LOG_FILES_SIZE', 1E7)
            backupCount = getattr(sardanacustomsettings, 'LOG_BCK_COUNT', 5)

            fmt = Logger.getLogFormat()
            f_h = logging.handlers.RotatingFileHandler(log_file_name,
                                                       maxBytes=maxBytes,
                                                       backupCount=backupCount)
            f_h.setFormatter(fmt)
            f_h.setLevel(log_file_level)
            root.addHandler(f_h)
            handlers.append(f_h)

            if start_time is not None:
                taurus.info("Started at %s", start_time)
            else:
                taurus.info("Starting up...")
            taurus.info("Log is being stored in %s", log_file_name)
        except:
            if start_time is not None:
                taurus.info("Started at %s", start_time)
            else:
                taurus.info("Starting up...")
            taurus.warning(
                "'%s' could not be created. Logs will not be stored",
                log_file_name)
            taurus.debug("Error description", exc_info=1)

    if log_messages is None:
        log_messages = []
    for log_message in log_messages:
        taurus.info(*log_message)

    taurus.debug("Start args=%s", args)
    taurus.debug("Start tango args=%s", tango_args)
    taurus.debug("Start options=%s", options)
    taurus.debug("Using PyTango %s from %s", PyTango.Release.version,
                 PyTango.__path__[0])
    taurus.debug("Using taurus %s from %s", taurus.Release.version,
                 taurus.__path__[0])
    taurus.debug("Using sardana %s from %s", sardana.Release.version,
                 sardana.__path__[0])
コード例 #13
0
ファイル: util.py プロジェクト: cmft/sardana
def prepare_logging(options, args, tango_args, start_time=None, log_messages=None):
    taurus.setLogLevel(taurus.Debug)
    root = Logger.getRootLog()

    # output logger configuration
    log_output_level = options.log_level
    log_level_map = { "0" : taurus.Critical, "critical" : taurus.Critical,
                       "1" : taurus.Error, "error" : taurus.Error,
                       "2" : taurus.Warning, "warning" : taurus.Warning,
                       "3" : taurus.Info, "info" : taurus.Info,
                       "4" : taurus.Debug, "debug" : taurus.Debug,
                       "5" : taurus.Trace, "trace" : taurus.Trace,
                     }
    log_output_level = log_level_map[log_output_level]
    root.handlers[0].setLevel(log_output_level)

    if not options.without_log_file:
        log_file_level = options.log_file_level
        log_file_level = log_level_map[log_file_level]

        # Create a file handler
        if options.log_file_name is None:
            _, ds_name = os.path.split(args[0])
            ds_name, _ = os.path.splitext(ds_name)
            ds_instance = args[-1].lower()
            import getpass
            try:
                tangodir = 'tango-%s' % getpass.getuser()  #include the user name to avoid permission errors
            except:
                tangodir = 'tango' % getpass.getuser()
            path = os.path.join(os.sep, "tmp", tangodir, ds_name, ds_instance)
            log_file_name = os.path.join(path, 'log.txt')
        else:
            log_file_name = options.log_file_name
        path = os.path.dirname(log_file_name)

        # because some versions of python have a bug in logging.shutdown (this
        # function is not protected against deleted handlers) we store the
        # handlers we create to make sure a strong reference exists when the
        # logging.shutdown is called
        taurus._handlers = handlers = []
        try:
            if not os.path.exists(path):
                os.makedirs(path, 0777)
            
            from sardana import sardanacustomsettings    
            maxBytes = getattr(sardanacustomsettings, 'LOG_FILES_SIZE', 1E7)
            backupCount = getattr(sardanacustomsettings, 'LOG_BCK_COUNT', 5)

            fmt = Logger.getLogFormat()
            f_h = logging.handlers.RotatingFileHandler(log_file_name,
                                                       maxBytes=maxBytes,
                                                       backupCount=backupCount)
            f_h.setFormatter(fmt)
            f_h.setLevel(log_file_level)
            root.addHandler(f_h)
            handlers.append(f_h)

            if start_time is not None:
                taurus.info("Started at %s", start_time)
            else:
                taurus.info("Starting up...")
            taurus.info("Log is being stored in %s", log_file_name)
        except:
            if start_time is not None:
                taurus.info("Started at %s", start_time)
            else:
                taurus.info("Starting up...")
            taurus.warning("'%s' could not be created. Logs will not be stored",
                           log_file_name)
            taurus.debug("Error description", exc_info=1)

    if log_messages is None:
        log_messages = []
    for log_message in log_messages:
        taurus.info(*log_message)

    taurus.debug("Start args=%s", args)
    taurus.debug("Start tango args=%s", tango_args)
    taurus.debug("Start options=%s", options)
    taurus.debug("Using PyTango %s from %s", PyTango.Release.version, PyTango.__path__[0])
    taurus.debug("Using taurus %s from %s", taurus.Release.version, taurus.__path__[0])
    taurus.debug("Using sardana %s from %s", sardana.Release.version, sardana.__path__[0])
コード例 #14
0
# This file is part of Taurus
##
# http://taurus-scada.org
##
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
# Taurus is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
##
# Taurus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with Taurus.  If not, see <http://www.gnu.org/licenses/>.
##
#############################################################################
"""This package contains a collection of taurus text editor widgets"""

__docformat__ = 'restructuredtext'

try:
    from .tauruseditor import *
except Exception as e:
    from taurus import warning, debug
    warning('Problem with taurus.qt.editor (hint: is spyder >=3 installed?)')
    debug('%r', e)