toolsutils.py
branchstable
changeset 6495 3187112bc7cc
parent 6138 65f5e488f983
child 7155 4bab50b02927
equal deleted inserted replaced
6471:6e0642346f80 6495:3187112bc7cc
   192     except IOError, ex:
   192     except IOError, ex:
   193         warning('missing or non readable configuration file %s (%s)',
   193         warning('missing or non readable configuration file %s (%s)',
   194                 config_file, ex)
   194                 config_file, ex)
   195     return config
   195     return config
   196 
   196 
   197 def env_path(env_var, default, name, checkexists=True):
       
   198     """get a path specified in a variable or using the default value and return
       
   199     it.
       
   200 
       
   201     :type env_var: str
       
   202     :param env_var: name of an environment variable
       
   203 
       
   204     :type default: str
       
   205     :param default: default value if the environment variable is not defined
       
   206 
       
   207     :type name: str
       
   208     :param name: the informal name of the path, used for error message
       
   209 
       
   210     :rtype: str
       
   211     :return: the value of the environment variable or the default value
       
   212 
       
   213     :raise `ConfigurationError`: if the returned path does not exist
       
   214     """
       
   215     path = environ.get(env_var, default)
       
   216     if checkexists and not exists(path):
       
   217         raise ConfigurationError('%s directory %s doesn\'t exist' % (name, path))
       
   218     return abspath(path)
       
   219 
       
   220 
       
   221 
   197 
   222 _HDLRS = {}
   198 _HDLRS = {}
   223 
   199 
   224 class metacmdhandler(type):
   200 class metacmdhandler(type):
   225     def __new__(mcs, name, bases, classdict):
   201     def __new__(mcs, name, bases, classdict):