diff mbox series

[v2,01/43] docker: add "probe" command for configure

Message ID 20180419135901.30035-2-alex.bennee@linaro.org
State Superseded
Headers show
Series fix building of tests/tcg | expand

Commit Message

Alex Bennée April 19, 2018, 1:58 p.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>


This is a helper function for the configure script. It replies yes,
sudo or no to inform the user if non-interactive docker support is
available. We trap the Exception to fail gracefully.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 tests/docker/docker.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

-- 
2.17.0

Comments

Fam Zheng April 20, 2018, 2:08 a.m. UTC | #1
On Thu, 04/19 14:58, Alex Bennée wrote:
> From: Peter Maydell <peter.maydell@linaro.org>

> 

> This is a helper function for the configure script. It replies yes,

> sudo or no to inform the user if non-interactive docker support is

> available. We trap the Exception to fail gracefully.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  tests/docker/docker.py | 18 ++++++++++++++++++

>  1 file changed, 18 insertions(+)

> 

> diff --git a/tests/docker/docker.py b/tests/docker/docker.py

> index 1246ba9578..f8267586eb 100755

> --- a/tests/docker/docker.py

> +++ b/tests/docker/docker.py

> @@ -390,6 +390,24 @@ class ImagesCommand(SubCommand):

>      def run(self, args, argv):

>          return Docker().command("images", argv, args.quiet)

>  

> +

> +class ProbeCommand(SubCommand):

> +    """Probe if we can run docker automatically"""

> +    name = "probe"

> +

> +    def run(self, args, argv):

> +        try:

> +            docker = Docker()

> +            if docker._command[0] == "docker":

> +                print "yes"

> +            elif docker._command[0] == "sudo":

> +                print "sudo"

> +        except Exception:

> +            print "no"


Non-zero exit code is better in 'no' case, but I guess it's not required by
configure. Either way:

Reviewed-by: Fam Zheng <famz@redhat.com>



> +

> +        return

> +

> +

>  def main():

>      parser = argparse.ArgumentParser(description="A Docker helper",

>              usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))

> -- 

> 2.17.0

>
diff mbox series

Patch

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 1246ba9578..f8267586eb 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -390,6 +390,24 @@  class ImagesCommand(SubCommand):
     def run(self, args, argv):
         return Docker().command("images", argv, args.quiet)
 
+
+class ProbeCommand(SubCommand):
+    """Probe if we can run docker automatically"""
+    name = "probe"
+
+    def run(self, args, argv):
+        try:
+            docker = Docker()
+            if docker._command[0] == "docker":
+                print "yes"
+            elif docker._command[0] == "sudo":
+                print "sudo"
+        except Exception:
+            print "no"
+
+        return
+
+
 def main():
     parser = argparse.ArgumentParser(description="A Docker helper",
             usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))