How to use the ganga.GangaCore.Utility.Config.Config.ConfigError function in ganga

To help you get started, we’ve selected a few ganga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def setSessionValue(self, session_value):
        if not hasattr(self, 'docstring'):
            raise ConfigError('Can\'t set a session value without a docstring!')

        self.hasModified = True

        # try:
        if self.filter:
            session_value = self.filter(self, session_value)

        if hasattr(self, 'session_value'):
            session_value = self.transform_PATH_option(session_value, self.session_value)

        self.session_value = session_value
        self.convert_type('session_value')
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
logger.debug('checking value type: %s (%s)', cast_type, optdesc)

        def check_type(x, t):
            return isinstance(x, t) or x is t

        # first we check using the same rules for typelist as for the GPI proxy
        # objects
        try:
            import GangaCore.GPIDev.TypeCheck
            type_matched = GangaCore.GPIDev.TypeCheck._valueTypeAllowed(new_value, cast_type, logger)
        except TypeError:  # cast_type is not a list
            type_matched = check_type(new_value, cast_type)

        from GangaCore.Utility.logic import implies
        if not implies(not cast_type is type(None), type_matched):
            raise ConfigError('type mismatch: expected %s got %s (%s)' % (cast_type, type(new_value), optdesc))

        setattr(self, x_name, new_value)
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def __init__(self, what=''):
        super(ConfigError, self).__init__()
        self.what = what
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def makeConfig(name, docstring, **kwds):
    """
    Create a config package and attach metadata to it. makeConfig() should be called once for each package.
    """

    if _after_bootstrap:
        raise ConfigError('attempt to create a configuration section [%s] after bootstrap' % name)

    try:
        c = allConfigs[name]
        c.docstring = docstring
        for k in kwds:
            setattr(c, k, kwds[k])
    except KeyError:
        c = allConfigs[name] = PackageConfig(name, docstring, **kwds)

    c._config_made = True
    return c
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def getEffectiveOption(self, name):
        try:
            return self.options[name].value
        except KeyError:
            raise ConfigError('option "%s" does not exist in "%s"' % (name, self.name))
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def setGangarcValue(self, gangarc_value):
        if not hasattr(self, 'docstring'):
            raise ConfigError('Can\'t set a gangarc value without a docstring!')

        self.hasModified = True
        try:
            if self.filter:
                gangarc_value = self.filter(self, gangarc_value)
        except Exception as x:
            logger = getLogger()
            logger.warning('problem with option filter: %s: %s', self.name, x)

        if hasattr(self, 'gangarc_value'):
            gangarc_value = self.transform_PATH_option(gangarc_value, self.gangarc_value)

        if hasattr(self, 'gangarc_value'):
            old_value = self.gangarc_value

        self.gangarc_value = gangarc_value
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def getEffectiveLevel(self, name):
        """ Return 0 if option is effectively set at the user level, 1
        if at session level or 2 if at default level """
        try:
            return self.options[name].level
        except KeyError:
            raise ConfigError('option "%s" does not exist in "%s"' % (name, self.name))
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def setUserValue(self, user_value):
        if not hasattr(self, 'docstring'):
            raise ConfigError('Can\'t set a user value without a docstring!')

        self.hasModified = True
        try:
            if self.filter:
                user_value = self.filter(self, user_value)
        except Exception as x:
            logger = getLogger()
            logger.warning('problem with option filter: %s: %s', self.name, x)

        if hasattr(self, 'user_value'):
            user_value = self.transform_PATH_option(user_value, self.user_value)

        if hasattr(self, 'user_value'):
            old_value = self.user_value

        self.user_value = user_value
github ganga-devs / ganga / ganga / GangaCore / Utility / Config / Config.py View on Github external
def addOption(self, name, default_value, docstring, override=False, typelist=None, **meta):
        """
        Add a new option to the configuration.
        """
        if _after_bootstrap and not self.is_open:
            raise ConfigError('attempt to add a new option [%s]%s after bootstrap' % (self.name, name))

        # has the option already been made
        try:
            option = self.options[name]
        except KeyError:
            option = ConfigOption(name)

        if option.check_defined() and not override:
            logger = getLogger()
            logger.warning('attempt to add again the option [%s]%s (ignored)', self.name, name)
            return

        option.defineOption(default_value, docstring, typelist, **meta)
        self.options[option.name] = option

        # is it in the list of unknown options from the standard config files