docker: add "probe" command for configure

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>
This commit is contained in:
Alex Bennée 2018-05-10 10:45:55 +01:00
parent 1d889f2a8b
commit 15df9d3783

View File

@ -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]))