예제 #1
0
    def __init__(self, filename, conditions_modifiers):
        self._config = {
            '__file__': _defaults_file,
            'addpath': addpath,
            'prependpath': prependpath,
            'include': self.include,
        }

        if not self._orig_environ:
            self.__dict__['_orig_environ'] = os.environ.copy()
        os.environ['UNMANGLED_LD_LIBRARY_PATH'] = os.environ.get(
            'LD_LIBRARY_PATH', '')
        os.environ['UNMANGLED_PATH'] = os.environ.get('PATH', '')

        env_prepends.clear()
        try:
            execfile(_defaults_file, self._config)
        except Exception:
            traceback.print_exc()
            raise FatalError(_('could not load config defaults'))

        old_config = os.path.join(os.path.expanduser('~'), '.jhbuildrc')
        new_config = os.path.join(
            os.environ.get('XDG_CONFIG_HOME',
                           os.path.join(os.path.expanduser('~'), '.config')),
            'jhbuildrc')

        if filename:
            if not os.path.exists(filename):
                raise FatalError(
                    _('could not load config file, %s is missing') % filename)
        else:
            if os.path.isfile(old_config) \
                    and not os.path.islink(old_config) \
                    and os.path.isfile(new_config) \
                    and not os.path.islink(new_config):
                raise FatalError(_('The default location of the configuration '
                                   'file has changed. Please move %(old_path)s'
                                   ' to %(new_path)s.' \
                                   % {'old_path': old_config,
                                      'new_path': new_config}))
            if os.path.exists(new_config):
                filename = new_config
            elif os.path.exists(old_config):
                filename = old_config

        if filename:
            self._config['__file__'] = filename
            self.filename = filename
        else:
            self._config['__file__'] = new_config
            self.filename = new_config

        # we might need to redo this process on config reloads, so save these
        self.saved_conditions_modifiers = conditions_modifiers

        # We handle the conditions flags like so:
        #   - get the default set of conditions (determined by the OS)
        #   - modify it with the commandline arguments
        #   - load the config file so that it can make further modifications
        #   - modify it with the commandline arguments again
        #
        # We apply the commandline argument condition modifiers both before
        # and after parsing the configuration so that the jhbuildrc has a
        # chance to inspect the modified set of flags (and conditionally act
        # on it to set new autogenargs, for example) but also so that the
        # condition flags given on the commandline will ultimately override
        # those in jhbuildrc.
        self._config['conditions'] = sysid.get_default_conditions()
        modify_conditions(self._config['conditions'], conditions_modifiers)
        self.load(filename)
        modify_conditions(self.conditions, conditions_modifiers)
        self.ignore_conditions = False

        self.create_directories()

        setup_env_defaults(self.system_libdirs)

        for prefix in reversed(self.extra_prefixes):
            setup_env(prefix)
        setup_env(self.prefix)

        self.apply_env_prepends()
        self.update_build_targets()
예제 #2
0
파일: config.py 프로젝트: aissat/jhbuild
    def __init__(self, filename, conditions_modifiers):
        self._config = {
            '__file__': _defaults_file,
            'addpath':  addpath,
            'prependpath':  prependpath,
            'include': self.include,
            }

        if not self._orig_environ:
            self.__dict__['_orig_environ'] = os.environ.copy()
        os.environ['UNMANGLED_LD_LIBRARY_PATH'] = os.environ.get('LD_LIBRARY_PATH', '')
        os.environ['UNMANGLED_PATH'] = os.environ.get('PATH', '')

        env_prepends.clear()
        try:
            execfile(_defaults_file, self._config)
        except:
            traceback.print_exc()
            raise FatalError(_('could not load config defaults'))

        old_config = os.path.join(os.path.expanduser('~'), '.jhbuildrc')
        new_config = os.path.join \
                         (os.environ.get \
                             ('XDG_CONFIG_HOME',
                              os.path.join(os.path.expanduser('~'), '.config')),
                          'jhbuildrc')

        if filename:
            if not os.path.exists(filename):
                raise FatalError(_('could not load config file, %s is missing') % filename)
        else:
            if os.path.isfile(old_config) \
                and not os.path.islink(old_config) \
                and os.path.isfile(new_config) \
                and not os.path.islink(new_config):
                raise FatalError(_('The default location of the configuration '
                                   'file has changed. Please move %(old_path)s'
                                   ' to %(new_path)s.' \
                                   % {'old_path': old_config,
                                      'new_path': new_config}))
            if os.path.exists(new_config):
                filename = new_config
            elif os.path.exists(old_config):
                filename = old_config

        if filename:
            self._config['__file__'] = filename
            self.filename = filename
        else:
            self._config['__file__'] = new_config
            self.filename = new_config

        # we might need to redo this process on config reloads, so save these
        self.saved_conditions_modifiers = conditions_modifiers

        # We handle the conditions flags like so:
        #   - get the default set of conditions (determined by the OS)
        #   - modify it with the commandline arguments
        #   - load the config file so that it can make further modifications
        #   - modify it with the commandline arguments again
        #
        # We apply the commandline argument condition modifiers both before
        # and after parsing the configuration so that the jhbuildrc has a
        # chance to inspect the modified set of flags (and conditionally act
        # on it to set new autogenargs, for example) but also so that the
        # condition flags given on the commandline will ultimately override
        # those in jhbuildrc.
        self._config['conditions'] = sysid.get_default_conditions()
        modify_conditions(self._config['conditions'], conditions_modifiers)
        self.load(filename)
        modify_conditions(self.conditions, conditions_modifiers)

        self.create_directories()

        setup_env_defaults(self.system_libdirs)

        for prefix in reversed(self.extra_prefixes):
            setup_env(prefix)
        setup_env(self.prefix)

        self.apply_env_prepends()
        self.update_build_targets()