tests: PEP8 cleanup of docker.py, mostly white space
My editor keeps putting squiggly lines under a bunch of the python lines to remind me how non-PEP8 compliant it is. Clean that up so it's easier to spot new errors. Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
This commit is contained in:
parent
d10404b193
commit
432d8ad5f6
|
@ -43,9 +43,11 @@ def _text_checksum(text):
|
||||||
"""Calculate a digest string unique to the text content"""
|
"""Calculate a digest string unique to the text content"""
|
||||||
return hashlib.sha1(text).hexdigest()
|
return hashlib.sha1(text).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def _file_checksum(filename):
|
def _file_checksum(filename):
|
||||||
return _text_checksum(open(filename, 'rb').read())
|
return _text_checksum(open(filename, 'rb').read())
|
||||||
|
|
||||||
|
|
||||||
def _guess_docker_command():
|
def _guess_docker_command():
|
||||||
""" Guess a working docker command or raise exception if not found"""
|
""" Guess a working docker command or raise exception if not found"""
|
||||||
commands = [["docker"], ["sudo", "-n", "docker"]]
|
commands = [["docker"], ["sudo", "-n", "docker"]]
|
||||||
|
@ -59,9 +61,10 @@ def _guess_docker_command():
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
commands_txt = "\n".join([" " + " ".join(x) for x in commands])
|
commands_txt = "\n".join([" " + " ".join(x) for x in commands])
|
||||||
raise Exception("Cannot find working docker command. Tried:\n%s" % \
|
raise Exception("Cannot find working docker command. Tried:\n%s" %
|
||||||
commands_txt)
|
commands_txt)
|
||||||
|
|
||||||
|
|
||||||
def _copy_with_mkdir(src, root_dir, sub_path='.'):
|
def _copy_with_mkdir(src, root_dir, sub_path='.'):
|
||||||
"""Copy src into root_dir, creating sub_path as needed."""
|
"""Copy src into root_dir, creating sub_path as needed."""
|
||||||
dest_dir = os.path.normpath("%s/%s" % (root_dir, sub_path))
|
dest_dir = os.path.normpath("%s/%s" % (root_dir, sub_path))
|
||||||
|
@ -96,6 +99,7 @@ def _get_so_libs(executable):
|
||||||
|
|
||||||
return libs
|
return libs
|
||||||
|
|
||||||
|
|
||||||
def _copy_binary_with_libs(src, bin_dest, dest_dir):
|
def _copy_binary_with_libs(src, bin_dest, dest_dir):
|
||||||
"""Maybe copy a binary and all its dependent libraries.
|
"""Maybe copy a binary and all its dependent libraries.
|
||||||
|
|
||||||
|
@ -142,7 +146,7 @@ def _check_binfmt_misc(executable):
|
||||||
with open(binfmt_entry) as x: entry = x.read()
|
with open(binfmt_entry) as x: entry = x.read()
|
||||||
|
|
||||||
if re.search("flags:.*F.*\n", entry):
|
if re.search("flags:.*F.*\n", entry):
|
||||||
print("binfmt_misc for %s uses persistent(F) mapping to host binary\n" %
|
print("binfmt_misc for %s uses persistent(F) mapping to host binary" %
|
||||||
(binary))
|
(binary))
|
||||||
return None, True
|
return None, True
|
||||||
|
|
||||||
|
@ -164,6 +168,7 @@ def _read_qemu_dockerfile(img_name):
|
||||||
img_name + ".docker")
|
img_name + ".docker")
|
||||||
return open(df, "r").read()
|
return open(df, "r").read()
|
||||||
|
|
||||||
|
|
||||||
def _dockerfile_preprocess(df):
|
def _dockerfile_preprocess(df):
|
||||||
out = ""
|
out = ""
|
||||||
for l in df.splitlines():
|
for l in df.splitlines():
|
||||||
|
@ -181,6 +186,7 @@ def _dockerfile_preprocess(df):
|
||||||
out += l + "\n"
|
out += l + "\n"
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
class Docker(object):
|
class Docker(object):
|
||||||
""" Running Docker commands """
|
""" Running Docker commands """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -248,7 +254,7 @@ class Docker(object):
|
||||||
|
|
||||||
def build_image(self, tag, docker_dir, dockerfile,
|
def build_image(self, tag, docker_dir, dockerfile,
|
||||||
quiet=True, user=False, argv=None, extra_files_cksum=[]):
|
quiet=True, user=False, argv=None, extra_files_cksum=[]):
|
||||||
if argv == None:
|
if argv is None:
|
||||||
argv = []
|
argv = []
|
||||||
|
|
||||||
tmp_df = tempfile.NamedTemporaryFile(dir=docker_dir, suffix=".docker")
|
tmp_df = tempfile.NamedTemporaryFile(dir=docker_dir, suffix=".docker")
|
||||||
|
@ -269,7 +275,7 @@ class Docker(object):
|
||||||
|
|
||||||
tmp_df.flush()
|
tmp_df.flush()
|
||||||
|
|
||||||
self._do_check(["build", "-t", tag, "-f", tmp_df.name] + argv + \
|
self._do_check(["build", "-t", tag, "-f", tmp_df.name] + argv +
|
||||||
[docker_dir],
|
[docker_dir],
|
||||||
quiet=quiet)
|
quiet=quiet)
|
||||||
|
|
||||||
|
@ -299,9 +305,11 @@ class Docker(object):
|
||||||
def command(self, cmd, argv, quiet):
|
def command(self, cmd, argv, quiet):
|
||||||
return self._do([cmd] + argv, quiet=quiet)
|
return self._do([cmd] + argv, quiet=quiet)
|
||||||
|
|
||||||
|
|
||||||
class SubCommand(object):
|
class SubCommand(object):
|
||||||
"""A SubCommand template base class"""
|
"""A SubCommand template base class"""
|
||||||
name = None # Subcommand name
|
name = None # Subcommand name
|
||||||
|
|
||||||
def shared_args(self, parser):
|
def shared_args(self, parser):
|
||||||
parser.add_argument("--quiet", action="store_true",
|
parser.add_argument("--quiet", action="store_true",
|
||||||
help="Run quietly unless an error occurred")
|
help="Run quietly unless an error occurred")
|
||||||
|
@ -309,6 +317,7 @@ class SubCommand(object):
|
||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
"""Setup argument parser"""
|
"""Setup argument parser"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, args, argv):
|
def run(self, args, argv):
|
||||||
"""Run command.
|
"""Run command.
|
||||||
args: parsed argument by argument parser.
|
args: parsed argument by argument parser.
|
||||||
|
@ -316,18 +325,23 @@ class SubCommand(object):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RunCommand(SubCommand):
|
class RunCommand(SubCommand):
|
||||||
"""Invoke docker run and take care of cleaning up"""
|
"""Invoke docker run and take care of cleaning up"""
|
||||||
name = "run"
|
name = "run"
|
||||||
|
|
||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
parser.add_argument("--keep", action="store_true",
|
parser.add_argument("--keep", action="store_true",
|
||||||
help="Don't remove image when command completes")
|
help="Don't remove image when command completes")
|
||||||
|
|
||||||
def run(self, args, argv):
|
def run(self, args, argv):
|
||||||
return Docker().run(argv, args.keep, quiet=args.quiet)
|
return Docker().run(argv, args.keep, quiet=args.quiet)
|
||||||
|
|
||||||
|
|
||||||
class BuildCommand(SubCommand):
|
class BuildCommand(SubCommand):
|
||||||
""" Build docker image out of a dockerfile. Arguments: <tag> <dockerfile>"""
|
""" Build docker image out of a dockerfile. Arg: <tag> <dockerfile>"""
|
||||||
name = "build"
|
name = "build"
|
||||||
|
|
||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
parser.add_argument("--include-executable", "-e",
|
parser.add_argument("--include-executable", "-e",
|
||||||
help="""Specify a binary that will be copied to the
|
help="""Specify a binary that will be copied to the
|
||||||
|
@ -402,9 +416,11 @@ class BuildCommand(SubCommand):
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class UpdateCommand(SubCommand):
|
class UpdateCommand(SubCommand):
|
||||||
""" Update a docker image with new executables. Arguments: <tag> <executable>"""
|
""" Update a docker image with new executables. Args: <tag> <executable>"""
|
||||||
name = "update"
|
name = "update"
|
||||||
|
|
||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
parser.add_argument("tag",
|
parser.add_argument("tag",
|
||||||
help="Image Tag")
|
help="Image Tag")
|
||||||
|
@ -457,16 +473,20 @@ class UpdateCommand(SubCommand):
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class CleanCommand(SubCommand):
|
class CleanCommand(SubCommand):
|
||||||
"""Clean up docker instances"""
|
"""Clean up docker instances"""
|
||||||
name = "clean"
|
name = "clean"
|
||||||
|
|
||||||
def run(self, args, argv):
|
def run(self, args, argv):
|
||||||
Docker().clean()
|
Docker().clean()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class ImagesCommand(SubCommand):
|
class ImagesCommand(SubCommand):
|
||||||
"""Run "docker images" command"""
|
"""Run "docker images" command"""
|
||||||
name = "images"
|
name = "images"
|
||||||
|
|
||||||
def run(self, args, argv):
|
def run(self, args, argv):
|
||||||
return Docker().command("images", argv, args.quiet)
|
return Docker().command("images", argv, args.quiet)
|
||||||
|
|
||||||
|
@ -539,7 +559,7 @@ class CheckCommand(SubCommand):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dkr = Docker()
|
dkr = Docker()
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
print("Docker not set up")
|
print("Docker not set up")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -578,7 +598,8 @@ class CheckCommand(SubCommand):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="A Docker helper",
|
parser = argparse.ArgumentParser(description="A Docker helper",
|
||||||
usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))
|
usage="%s <subcommand> ..." %
|
||||||
|
os.path.basename(sys.argv[0]))
|
||||||
subparsers = parser.add_subparsers(title="subcommands", help=None)
|
subparsers = parser.add_subparsers(title="subcommands", help=None)
|
||||||
for cls in SubCommand.__subclasses__():
|
for cls in SubCommand.__subclasses__():
|
||||||
cmd = cls()
|
cmd = cls()
|
||||||
|
@ -589,5 +610,6 @@ def main():
|
||||||
args, argv = parser.parse_known_args()
|
args, argv = parser.parse_known_args()
|
||||||
return args.cmdobj.run(args, argv)
|
return args.cmdobj.run(args, argv)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in a new issue