Browse Source

String override

develop
William Petit 2 years ago
parent
commit
110097ec81
2 changed files with 10 additions and 6 deletions
  1. 7
    2
      lib/tamarin.py
  2. 3
    4
      package

+ 7
- 2
lib/tamarin.py View File

@@ -52,8 +52,9 @@ def get_workspace_subdir(subdir):
52 52
 def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
53 53
     """Execute an arbitrary command on the system"""
54 54
     if debug:
55
-        print(" ".join(cmd))
55
+        print(" ".join(cmd) if isinstance(cmd, list) else cmd)
56 56
     stdin=subprocess.PIPE
57
+    kwargs['shell'] = False if isinstance(cmd, list) else True
57 58
     if pty:
58 59
         kwargs['stdin'] = sys.stdin
59 60
     if captureOutput:
@@ -62,4 +63,8 @@ def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
62 63
         return subprocess.check_call(cmd, **kwargs)
63 64
 
64 65
 def run_docker(args, captureOutput=False, **kwargs):
65
-    return run(["docker"] + args, captureOutput=captureOutput, **kwargs)
66
+    if isinstance(args, list):
67
+        cmd = ["docker"] + args
68
+    else:
69
+        cmd = "docker " + args
70
+    return run(cmd, captureOutput=captureOutput, **kwargs)

+ 3
- 4
package View File

@@ -21,7 +21,7 @@ def create_args_parser():
21 21
     parser.add_argument("--rebuild", help="Ignore cache and rebuild container's image", action="store_true", default=False)
22 22
     parser.add_argument("--debug", help="Will add extra output and start the container in interactive mode", action="store_true", default=False)
23 23
     parser.add_argument("--cleanup", help="Clear the workspace and remove obsolete Docker images before build", action="store_true", default=False)
24
-    parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. You can use this flag multiple times to add custom arguments", default=[], action='append')
24
+    parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. Use '[IMAGE_TAG]' to insert the generated image's name.", default="")
25 25
 
26 26
     return parser
27 27
 
@@ -89,9 +89,8 @@ if __name__ == "__main__":
89 89
     docker_args = []
90 90
 
91 91
     # Append custom arguments
92
-    if len(args.override_docker_args) > 0:
93
-        docker_args += args.override_docker_args
94
-        docker_args = [a.replace('[IMAGE_TAG]', image_tag) for a in docker_args]
92
+    if args.override_docker_args != "":
93
+        docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag)
95 94
     else:
96 95
 
97 96
         docker_args += [ "run", "--rm" ]

Loading…
Cancel
Save