예제 #1
0
 def addToSearchPath(n, _1, _2):
     '''
     Add entries to the search path expanding variables inside.
     '''
     entries = Variable.List('_SEARCH_PATH')
     entries.set(n, os.pathsep, environment=self.variables)
     self.searchPath.extend(entries)
예제 #2
0
    def declare(self, name, vartype, local):
        '''Creates an instance of new variable. It loads values from the OS if the variable is not local.'''
        if self.asWriter:
            self._writeVarToXML(name, 'declare', '', vartype, local)

        if not isinstance(local, bool):
            if str(local).lower() == 'true':
                local = True
            else:
                local = False

        if name in self.variables.keys():
            if self.variables[name].local != local:
                raise Variable.EnvError(name, 'redeclaration')
            else:
                if vartype.lower() == "list":
                    if not isinstance(self.variables[name],Variable.List):
                        raise Variable.EnvError(name, 'redeclaration')
                else:
                    if not isinstance(self.variables[name],Variable.Scalar):
                        raise Variable.EnvError(name, 'redeclaration')

        if vartype.lower() == "list":
            a = Variable.List(name, local)
        else:
            a = Variable.Scalar(name, local)

        if self.loadFromSystem and not local and name in os.environ:
            a.expandVars = False # disable var expansion when importing from the environment
            a.set(os.environ[name], os.pathsep, environment=self.variables)
            a.expandVars = True

        self.variables[name] = a
예제 #3
0
 def default(self, name, value):
     '''Sets a single variable only if it is not already set!'''
     name = str(name)
     if self.asWriter:
         self._writeVarToXML(name, 'default', value)
     else:
         # Here it is different from the other actions because after a 'declare'
         # we cannot tell if the variable was already set or not.
         # FIXME: improve declare() to allow for a default.
         if name not in self.variables:
             if self._guessType(name) == 'list':
                 v = Variable.List(name, False)
             else:
                 v = Variable.Scalar(name, False)
             if self.loadFromSystem and name in os.environ:
                 v.set(os.environ[name], os.pathsep, environment=self.variables)
             else:
                 v.set(value, self.separator, environment=self.variables)
             self.variables[name] = v
         else:
             v = self.variables[name]
             if not v.val:
                 v.set(value, self.separator, environment=self.variables)