# HG changeset patch
# User Georges Racinet <georges.racinet@octobus.net>
# Date 1608034529 -3600
#      Tue Dec 15 13:15:29 2020 +0100
# Node ID cdf109f157f132e03d75e0b9b795253e3d71ddc8
# Parent  11ab298f4aa5cce57f448c494b713d52f9e991d5
Docker push/pull script: made push optional

…and rewritten in Python for safe command line arguments
parsing.

diff --git a/registry-pull-heptapod-push-docker b/registry-pull-heptapod-push-docker
--- a/registry-pull-heptapod-push-docker
+++ b/registry-pull-heptapod-push-docker
@@ -1,10 +1,19 @@
-#!/bin/sh
+#!/usr/bin/env python3
+import argparse
+import subprocess
 
-TAG=testing
+TAG="testing"
+HEPTAPOD_REGISTRY_IMAGE="registry.heptapod.net:443/heptapod/omnibus-heptapod:" + TAG
+TARGET_IMAGE="octobus/heptapod:" + TAG
 
-HEPTAPOD_REGISTRY_IMAGE=registry.heptapod.net:443/heptapod/omnibus-heptapod:$TAG
-TARGET_IMAGE=octobus/heptapod:$TAG
+parser = argparse.ArgumentParser(
+    description="Pull Heptapod image from registry.h.n and tag it "
+    "for Docker Hub and the launch script"
+)
+parser.add_argument("--push", help="Push to Docker Hub", action="store_true")
+cl_args = parser.parse_args()
 
-docker pull $HEPTAPOD_REGISTRY_IMAGE
-docker tag $HEPTAPOD_REGISTRY_IMAGE $TARGET_IMAGE
-docker push $TARGET_IMAGE
+subprocess.check_call(("docker", "pull", HEPTAPOD_REGISTRY_IMAGE))
+subprocess.check_call(("docker", "tag", HEPTAPOD_REGISTRY_IMAGE, TARGET_IMAGE))
+if cl_args.push:
+   subprocess.check_call(("docker", "push", TARGET_IMAGE))