docker: add "probe" command for configure
authorAlex Bennée <alex.bennee@linaro.org>
Thu, 10 May 2018 09:45:55 +0000 (10:45 +0100)
committerAlex Bennée <alex.bennee@linaro.org>
Tue, 5 Jun 2018 15:25:42 +0000 (16:25 +0100)
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>
Reviewed-by: Fam Zheng <famz@redhat.com>
tests/docker/docker.py

index 1246ba9578730919cb1a926ed597a90328bb688c..f8267586eb620066499eb5a942121d21874ec8e8 100755 (executable)
@@ -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]))