Esempio n. 1
0
    def file_lock_dir(self):
        dirname = _settings.file_lock_dir
        if not dirname:
            return None

        # sanity check
        if os.path.isabs(dirname) or os.path.basename(dirname) != dirname:
            raise ConfigurationError(
                "filesystem package repository setting 'file_lock_dir' must be "
                "a single relative directory such as '.lock'")

        # fall back to location path if lock dir doesn't exist.
        path = os.path.join(self.location, dirname)
        if not os.path.exists(path):
            return None

        return dirname
Esempio n. 2
0
def _load_config_py(filepath):
    from rez.vendor.six.six import exec_

    reserved = dict(
        rez_version=__version__,
        ModifyList=ModifyList
    )

    globs = reserved.copy()
    result = {}

    with open(filepath) as f:
        try:
            code = compile(f.read(), filepath, 'exec')
            exec_(code, _globs_=globs)
        except Exception, e:
            raise ConfigurationError("Error loading configuration from %s: %s"
                                     % (filepath, str(e)))
Esempio n. 3
0
def _load_config_py(filepath):
    from rez.vendor.six.six import exec_

    reserved = dict(
        # Standard Python module variables
        # Made available from within the module,
        # and later excluded from the `Config` class
        __name__=os.path.splitext(os.path.basename(filepath))[0],
        __file__=filepath,
        rez_version=__version__,
        ModifyList=ModifyList)

    globs = reserved.copy()
    result = {}

    with open(filepath) as f:
        try:
            code = compile(f.read(), filepath, 'exec')
            exec_(code, _globs_=globs)
        except Exception, e:
            raise ConfigurationError(
                "Error loading configuration from %s: %s" % (filepath, str(e)))
Esempio n. 4
0
    def _parse_env_var(self, value):
        items = value.split(",")
        result = {}

        for item in items:
            if ':' not in item:
                raise ConfigurationError(
                    "Expected dict string in form 'k1:v1,k2:v2,...kN:vN': %s" %
                    value)

            k, v = item.split(':', 1)

            try:
                v = int(v)
            except ValueError:
                try:
                    v = float(v)
                except ValueError:
                    pass

            result[k] = v

        return result
Esempio n. 5
0
    def _validate(self, data):
        # overridden settings take precedence. Note that `data` has already
        # taken override into account at this point
        if self.key in self.config.overrides:
            return data

        if not self.config.locked:

            # next, env-var
            value = os.getenv(self._env_var_name)
            if value is not None:
                return self._parse_env_var(value)

            # next, JSON-encoded env-var
            varname = self._env_var_name + "_JSON"
            value = os.getenv(varname)
            if value is not None:
                from rez.utils import json

                try:
                    return json.loads(value)
                except ValueError:
                    raise ConfigurationError(
                        "Expected $%s to be JSON-encoded string." % varname
                    )

        # next, data unchanged
        if data is not None:
            return data

        # some settings have a programmatic default
        attr = "_get_%s" % self.key
        if hasattr(self.config, attr):
            return getattr(self.config, attr)()

        # setting is None
        return None
Esempio n. 6
0
 def _parse_env_var(self, value):
     try:
         return float(value)
     except ValueError:
         raise ConfigurationError("Expected %s to be a float" %
                                  self._env_var_name)
Esempio n. 7
0
 def _parse_env_var(self, value):
     try:
         return int(value)
     except ValueError:
         raise ConfigurationError("expected %s to be an integer" %
                                  self._env_var_name)
Esempio n. 8
0
"""
Abstraction for PyQt/PySide import.
"""
import sys
from rez.config import config
from rez.exceptions import RezGuiQTImportError
from rez.utils.lint_helper import used

USE_PYSIDE = None
if config.use_pyside:
    if config.use_pyqt:
        from rez.exceptions import ConfigurationError
        raise ConfigurationError(
            "'use_pyside' and 'use_pyqt' are both enabled")
    USE_PYSIDE = True
elif config.use_pyqt:
    USE_PYSIDE = False

if USE_PYSIDE is None:
    if 'PyQt4' in sys.modules:
        USE_PYSIDE = False
    elif 'PySide' in sys.modules:
        USE_PYSIDE = True
    else:
        try:
            import PyQt4
            used(PyQt4)
            USE_PYSIDE = False
        except ImportError:
            try:
                import PySide