- add stderr and stdout to api.init() // this is needed for buildfarm.
- use subprocess and be consistent on return value in util.run_batch()
This commit is contained in:
@@ -222,4 +222,4 @@ def dirName(filePath):
|
|||||||
|
|
||||||
def system(command):
|
def system(command):
|
||||||
command = string.join(string.split(command))
|
command = string.join(string.split(command))
|
||||||
return run_batch(command, True)
|
return run_batch(command, True)[0]
|
||||||
|
|||||||
+12
-1
@@ -49,7 +49,9 @@ import pisi.lockeddbshelve as shelve
|
|||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def init(database = True, write = True, options = None, ui = None, comar = True):
|
def init(database = True, write = True,
|
||||||
|
options = None, ui = None, comar = True,
|
||||||
|
stdout = None, stderr = None):
|
||||||
"""Initialize PiSi subsystem"""
|
"""Initialize PiSi subsystem"""
|
||||||
|
|
||||||
# UI comes first
|
# UI comes first
|
||||||
@@ -63,6 +65,15 @@ def init(database = True, write = True, options = None, ui = None, comar = True)
|
|||||||
else:
|
else:
|
||||||
ctx.ui = ui
|
ctx.ui = ui
|
||||||
|
|
||||||
|
|
||||||
|
# If given define stdout and stderr. Needed by buildfarm currently
|
||||||
|
# but others can benefit from this too.
|
||||||
|
if stdout:
|
||||||
|
ctx.stdout = stdout
|
||||||
|
if stderr:
|
||||||
|
ctx.stderr = stderr
|
||||||
|
|
||||||
|
|
||||||
import pisi.config
|
import pisi.config
|
||||||
ctx.config = pisi.config.Config(options)
|
ctx.config = pisi.config.Config(options)
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ def get_option(opt):
|
|||||||
# default UI is CLI
|
# default UI is CLI
|
||||||
ui = None # not now
|
ui = None # not now
|
||||||
|
|
||||||
|
# stdout, stderr for PiSi API
|
||||||
|
stdout = None
|
||||||
|
stderr = None
|
||||||
|
|
||||||
dbenv = None
|
dbenv = None
|
||||||
installdb = None
|
installdb = None
|
||||||
packagedb = None
|
packagedb = None
|
||||||
|
|||||||
+29
-17
@@ -26,6 +26,7 @@ import shutil
|
|||||||
import string
|
import string
|
||||||
import statvfs
|
import statvfs
|
||||||
import operator
|
import operator
|
||||||
|
import subprocess
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
@@ -141,22 +142,33 @@ def human_readable_rate(size = 0):
|
|||||||
def run_batch(cmd, realtime = False):
|
def run_batch(cmd, realtime = False):
|
||||||
"""run command non-interactively/realtime and report return value and output"""
|
"""run command non-interactively/realtime and report return value and output"""
|
||||||
ctx.ui.info(_('Running ') + cmd, verbose=True)
|
ctx.ui.info(_('Running ') + cmd, verbose=True)
|
||||||
p = os.popen(cmd)
|
|
||||||
if realtime:
|
if ctx.stdout:
|
||||||
while 1:
|
stdout = ctx.stdout
|
||||||
line = p.readline()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
ctx.ui.debug(line[:-1])
|
|
||||||
return p.close()
|
|
||||||
else:
|
else:
|
||||||
lines = p.readlines()
|
stdout = subprocess.PIPE
|
||||||
ret = p.close()
|
|
||||||
ctx.ui.debug(_('return value %s') % ret)
|
if ctx.stderr:
|
||||||
successful = ret == None
|
stderr = ctx.stderr
|
||||||
if not successful:
|
else:
|
||||||
ctx.ui.error(_('Failed command: %s') % cmd + strlist(lines))
|
stderr = subprocess.PIPE
|
||||||
return (successful,lines)
|
|
||||||
|
out = err = ""
|
||||||
|
p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
|
||||||
|
if realtime and not ctx.stdout:
|
||||||
|
while p.poll() == None:
|
||||||
|
line = p.stdout.readline()
|
||||||
|
if line:
|
||||||
|
ctx.ui.debug(line[:-1])
|
||||||
|
else:
|
||||||
|
out, err = p.communicate()
|
||||||
|
|
||||||
|
ctx.ui.debug(_('return value %s') % p.returncode)
|
||||||
|
if p.returncode:
|
||||||
|
# Non-zero means failed.
|
||||||
|
ctx.ui.error(_('Failed command: %s') % cmd + strlist(out))
|
||||||
|
|
||||||
|
return (p.returncode, out)
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# Terminal functions #
|
# Terminal functions #
|
||||||
@@ -475,9 +487,9 @@ def do_patch(sourceDir, patchFile, level = 0, target = ''):
|
|||||||
target = ''
|
target = ''
|
||||||
|
|
||||||
check_file(patchFile)
|
check_file(patchFile)
|
||||||
(successful, lines) = run_batch("patch -p%d %s< %s" %
|
(ret, out) = run_batch("patch -p%d %s< %s" %
|
||||||
(level, target, patchFile))
|
(level, target, patchFile))
|
||||||
if not successful:
|
if ret:
|
||||||
raise Error(_("ERROR: patch (%s) failed: %s") % (patchFile,
|
raise Error(_("ERROR: patch (%s) failed: %s") % (patchFile,
|
||||||
strlist (lines)))
|
strlist (lines)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user