[PATCH] move system from util to scmutil
Adrian Buehlmann
adrian at cadifra.com
Fri Apr 22 04:29:16 CDT 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1303453071 -7200
# Node ID 5e8843698a38717196f144079fa3f2c95de01ce0
# Parent e0f07847f8de2a349ce6f17b36cb6beb64da704d
move system from util to scmutil
diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -219,7 +219,7 @@
cmdline = util.shellquote(diffcmd) + ' ' + args
ui.debug('running %r in %s\n' % (cmdline, tmproot))
- util.system(cmdline, cwd=tmproot)
+ scmutil.system(cmdline, cwd=tmproot)
for copy_fn, working_fn, mtime in fns_and_mtime:
if os.path.getmtime(copy_fn) != mtime:
diff --git a/hgext/hgk.py b/hgext/hgk.py
--- a/hgext/hgk.py
+++ b/hgext/hgk.py
@@ -35,7 +35,7 @@
'''
import os
-from mercurial import commands, util, patch, revlog, cmdutil
+from mercurial import commands, scmutil, patch, revlog, cmdutil
from mercurial.node import nullid, nullrev, short
from mercurial.i18n import _
@@ -309,7 +309,7 @@
optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
cmd = ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc))
ui.debug("running %s\n" % cmd)
- util.system(cmd)
+ scmutil.system(cmd)
cmdtable = {
"^view":
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -191,12 +191,12 @@
fp.close()
try:
- util.system('%s %s %s' % (filter, util.shellquote(headerfile),
- util.shellquote(patchfile)),
- environ={'HGUSER': changelog[1],
- 'HGREVISION': revlog.hex(node),
- },
- onerr=util.Abort, errprefix=_('filter failed'))
+ scmutil.system('%s %s %s' % (filter, util.shellquote(headerfile),
+ util.shellquote(patchfile)),
+ environ={'HGUSER': changelog[1],
+ 'HGREVISION': revlog.hex(node),
+ },
+ onerr=util.Abort, errprefix=_('filter failed'))
user, date, msg = self.parselog(file(headerfile))[1:4]
finally:
os.unlink(headerfile)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -406,7 +406,7 @@
try:
while changesets:
# update state
- status = util.system(command)
+ status = scmutil.system(command)
if status == 125:
transition = "skip"
elif status == 0:
@@ -1101,7 +1101,7 @@
ui.status('branch %s\n' % data)
atbranch = data
elif type in 'cC':
- r = util.system(data, cwd=repo.root)
+ r = scmutil.system(data, cwd=repo.root)
if r:
desc, r = util.explain_exit(r)
raise util.Abort(_('%s command %s') % (data, desc))
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -7,7 +7,7 @@
from i18n import _
import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re
-import util, commands, hg, fancyopts, extensions, hook, error
+import scmutil, util, commands, hg, fancyopts, extensions, hook, error
import cmdutil, encoding
import ui as uimod
@@ -235,7 +235,7 @@
replace['0'] = self.name
replace['@'] = ' '.join(args)
cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True)
- return util.system(cmd, environ=env)
+ return scmutil.system(cmd, environ=env)
self.fn = fn
return
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -7,7 +7,7 @@
from node import short
from i18n import _
-import util, simplemerge, match, error
+import scmutil, util, simplemerge, match, error
import os, tempfile, re, filecmp
def _toolstr(ui, tool, part, default=""):
@@ -233,7 +233,7 @@
replace = dict(local=a, base=b, other=c, output=out)
args = util.interpolate(r'\$', replace, args,
lambda s: '"%s"' % util.localpath(s))
- r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env)
+ r = scmutil.system(toolpath + ' ' + args, cwd=repo.root, environ=env)
if not r and (_toolbool(ui, tool, "checkconflicts") or
'conflicts' in _toollist(ui, tool, "check")):
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -7,7 +7,7 @@
from i18n import _
import os, sys
-import extensions, util
+import extensions, scmutil, util
def _pythonhook(ui, repo, name, hname, funcname, args, throw):
'''call python hook. hook is callable object, looked up as
@@ -105,9 +105,9 @@
else:
cwd = os.getcwd()
if 'HG_URL' in env and env['HG_URL'].startswith('remote:http'):
- r = util.system(cmd, environ=env, cwd=cwd, out=ui)
+ r = scmutil.system(cmd, environ=env, cwd=cwd, out=ui)
else:
- r = util.system(cmd, environ=env, cwd=cwd)
+ r = scmutil.system(cmd, environ=env, cwd=cwd)
if r:
desc, r = util.explain_exit(r)
if throw:
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -7,7 +7,7 @@
from i18n import _
import util, error, osutil
-import os, errno, stat, sys
+import os, errno, stat, sys, subprocess
def checkfilename(f):
'''Check that the filename f is an acceptable filename for a tracked file'''
@@ -296,6 +296,56 @@
newdirs.append(d)
dirs[:] = newdirs
+def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None):
+ '''enhanced shell command execution.
+ run with environment maybe modified, maybe in different dir.
+
+ if command fails and onerr is None, return status. if ui object,
+ print error message and return status, else raise onerr object as
+ exception.
+
+ if out is specified, it is assumed to be a file-like object that has a
+ write() method. stdout and stderr will be redirected to out.'''
+ try:
+ sys.stdout.flush()
+ except Exception:
+ pass
+ def py2shell(val):
+ 'convert python object into string that is useful to shell'
+ if val is None or val is False:
+ return '0'
+ if val is True:
+ return '1'
+ return str(val)
+ origcmd = cmd
+ cmd = util.quotecommand(cmd)
+ env = dict(os.environ)
+ env.update((k, py2shell(v)) for k, v in environ.iteritems())
+ env['HG'] = util.hgexecutable()
+ if out is None:
+ rc = subprocess.call(cmd, shell=True, close_fds=util.closefds,
+ env=env, cwd=cwd)
+ else:
+ proc = subprocess.Popen(cmd, shell=True, close_fds=util.closefds,
+ env=env, cwd=cwd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ for line in proc.stdout:
+ out.write(line)
+ proc.wait()
+ rc = proc.returncode
+ if sys.platform == 'OpenVMS' and rc & 1:
+ rc = 0
+ if rc and onerr:
+ errmsg = '%s %s' % (os.path.basename(origcmd.split(None, 1)[0]),
+ util.explain_exit(rc)[0])
+ if errprefix:
+ errmsg = '%s: %s' % (errprefix, errmsg)
+ try:
+ onerr.warn(errmsg + '\n')
+ except AttributeError:
+ raise onerr(errmsg)
+ return rc
+
def os_rcpath():
'''return default os-specific hgrc search path'''
path = system_rcpath()
diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshrepo.py
@@ -6,7 +6,7 @@
# GNU General Public License version 2 or any later version.
from i18n import _
-import util, error, wireproto, url
+import scmutil, util, error, wireproto, url
class remotelock(object):
def __init__(self, repo):
@@ -44,7 +44,7 @@
cmd = cmd % (sshcmd, args, remotecmd, self.path)
ui.note(_('running %s\n') % cmd)
- res = util.system(cmd)
+ res = scmutil.system(cmd)
if res != 0:
self._abort(error.RepoError(_("could not create remote repo")))
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -559,9 +559,9 @@
editor = self.geteditor()
- util.system("%s \"%s\"" % (editor, name),
- environ={'HGUSER': user},
- onerr=util.Abort, errprefix=_("edit failed"))
+ scmutil.system("%s \"%s\"" % (editor, name),
+ environ={'HGUSER': user},
+ onerr=util.Abort, errprefix=_("edit failed"))
f = open(name)
t = f.read()
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -328,56 +328,6 @@
global _hgexecutable
_hgexecutable = path
-def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None):
- '''enhanced shell command execution.
- run with environment maybe modified, maybe in different dir.
-
- if command fails and onerr is None, return status. if ui object,
- print error message and return status, else raise onerr object as
- exception.
-
- if out is specified, it is assumed to be a file-like object that has a
- write() method. stdout and stderr will be redirected to out.'''
- try:
- sys.stdout.flush()
- except Exception:
- pass
- def py2shell(val):
- 'convert python object into string that is useful to shell'
- if val is None or val is False:
- return '0'
- if val is True:
- return '1'
- return str(val)
- origcmd = cmd
- cmd = quotecommand(cmd)
- env = dict(os.environ)
- env.update((k, py2shell(v)) for k, v in environ.iteritems())
- env['HG'] = hgexecutable()
- if out is None:
- rc = subprocess.call(cmd, shell=True, close_fds=closefds,
- env=env, cwd=cwd)
- else:
- proc = subprocess.Popen(cmd, shell=True, close_fds=closefds,
- env=env, cwd=cwd, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- for line in proc.stdout:
- out.write(line)
- proc.wait()
- rc = proc.returncode
- if sys.platform == 'OpenVMS' and rc & 1:
- rc = 0
- if rc and onerr:
- errmsg = '%s %s' % (os.path.basename(origcmd.split(None, 1)[0]),
- explain_exit(rc)[0])
- if errprefix:
- errmsg = '%s: %s' % (errprefix, errmsg)
- try:
- onerr.warn(errmsg + '\n')
- except AttributeError:
- raise onerr(errmsg)
- return rc
-
def checksignature(func):
'''wrap a function with code to check for calling errors'''
def check(*args, **kwargs):
diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -17,12 +17,12 @@
print "os.system =", f(os.system)
print "os =", f(os)
-from mercurial import util
+from mercurial import scmutil
-print "util =", f(util)
-print "util.system =", f(util.system)
-print "util =", f(util)
-print "util.system =", f(util.system)
+print "scmutil =", f(scmutil)
+print "scmutil.system =", f(scmutil.system)
+print "scmutil =", f(scmutil)
+print "scmutil.system =", f(scmutil.system)
import re as fred
print "fred =", f(fred)
diff --git a/tests/test-demandimport.py.out b/tests/test-demandimport.py.out
--- a/tests/test-demandimport.py.out
+++ b/tests/test-demandimport.py.out
@@ -1,10 +1,10 @@
os = <unloaded module 'os'>
os.system = <built-in function system>
os = <module 'os' from '?'>
-util = <unloaded module 'util'>
-util.system = <function system at 0x?>
-util = <module 'mercurial.util' from '?'>
-util.system = <function system at 0x?>
+scmutil = <unloaded module 'scmutil'>
+scmutil.system = <function system at 0x?>
+scmutil = <module 'mercurial.scmutil' from '?'>
+scmutil.system = <function system at 0x?>
fred = <unloaded module 're'>
re = <unloaded module 'sys'>
fred = <unloaded module 're'>
More information about the Mercurial-devel
mailing list