Remove duplicate run_with_tee.

This commit is contained in:
Jelmer Vernooij 2021-02-05 17:41:24 +00:00
parent b7f2f8dbe3
commit f6f6b5a696
No known key found for this signature in database
GPG key ID: 579C160D4C9E23E8
3 changed files with 16 additions and 24 deletions

View file

@ -21,6 +21,7 @@ import stat
import subprocess
import sys
from typing import List
from .session import run_with_tee
DEFAULT_PYTHON = 'python3'
@ -59,18 +60,6 @@ def warning(m):
sys.stderr.write('WARNING: %s\n' % m)
def run_with_tee(session, args: List[str], **kwargs):
p = session.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
contents = []
while p.poll() is None:
line = p.stdout.readline()
sys.stdout.buffer.write(line)
sys.stdout.buffer.flush()
contents.append(line.decode('utf-8', 'surrogateescape'))
return p.returncode, contents
def run_apt(session, args: List[str]) -> None:
args = ['apt', '-y'] + args
retcode, lines = run_with_tee(session, args, cwd='/', user='root')

View file

@ -33,6 +33,7 @@ from breezy.workingtree import WorkingTree
from breezy.plugins.debian.repack_tarball import get_filetype
from .session import run_with_tee
from .debian.fix_build import (
DependencyContext,
resolve_error,
@ -93,18 +94,6 @@ def satisfy_build_deps(session: Session, tree):
apt_satisfy(session, deps)
def run_with_tee(session: Session, args: List[str], **kwargs):
p = session.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
contents = []
while p.poll() is None:
line = p.stdout.readline()
sys.stdout.buffer.write(line)
sys.stdout.buffer.flush()
contents.append(line.decode('utf-8', 'surrogateescape'))
return p.returncode, contents
class SchrootDependencyContext(DependencyContext):
def __init__(self, session):

View file

@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from typing import Optional, List, Dict
import sys
import subprocess
class Session(object):
@ -64,3 +66,15 @@ class Session(object):
class SessionSetupFailure(Exception):
"""Session failed to be set up."""
def run_with_tee(session: Session, args: List[str], **kwargs):
p = session.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
contents = []
while p.poll() is None:
line = p.stdout.readline()
sys.stdout.buffer.write(line)
sys.stdout.buffer.flush()
contents.append(line.decode('utf-8', 'surrogateescape'))
return p.returncode, contents