asyncioify run_command_in_foreground
This commit is contained in:
parent
614ebc415e
commit
a92b88ed9d
|
@ -164,7 +164,7 @@ class Subiquity(Application):
|
||||||
print(DEBUG_SHELL_INTRO)
|
print(DEBUG_SHELL_INTRO)
|
||||||
|
|
||||||
self.run_command_in_foreground(
|
self.run_command_in_foreground(
|
||||||
"bash", before_hook=_before, cwd='/')
|
["bash"], before_hook=_before, cwd='/')
|
||||||
|
|
||||||
def note_file_for_apport(self, key, path):
|
def note_file_for_apport(self, key, path):
|
||||||
self._apport_files.append((key, path))
|
self._apport_files.append((key, path))
|
||||||
|
|
|
@ -19,13 +19,13 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import tty
|
import tty
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from subiquitycore.async_helpers import schedule_task
|
||||||
from subiquitycore.controller import (
|
from subiquitycore.controller import (
|
||||||
RepeatedController,
|
RepeatedController,
|
||||||
Skip,
|
Skip,
|
||||||
|
@ -33,6 +33,7 @@ from subiquitycore.controller import (
|
||||||
from subiquitycore.signals import Signal
|
from subiquitycore.signals import Signal
|
||||||
from subiquitycore.prober import Prober
|
from subiquitycore.prober import Prober
|
||||||
from subiquitycore.ui.frame import SubiquityCoreUI
|
from subiquitycore.ui.frame import SubiquityCoreUI
|
||||||
|
from subiquitycore.utils import arun_command
|
||||||
|
|
||||||
log = logging.getLogger('subiquitycore.core')
|
log = logging.getLogger('subiquitycore.core')
|
||||||
|
|
||||||
|
@ -415,10 +416,9 @@ class Application:
|
||||||
# there the symptom is that we are running in the foreground but not
|
# there the symptom is that we are running in the foreground but not
|
||||||
# listening to stdin! The fix is the same.
|
# listening to stdin! The fix is the same.
|
||||||
|
|
||||||
def run():
|
async def _run():
|
||||||
subprocess.run(cmd, **kw)
|
await arun_command(
|
||||||
|
cmd, stdin=None, stdout=None, stderr=None)
|
||||||
def restore(fut):
|
|
||||||
screen.start()
|
screen.start()
|
||||||
urwid.emit_signal(
|
urwid.emit_signal(
|
||||||
screen, urwid.display_common.INPUT_DESCRIPTORS_CHANGED)
|
screen, urwid.display_common.INPUT_DESCRIPTORS_CHANGED)
|
||||||
|
@ -431,7 +431,7 @@ class Application:
|
||||||
screen, urwid.display_common.INPUT_DESCRIPTORS_CHANGED)
|
screen, urwid.display_common.INPUT_DESCRIPTORS_CHANGED)
|
||||||
if before_hook is not None:
|
if before_hook is not None:
|
||||||
before_hook()
|
before_hook()
|
||||||
self.run_in_bg(run, restore)
|
schedule_task(_run())
|
||||||
|
|
||||||
def _connect_base_signals(self):
|
def _connect_base_signals(self):
|
||||||
"""Connect signals used in the core controller."""
|
"""Connect signals used in the core controller."""
|
||||||
|
|
|
@ -66,7 +66,8 @@ async def arun_command(cmd, *, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
encoding='utf-8', input=None, errors='replace',
|
encoding='utf-8', input=None, errors='replace',
|
||||||
env=None, check=False, **kw):
|
env=None, check=False, **kw):
|
||||||
if input is None:
|
if input is None:
|
||||||
kw['stdin'] = subprocess.DEVNULL
|
if 'stdin' not in kw:
|
||||||
|
kw['stdin'] = subprocess.DEVNULL
|
||||||
else:
|
else:
|
||||||
kw['stdin'] = subprocess.PIPE
|
kw['stdin'] = subprocess.PIPE
|
||||||
input = input.encode(encoding)
|
input = input.encode(encoding)
|
||||||
|
@ -75,8 +76,10 @@ async def arun_command(cmd, *, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
*cmd, stdout=stdout, stderr=stderr, env=_clean_env(env), **kw)
|
*cmd, stdout=stdout, stderr=stderr, env=_clean_env(env), **kw)
|
||||||
stdout, stderr = await proc.communicate(input=input)
|
stdout, stderr = await proc.communicate(input=input)
|
||||||
if encoding:
|
if encoding:
|
||||||
stdout = stdout.decode(encoding)
|
if stdout is not None:
|
||||||
stderr = stderr.decode(encoding)
|
stdout = stdout.decode(encoding)
|
||||||
|
if stderr is not None:
|
||||||
|
stderr = stderr.decode(encoding)
|
||||||
log.debug("arun_command %s exited with code %s", cmd, proc.returncode)
|
log.debug("arun_command %s exited with code %s", cmd, proc.returncode)
|
||||||
if check and proc.returncode != 0:
|
if check and proc.returncode != 0:
|
||||||
raise subprocess.CalledProcessError(proc.returncode, cmd)
|
raise subprocess.CalledProcessError(proc.returncode, cmd)
|
||||||
|
|
Loading…
Reference in New Issue