##// END OF EJS Templates
util.system: Use subprocess instead of os.system...
Mads Kiilerich -
r9517:4368f582 default
parent child Browse files
Show More
@@ -165,17 +165,11 b' def testpid(pid):'
165 return inst.errno != errno.ESRCH
165 return inst.errno != errno.ESRCH
166
166
167 def explain_exit(code):
167 def explain_exit(code):
168 """return a 2-tuple (desc, code) describing a process's status"""
168 """return a 2-tuple (desc, code) describing a subprocess status
169 if os.WIFEXITED(code):
169 (codes from kill are negative - not os.system/wait encoding)"""
170 val = os.WEXITSTATUS(code)
170 if code >= 0:
171 return _("exited with status %d") % val, val
171 return _("exited with status %d") % code, code
172 elif os.WIFSIGNALED(code):
172 return _("killed by signal %d") % -code, -code
173 val = os.WTERMSIG(code)
174 return _("killed by signal %d") % val, val
175 elif os.WIFSTOPPED(code):
176 val = os.WSTOPSIG(code)
177 return _("stopped by signal %d") % val, val
178 raise ValueError(_("invalid exit code"))
179
173
180 def isowner(st):
174 def isowner(st):
181 """Return True if the stat object st is from the current user."""
175 """Return True if the stat object st is from the current user."""
@@ -357,21 +357,14 b' def system(cmd, environ={}, cwd=None, on'
357 if val is True:
357 if val is True:
358 return '1'
358 return '1'
359 return str(val)
359 return str(val)
360 oldenv = {}
361 for k in environ:
362 oldenv[k] = os.environ.get(k)
363 if cwd is not None:
364 oldcwd = os.getcwd()
365 origcmd = cmd
360 origcmd = cmd
366 if os.name == 'nt':
361 if os.name == 'nt':
367 cmd = '"%s"' % cmd
362 cmd = '"%s"' % cmd
368 try:
363 env = dict(os.environ)
369 for k, v in environ.iteritems():
364 env.update((k, py2shell(v)) for k, v in environ.iteritems())
370 os.environ[k] = py2shell(v)
365 env['HG'] = hgexecutable()
371 os.environ['HG'] = hgexecutable()
366 rc = subprocess.call(cmd, shell=True, close_fds=closefds,
372 if cwd is not None and oldcwd != cwd:
367 env=env, cwd=cwd)
373 os.chdir(cwd)
374 rc = os.system(cmd)
375 if sys.platform == 'OpenVMS' and rc & 1:
368 if sys.platform == 'OpenVMS' and rc & 1:
376 rc = 0
369 rc = 0
377 if rc and onerr:
370 if rc and onerr:
@@ -384,14 +377,6 b' def system(cmd, environ={}, cwd=None, on'
384 except AttributeError:
377 except AttributeError:
385 raise onerr(errmsg)
378 raise onerr(errmsg)
386 return rc
379 return rc
387 finally:
388 for k, v in oldenv.iteritems():
389 if v is None:
390 del os.environ[k]
391 else:
392 os.environ[k] = v
393 if cwd is not None and oldcwd != cwd:
394 os.chdir(oldcwd)
395
380
396 def checksignature(func):
381 def checksignature(func):
397 '''wrap a function with code to check for calling errors'''
382 '''wrap a function with code to check for calling errors'''
General Comments 0
You need to be logged in to leave comments. Login now