From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c12L4-0002ip-Vh for qemu-devel@nongnu.org; Sun, 30 Oct 2016 22:28:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c12L1-0003GM-RU for qemu-devel@nongnu.org; Sun, 30 Oct 2016 22:28:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c12L1-0003GH-Jk for qemu-devel@nongnu.org; Sun, 30 Oct 2016 22:28:39 -0400 Date: Mon, 31 Oct 2016 10:28:36 +0800 From: Fam Zheng Message-ID: <20161031022836.GH30303@lemon> References: <20161028163339.31096-1-alex.bennee@linaro.org> <20161028163339.31096-6-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20161028163339.31096-6-alex.bennee@linaro.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 5/6] tests/docker/docker.py: expand images command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: qemu-devel@nongnu.org On Fri, 10/28 17:33, Alex Benn=E9e wrote: > Modern docker cli commands can filter by repository but as we want to > work on all instances do this by hand in python: >=20 > /tests/docker/docker.py images --repo qemu >=20 > Will return a space delimited list for the benefit of our Makefile > recipes. >=20 > Signed-off-by: Alex Benn=E9e > --- > tests/docker/docker.py | 27 ++++++++++++++++++++++----- > 1 file changed, 22 insertions(+), 5 deletions(-) >=20 > diff --git a/tests/docker/docker.py b/tests/docker/docker.py > index 37d8319..03c0238 100755 > --- a/tests/docker/docker.py > +++ b/tests/docker/docker.py > @@ -105,12 +105,15 @@ class Docker(object): > signal.signal(signal.SIGTERM, self._kill_instances) > signal.signal(signal.SIGHUP, self._kill_instances) > =20 > - def _do(self, cmd, quiet=3DTrue, infile=3DNone, **kwargs): > + def _do(self, cmd, quiet=3DTrue, infile=3DNone, output=3DFalse, **= kwargs): > if quiet: > kwargs["stdout"] =3D DEVNULL > if infile: > kwargs["stdin"] =3D infile > - return subprocess.call(self._command + cmd, **kwargs) > + if output: > + return subprocess.check_output(self._command + cmd, **kwar= gs) > + else: > + return subprocess.call(self._command + cmd, **kwargs) > =20 > def _do_kill_instances(self, only_known, only_active=3DTrue): > cmd =3D ["ps", "-q"] > @@ -188,8 +191,8 @@ class Docker(object): > self._instances.remove(label) > return ret > =20 > - def command(self, cmd, argv, quiet): > - return self._do([cmd] + argv, quiet=3Dquiet) > + def command(self, cmd, argv, quiet, output=3DFalse): > + return self._do([cmd] + argv, quiet=3Dquiet, output=3Doutput) > =20 > class SubCommand(object): > """A SubCommand template base class""" > @@ -325,8 +328,22 @@ class CleanCommand(SubCommand): > class ImagesCommand(SubCommand): > """Run "docker images" command""" > name =3D "images" > + def args(self, parser): > + parser.add_argument("--repo", > + help=3D"List images in the given repositor= y") > + > def run(self, args, argv): > - return Docker().command("images", argv, args.quiet) > + if args.repo: > + images=3D[] > + image_re =3D re.compile(r"^"+re.escape(args.repo)+r"\s+(\S= *)") > + output =3D Docker().command("images", argv, args.quiet, ou= tput=3DTrue) > + for line in output.split("\n"): > + search =3D image_re.search(line) > + if search: > + images.append(search.group(1)) > + print ' '.join(map(str,images)) s/,/, / Otherwise looks good. > + else: > + return Docker().command("images", argv, args.quiet) > =20 > def main(): > parser =3D argparse.ArgumentParser(description=3D"A Docker helper"= , > --=20 > 2.10.1 >=20