mercurial/util.py
changeset 1880 05c7d75be925
parent 1877 d314a89fa4f1
child 1882 c0320567931f
equal deleted inserted replaced
1879:9ef0850b9b68 1880:05c7d75be925
   323                             explain_exit(rc)[0])
   323                             explain_exit(rc)[0])
   324         if errprefix:
   324         if errprefix:
   325             errmsg = "%s: %s" % (errprefix, errmsg)
   325             errmsg = "%s: %s" % (errprefix, errmsg)
   326         raise Abort(errmsg)
   326         raise Abort(errmsg)
   327 
   327 
       
   328 def esystem(cmd, environ={}, cwd=None):
       
   329     '''enhanced shell command execution.
       
   330     run with environment maybe modified, maybe in different dir.'''
       
   331     oldenv = {}
       
   332     for k in environ:
       
   333         oldenv[k] = os.environ.get(k)
       
   334     if cwd is not None:
       
   335         oldcwd = os.getcwd()
       
   336     try:
       
   337         for k, v in environ.iteritems():
       
   338             os.environ[k] = str(v)
       
   339         if cwd is not None and oldcwd != cwd:
       
   340             os.chdir(cwd)
       
   341         return os.system(cmd)
       
   342     finally:
       
   343         for k, v in oldenv.iteritems():
       
   344             if v is None:
       
   345                 del os.environ[k]
       
   346             else:
       
   347                 os.environ[k] = v
       
   348         if cwd is not None and oldcwd != cwd:
       
   349             os.chdir(oldcwd)
       
   350 
   328 def rename(src, dst):
   351 def rename(src, dst):
   329     """forcibly rename a file"""
   352     """forcibly rename a file"""
   330     try:
   353     try:
   331         os.rename(src, dst)
   354         os.rename(src, dst)
   332     except:
   355     except: