toolsutils.py
brancholdstable
changeset 5993 50e1a6ad3e98
parent 5426 0d4853a6e5ee
child 6138 65f5e488f983
equal deleted inserted replaced
5487:3ab2682a4b37 5993:50e1a6ad3e98
   114             copy.close()
   114             copy.close()
   115             print 'keep current version, the new file has been written to', copy_file
   115             print 'keep current version, the new file has been written to', copy_file
   116     else:
   116     else:
   117         print 'no diff between %s and %s' % (appl_file, ref_file)
   117         print 'no diff between %s and %s' % (appl_file, ref_file)
   118 
   118 
   119 
   119 SKEL_EXCLUDE = ('*.py[co]', '*.orig', '*~', '*_flymake.py')
   120 def copy_skeleton(skeldir, targetdir, context,
   120 def copy_skeleton(skeldir, targetdir, context,
   121                   exclude=('*.py[co]', '*.orig', '*~', '*_flymake.py'),
   121                   exclude=SKEL_EXCLUDE, askconfirm=False):
   122                   askconfirm=False):
       
   123     import shutil
   122     import shutil
   124     from fnmatch import fnmatch
   123     from fnmatch import fnmatch
   125     skeldir = normpath(skeldir)
   124     skeldir = normpath(skeldir)
   126     targetdir = normpath(targetdir)
   125     targetdir = normpath(targetdir)
   127     for dirpath, dirnames, filenames in walk(skeldir):
   126     for dirpath, dirnames, filenames in walk(skeldir):
   195     except IOError, ex:
   194     except IOError, ex:
   196         warning('missing or non readable configuration file %s (%s)',
   195         warning('missing or non readable configuration file %s (%s)',
   197                 config_file, ex)
   196                 config_file, ex)
   198     return config
   197     return config
   199 
   198 
   200 def env_path(env_var, default, name):
   199 def env_path(env_var, default, name, checkexists=True):
   201     """get a path specified in a variable or using the default value and return
   200     """get a path specified in a variable or using the default value and return
   202     it.
   201     it.
   203 
   202 
   204     :type env_var: str
   203     :type env_var: str
   205     :param env_var: name of an environment variable
   204     :param env_var: name of an environment variable
   214     :return: the value of the environment variable or the default value
   213     :return: the value of the environment variable or the default value
   215 
   214 
   216     :raise `ConfigurationError`: if the returned path does not exist
   215     :raise `ConfigurationError`: if the returned path does not exist
   217     """
   216     """
   218     path = environ.get(env_var, default)
   217     path = environ.get(env_var, default)
   219     if not exists(path):
   218     if checkexists and not exists(path):
   220         raise ConfigurationError('%s path %s doesn\'t exist' % (name, path))
   219         raise ConfigurationError('%s directory %s doesn\'t exist' % (name, path))
   221     return abspath(path)
   220     return abspath(path)
   222 
   221 
   223 
   222 
   224 
   223 
   225 _HDLRS = {}
   224 _HDLRS = {}