mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-25 17:36:13 +01:00
- added new function core.run_external which can be used to execute an external program
Basically it's just a wrapper around subprocess.call which raises an ExtRuntimeError exception if subprocess.call raised an OSError with errno set to ENOENT (unfortunately the OSError's filename attribute is set to None therefore we cannot print a meaningful error message (that's why an ExtRuntimeError is raised)). Replaced all occurrences of subprocess.call with a corresponding run_external call.
This commit is contained in:
parent
ec595d361b
commit
93df866787
@ -149,7 +149,7 @@ def run(prg):
|
|||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 2
|
return 2
|
||||||
except oscerr.ExtRuntimeError, e:
|
except oscerr.ExtRuntimeError, e:
|
||||||
print >>sys.stderr, e.msg
|
print >>sys.stderr, e.file + ':', e.msg
|
||||||
return 1
|
return 1
|
||||||
except oscerr.WorkingCopyOutdated, e:
|
except oscerr.WorkingCopyOutdated, e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
|
@ -13,7 +13,7 @@ import urlparse
|
|||||||
from tempfile import NamedTemporaryFile, mkdtemp
|
from tempfile import NamedTemporaryFile, mkdtemp
|
||||||
from osc.fetch import *
|
from osc.fetch import *
|
||||||
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir
|
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir
|
||||||
from osc.core import get_binarylist, get_binary_file
|
from osc.core import get_binarylist, get_binary_file, run_external
|
||||||
from osc.util import rpmquery, debquery, archquery
|
from osc.util import rpmquery, debquery, archquery
|
||||||
import osc.conf
|
import osc.conf
|
||||||
import oscerr
|
import oscerr
|
||||||
@ -913,14 +913,15 @@ def main(apiurl, opts, argv):
|
|||||||
cmd = [ change_personality[bi.buildarch] ] + cmd;
|
cmd = [ change_personality[bi.buildarch] ] + cmd;
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rc = subprocess.call(cmd)
|
rc = run_external(cmd[0], *cmd[1:])
|
||||||
if rc:
|
if rc:
|
||||||
print
|
print
|
||||||
print 'The buildroot was:', build_root
|
print 'The buildroot was:', build_root
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
except KeyboardInterrupt, i:
|
except KeyboardInterrupt, i:
|
||||||
print "keyboard interrupt, killing build ..."
|
print "keyboard interrupt, killing build ..."
|
||||||
subprocess.call(cmd + ["--kill"])
|
cmd.append('--kill')
|
||||||
|
run_external(cmd[0], *cmd[1:])
|
||||||
raise i
|
raise i
|
||||||
|
|
||||||
pacdir = os.path.join(build_root, '.build.packages')
|
pacdir = os.path.join(build_root, '.build.packages')
|
||||||
|
@ -5416,7 +5416,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
pdir,
|
pdir,
|
||||||
"%s:%s" % (hostname, os.path.dirname(hostprefer))]
|
"%s:%s" % (hostname, os.path.dirname(hostprefer))]
|
||||||
print 'Run: %s' % " ".join(rsync_prefer_cmd)
|
print 'Run: %s' % " ".join(rsync_prefer_cmd)
|
||||||
ret = subprocess.call(rsync_prefer_cmd)
|
ret = run_external(rsync_prefer_cmd[0], *rsync_prefer_cmd[1:])
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -5466,7 +5466,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
# 1.) rsync sources
|
# 1.) rsync sources
|
||||||
rsync_source_cmd = ['rsync', '-az', '-delete', '-e', 'ssh', cwd, "%s:%s" % (hostname, hostpath)]
|
rsync_source_cmd = ['rsync', '-az', '-delete', '-e', 'ssh', cwd, "%s:%s" % (hostname, hostpath)]
|
||||||
print 'Run: %s' % " ".join(rsync_source_cmd)
|
print 'Run: %s' % " ".join(rsync_source_cmd)
|
||||||
ret = subprocess.call(rsync_source_cmd)
|
ret = run_external(rsync_source_cmd[0], *rsync_source_cmd[1:])
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -5497,7 +5497,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
local_args = " ".join(hostargs))
|
local_args = " ".join(hostargs))
|
||||||
]
|
]
|
||||||
print 'Run: %s' % " ".join(ssh_cmd)
|
print 'Run: %s' % " ".join(ssh_cmd)
|
||||||
build_ret = subprocess.call(ssh_cmd)
|
build_ret = run_external(ssh_cmd[0], *ssh_cmd[1:])
|
||||||
if build_ret != 0:
|
if build_ret != 0:
|
||||||
return build_ret
|
return build_ret
|
||||||
|
|
||||||
@ -5505,7 +5505,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if opts.keep_pkgs:
|
if opts.keep_pkgs:
|
||||||
ret = rsync_keep_cmd = ['rsync', '-az', '-e', 'ssh', "%s:%s" % (hostname, hostkeep), opts.keep_pkgs]
|
ret = rsync_keep_cmd = ['rsync', '-az', '-e', 'ssh', "%s:%s" % (hostname, hostkeep), opts.keep_pkgs]
|
||||||
print 'Run: %s' % " ".join(rsync_keep_cmd)
|
print 'Run: %s' % " ".join(rsync_keep_cmd)
|
||||||
ret = subprocess.call(rsync_keep_cmd)
|
ret = run_external(rsync_keep_cmd[0], *rsync_keep_cmd[1:])
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -7308,14 +7308,14 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
o = open(os.path.join(destdir, name), 'wb')
|
o = open(os.path.join(destdir, name), 'wb')
|
||||||
code = subprocess.call(['diff3', '-m', '-E',
|
code = run_external('diff3', '-m', '-E',
|
||||||
'-L', '.mine',
|
'-L', '.mine',
|
||||||
os.path.join(destdir, name + '.mine'),
|
os.path.join(destdir, name + '.mine'),
|
||||||
'-L', '.old',
|
'-L', '.old',
|
||||||
os.path.join(destdir, name + '.old'),
|
os.path.join(destdir, name + '.old'),
|
||||||
'-L', '.new',
|
'-L', '.new',
|
||||||
os.path.join(destdir, name + '.new'),
|
os.path.join(destdir, name + '.new'),
|
||||||
], stdout=o)
|
stdout=o)
|
||||||
if code == 0:
|
if code == 0:
|
||||||
print statfrmt('G', name)
|
print statfrmt('G', name)
|
||||||
os.unlink(os.path.join(destdir, name + '.mine'))
|
os.unlink(os.path.join(destdir, name + '.mine'))
|
||||||
@ -7436,11 +7436,11 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
o = open(name, 'wb')
|
o = open(name, 'wb')
|
||||||
code = subprocess.call(['diff3', '-m', '-E',
|
code = run_external('diff3', '-m', '-E',
|
||||||
'-L', '.mine', name + '.mine',
|
'-L', '.mine', name + '.mine',
|
||||||
'-L', '.old', name + '.old',
|
'-L', '.old', name + '.old',
|
||||||
'-L', '.new', name + '.new',
|
'-L', '.new', name + '.new',
|
||||||
], stdout=o)
|
stdout=o)
|
||||||
if code == 0:
|
if code == 0:
|
||||||
print statfrmt('G', name)
|
print statfrmt('G', name)
|
||||||
os.unlink(name + '.mine')
|
os.unlink(name + '.mine')
|
||||||
|
51
osc/core.py
51
osc/core.py
@ -24,6 +24,7 @@ import conf
|
|||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import errno
|
||||||
try:
|
try:
|
||||||
from xml.etree import cElementTree as ET
|
from xml.etree import cElementTree as ET
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -361,10 +362,10 @@ class Serviceinfo:
|
|||||||
name = call.split(None, 1)[0]
|
name = call.split(None, 1)[0]
|
||||||
if not os.path.exists("/usr/lib/obs/service/"+name):
|
if not os.path.exists("/usr/lib/obs/service/"+name):
|
||||||
raise oscerr.PackageNotInstalled("obs-service-"+name)
|
raise oscerr.PackageNotInstalled("obs-service-"+name)
|
||||||
c = "/usr/lib/obs/service/" + call + " --outdir " + temp_dir
|
cmd = "/usr/lib/obs/service/" + call + " --outdir " + temp_dir
|
||||||
if conf.config['verbose'] > 1 or verbose:
|
if conf.config['verbose'] > 1 or verbose:
|
||||||
print "Run source service:", c
|
print "Run source service:", cmd
|
||||||
r = subprocess.call(c, shell=True)
|
r = run_external(cmd, shell=True)
|
||||||
|
|
||||||
if r != 0:
|
if r != 0:
|
||||||
print "Aborting: service call failed: " + c
|
print "Aborting: service call failed: " + c
|
||||||
@ -1458,8 +1459,7 @@ class Package:
|
|||||||
# try merging
|
# try merging
|
||||||
# diff3 OPTIONS... MINE OLDER YOURS
|
# diff3 OPTIONS... MINE OLDER YOURS
|
||||||
merge_cmd = 'diff3 -m -E %s %s %s > %s' % (myfilename, storefilename, upfilename, filename)
|
merge_cmd = 'diff3 -m -E %s %s %s > %s' % (myfilename, storefilename, upfilename, filename)
|
||||||
# we would rather use the subprocess module, but it is not availablebefore 2.4
|
ret = run_external(merge_cmd, shell=True)
|
||||||
ret = subprocess.call(merge_cmd, shell=True)
|
|
||||||
|
|
||||||
# "An exit status of 0 means `diff3' was successful, 1 means some
|
# "An exit status of 0 means `diff3' was successful, 1 means some
|
||||||
# conflicts were found, and 2 means trouble."
|
# conflicts were found, and 2 means trouble."
|
||||||
@ -3443,10 +3443,7 @@ def run_pager(message, tmp_suffix=''):
|
|||||||
tmpfile.flush()
|
tmpfile.flush()
|
||||||
pager = os.getenv('PAGER', default=get_default_pager())
|
pager = os.getenv('PAGER', default=get_default_pager())
|
||||||
try:
|
try:
|
||||||
try:
|
run_external(pager, tmpfile.name)
|
||||||
subprocess.call('%s %s' % (pager, tmpfile.name), shell=True)
|
|
||||||
except OSError, e:
|
|
||||||
raise oscerr.ExtRuntimeError('cannot run pager \'%s\': %s' % (pager, e.strerror), pager)
|
|
||||||
finally:
|
finally:
|
||||||
tmpfile.close()
|
tmpfile.close()
|
||||||
|
|
||||||
@ -3454,10 +3451,7 @@ def run_editor(filename):
|
|||||||
editor = os.getenv('EDITOR', default=get_default_editor())
|
editor = os.getenv('EDITOR', default=get_default_editor())
|
||||||
cmd = editor.split(' ')
|
cmd = editor.split(' ')
|
||||||
cmd.append(filename)
|
cmd.append(filename)
|
||||||
try:
|
return run_external(cmd[0], *cmd[1:])
|
||||||
return subprocess.call(cmd)
|
|
||||||
except OSError, e:
|
|
||||||
raise oscerr.ExtRuntimeError('cannot run editor \'%s\': %s' % (editor, e.strerror), editor)
|
|
||||||
|
|
||||||
def edit_message(footer='', template='', templatelen=30):
|
def edit_message(footer='', template='', templatelen=30):
|
||||||
delim = '--This line, and those below, will be ignored--\n'
|
delim = '--This line, and those below, will be ignored--\n'
|
||||||
@ -5836,7 +5830,7 @@ def unpack_srcrpm(srpm, dir, *files):
|
|||||||
if os.path.isdir(dir):
|
if os.path.isdir(dir):
|
||||||
os.chdir(dir)
|
os.chdir(dir)
|
||||||
cmd = 'rpm2cpio %s | cpio -i %s &> /dev/null' % (srpm, ' '.join(files))
|
cmd = 'rpm2cpio %s | cpio -i %s &> /dev/null' % (srpm, ' '.join(files))
|
||||||
ret = subprocess.call(cmd, shell=True)
|
ret = run_external(cmd, shell=True)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
print >>sys.stderr, 'error \'%s\' - cannot extract \'%s\'' % (ret, srpm)
|
print >>sys.stderr, 'error \'%s\' - cannot extract \'%s\'' % (ret, srpm)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -6413,7 +6407,7 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None, igno
|
|||||||
|
|
||||||
def edit_submitrequest(apiurl, project, orequest, new_request=None):
|
def edit_submitrequest(apiurl, project, orequest, new_request=None):
|
||||||
"""edit a submit action from orequest/new_request"""
|
"""edit a submit action from orequest/new_request"""
|
||||||
import tempfile, shutil, subprocess
|
import tempfile, shutil
|
||||||
actions = orequest.get_actions('submit')
|
actions = orequest.get_actions('submit')
|
||||||
oactions = actions
|
oactions = actions
|
||||||
if not orequest is None:
|
if not orequest is None:
|
||||||
@ -6446,7 +6440,7 @@ def edit_submitrequest(apiurl, project, orequest, new_request=None):
|
|||||||
os.chdir(tmpdir)
|
os.chdir(tmpdir)
|
||||||
print 'Checked out package \'%s\' to %s. Started a new shell (%s).\n' \
|
print 'Checked out package \'%s\' to %s. Started a new shell (%s).\n' \
|
||||||
'Please fix the package and close the shell afterwards.' % (package, tmpdir, shell)
|
'Please fix the package and close the shell afterwards.' % (package, tmpdir, shell)
|
||||||
subprocess.call(shell)
|
run_external(shell)
|
||||||
# the pkg might have uncommitted changes...
|
# the pkg might have uncommitted changes...
|
||||||
cleanup = False
|
cleanup = False
|
||||||
os.chdir(olddir)
|
os.chdir(olddir)
|
||||||
@ -6529,6 +6523,31 @@ def raw_input(*args):
|
|||||||
# interpret ctrl-d as user abort
|
# interpret ctrl-d as user abort
|
||||||
raise oscerr.UserAbort()
|
raise oscerr.UserAbort()
|
||||||
|
|
||||||
|
def run_external(filename, *args, **kwargs):
|
||||||
|
"""Executes the program filename via subprocess.call.
|
||||||
|
|
||||||
|
*args are additional arguments which are passed to the
|
||||||
|
program filename. **kwargs specify additional arguments for
|
||||||
|
the subprocess.call function.
|
||||||
|
if no args are specified the plain filename is passed
|
||||||
|
to subprocess.call (this can be used to execute a shell
|
||||||
|
command). Otherwise [filename] + list(args) is passed
|
||||||
|
to the subprocess.call function.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# unless explicitly specified use shell=False
|
||||||
|
kwargs.setdefault('shell', False)
|
||||||
|
if args:
|
||||||
|
cmd = [filename] + list(args)
|
||||||
|
else:
|
||||||
|
cmd = filename
|
||||||
|
try:
|
||||||
|
return subprocess.call(cmd, **kwargs)
|
||||||
|
except OSError, e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
raise oscerr.ExtRuntimeError(e.strerror, filename)
|
||||||
|
|
||||||
# backward compatibility: local role filtering
|
# backward compatibility: local role filtering
|
||||||
def filter_role(meta, user, role):
|
def filter_role(meta, user, role):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user