mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Move run_command_interruptible() to utils
Make this function more easily reusable from the RRS code. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
50aab7c03a
commit
59b66d5505
|
@ -14,7 +14,6 @@ import optparse
|
||||||
import codecs
|
import codecs
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
import utils
|
import utils
|
||||||
|
@ -35,36 +34,6 @@ except ImportError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def reenable_sigint():
|
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
||||||
|
|
||||||
def run_command_interruptible(cmd):
|
|
||||||
"""
|
|
||||||
Run a command with output displayed on the console, but ensure any Ctrl+C is
|
|
||||||
processed only by the child process.
|
|
||||||
"""
|
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
||||||
try:
|
|
||||||
process = subprocess.Popen(
|
|
||||||
cmd, cwd=os.path.dirname(sys.argv[0]), shell=True, preexec_fn=reenable_sigint, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
|
||||||
)
|
|
||||||
|
|
||||||
reader = codecs.getreader('utf-8')(process.stdout, errors='surrogateescape')
|
|
||||||
buf = ''
|
|
||||||
while True:
|
|
||||||
out = reader.read(1, 1)
|
|
||||||
if out:
|
|
||||||
sys.stdout.write(out)
|
|
||||||
sys.stdout.flush()
|
|
||||||
buf += out
|
|
||||||
elif out == '' and process.poll() != None:
|
|
||||||
break
|
|
||||||
|
|
||||||
finally:
|
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
||||||
return process.returncode, buf
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_update_layer_command(options, branch, layer, initial=False):
|
def prepare_update_layer_command(options, branch, layer, initial=False):
|
||||||
"""Prepare the update_layer.py command line"""
|
"""Prepare the update_layer.py command line"""
|
||||||
if branch.update_environment:
|
if branch.update_environment:
|
||||||
|
@ -417,7 +386,7 @@ def main():
|
||||||
|
|
||||||
cmd = prepare_update_layer_command(options, branchobj, layer, initial=True)
|
cmd = prepare_update_layer_command(options, branchobj, layer, initial=True)
|
||||||
logger.debug('Running layer update command: %s' % cmd)
|
logger.debug('Running layer update command: %s' % cmd)
|
||||||
ret, output = run_command_interruptible(cmd)
|
ret, output = utils.run_command_interruptible(cmd)
|
||||||
logger.debug('output: %s' % output)
|
logger.debug('output: %s' % output)
|
||||||
if ret == 254:
|
if ret == 254:
|
||||||
# Interrupted by user, break out of loop
|
# Interrupted by user, break out of loop
|
||||||
|
@ -491,7 +460,7 @@ def main():
|
||||||
cmd = prepare_update_layer_command(options, branchobj, layer)
|
cmd = prepare_update_layer_command(options, branchobj, layer)
|
||||||
logger.debug('Running layer update command: %s' % cmd)
|
logger.debug('Running layer update command: %s' % cmd)
|
||||||
layerupdate.started = datetime.now()
|
layerupdate.started = datetime.now()
|
||||||
ret, output = run_command_interruptible(cmd)
|
ret, output = utils.run_command_interruptible(cmd)
|
||||||
layerupdate.finished = datetime.now()
|
layerupdate.finished = datetime.now()
|
||||||
|
|
||||||
# We need to get layerbranch here because it might not have existed until
|
# We need to get layerbranch here because it might not have existed until
|
||||||
|
|
|
@ -12,6 +12,8 @@ import subprocess
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import signal
|
||||||
|
import codecs
|
||||||
|
|
||||||
def get_branch(branchname):
|
def get_branch(branchname):
|
||||||
from layerindex.models import Branch
|
from layerindex.models import Branch
|
||||||
|
@ -353,3 +355,32 @@ def setup_core_layer_sys_path(settings, branchname):
|
||||||
core_repodir = os.path.join(settings.LAYER_FETCH_DIR, core_urldir)
|
core_repodir = os.path.join(settings.LAYER_FETCH_DIR, core_urldir)
|
||||||
core_layerdir = os.path.join(core_repodir, core_layerbranch.vcs_subdir)
|
core_layerdir = os.path.join(core_repodir, core_layerbranch.vcs_subdir)
|
||||||
sys.path.insert(0, os.path.join(core_layerdir, 'lib'))
|
sys.path.insert(0, os.path.join(core_layerdir, 'lib'))
|
||||||
|
|
||||||
|
def run_command_interruptible(cmd):
|
||||||
|
"""
|
||||||
|
Run a command with output displayed on the console, but ensure any Ctrl+C is
|
||||||
|
processed only by the child process.
|
||||||
|
"""
|
||||||
|
def reenable_sigint():
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
try:
|
||||||
|
process = subprocess.Popen(
|
||||||
|
cmd, cwd=os.path.dirname(sys.argv[0]), shell=True, preexec_fn=reenable_sigint, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
|
||||||
|
reader = codecs.getreader('utf-8')(process.stdout, errors='surrogateescape')
|
||||||
|
buf = ''
|
||||||
|
while True:
|
||||||
|
out = reader.read(1, 1)
|
||||||
|
if out:
|
||||||
|
sys.stdout.write(out)
|
||||||
|
sys.stdout.flush()
|
||||||
|
buf += out
|
||||||
|
elif out == '' and process.poll() != None:
|
||||||
|
break
|
||||||
|
|
||||||
|
finally:
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
return process.returncode, buf
|
||||||
|
|
Loading…
Reference in New Issue
Block a user