aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/remote_build.py88
1 files changed, 46 insertions, 42 deletions
diff --git a/scripts/remote_build.py b/scripts/remote_build.py
index c5787f635..08e44c9ad 100644
--- a/scripts/remote_build.py
+++ b/scripts/remote_build.py
@@ -53,14 +53,11 @@ def _find_binary(name):
raise EnvironmentError(f"Unable to find '{name}' in the path")
#-------------------------------------------------------------------------------
-class _AutoKill(object):
- def __init__(self, proc):
- self._proc = proc
-
+class _DaemonAutoKill(object):
def __del__(self):
- self._proc.kill()
- self._proc.wait()
- pass
+ # Roundabout way to avoid orphaned git-daemon processes
+ if os.name == "nt":
+ os.system("taskkill /f /im git-daemon.exe")
@@ -73,7 +70,10 @@ def _local(args):
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("remotehost", help="")
parser.add_argument("action", default="build", nargs="?", help="")
+ parser.add_argument("--commit", default=None, help="Commit to act on")
parser.add_argument("--keyfile", default=None, help="SSH key file")
+ parser.add_argument("--gitport", default=None, help="Use an exist git daemon at the given port")
+ parser.add_argument("--outdir", default=None, help="Put .zip bundles here")
args = parser.parse_args(args)
# Find the binaries we'll need
@@ -135,28 +135,38 @@ def _local(args):
print(f"Using host '{host}'")
# Start a git daemon to use as a transfer mechanism
- _header("Starting a git daemon")
- print("Port: 4493")
- print("Base-path: ", zen_dir)
- print("Host: ", _get_ip())
- daemon = subprocess.Popen(
- ( git_bin,
- "daemon",
- "--port=4493",
- "--export-all",
- "--reuseaddr",
- "--verbose",
- "--informative-errors",
- "--base-path=" + str(zen_dir) ),
- #stdout = daemon_log,
- stderr = subprocess.STDOUT
- )
- daemon_killer = _AutoKill(daemon)
+ _header("Git daemon")
+ daemon_port = args.gitport
+ if not daemon_port:
+ daemon_port = 4493
+
+ print("Starting out own one up")
+ print("Port:", daemon_port)
+ print("Base-path: ", zen_dir)
+ print("Host: ", _get_ip())
+ daemon = subprocess.Popen(
+ ( git_bin,
+ "daemon",
+ "--port=" + str(daemon_port),
+ "--export-all",
+ "--reuseaddr",
+ "--verbose",
+ "--informative-errors",
+ "--base-path=" + str(zen_dir) ),
+ #stdout = daemon_log,
+ stderr = subprocess.STDOUT
+ )
+ daemon_killer = _DaemonAutoKill()
+ else:
+ print("Using existing instance")
+ print("Port:", daemon_port)
# Run this script on the remote machine
_header("Running SSH")
- remote_zen_dir = "%s_%s" % (os.getlogin(), _get_ip())
+ commit = args.commit if args.commit else "origin/main"
+
+ remote_zen_dir = "%s_%s_%s" % (os.getlogin(), _get_ip(), str(daemon_port))
print(f"Using zen '~/{remote_zen_dir}'")
print(f"Running {__file__} remotely")
@@ -166,12 +176,12 @@ def _local(args):
*identity,
"-tA",
host,
- f"python3 -u - !remote {_get_ip()} '{remote_zen_dir}' main '{args.action}'",
+ f"python3 -u - !remote {_get_ip()}:{daemon_port} '{remote_zen_dir}' {commit} '{args.action}'",
stdin=self_file)
# If we're bundling, collect zip files from the remote machine
if args.action == "bundle":
- build_dir = zen_dir / "build"
+ build_dir = Path(args.outdir) or (zen_dir / "build")
build_dir.mkdir(exist_ok=True)
scp_args = (*identity, host + f":zen/{remote_zen_dir}/build/*.zip", build_dir)
_run_checked("scp", *scp_args)
@@ -185,9 +195,9 @@ def _remote(args):
# Parse arguments
desc = "Build Zen on a remote host"
parser = argparse.ArgumentParser(description=desc)
- parser.add_argument("ip", help="Host's IP address")
+ parser.add_argument("gitaddr", help="Host's Git daemon address")
parser.add_argument("reponame", help="Repository name clone into and work in")
- parser.add_argument("branch", help="Zen branch to operate on")
+ parser.add_argument("commit", help="Zen commit to operate on")
parser.add_argument("action", help="The action to do")
args = parser.parse_args(args)
@@ -203,14 +213,15 @@ def _remote(args):
"""
# Check for a clone, create it, chdir to it
- _header("REMOTE:", f"Clone/pull from {args.ip}")
+ _header("REMOTE:", f"Clone/pull from {args.gitaddr}")
clone_dir = zen_dir / args.reponame
if not clone_dir.is_dir():
- _run_checked("git", "clone", f"git://{args.ip}:4493/", clone_dir)
+ _run_checked("git", "clone", f"git://{args.gitaddr}/", clone_dir)
os.chdir(clone_dir)
- _run_checked("git", "checkout", args.branch)
- _run_checked("git", "pull", "-r")
+ _run_checked("git", "clean", "-fd")
+ _run_checked("git", "fetch", "origin")
+ _run_checked("git", "checkout", args.commit)
_header("REMOTE:", f"Performing action '{args.action}'")
@@ -257,14 +268,7 @@ if __name__ == "__main__":
ret = _remote(sys.argv[2:])
raise SystemExit(ret)
- try:
- ret = _local(sys.argv[1:])
- raise SystemExit(ret)
- except:
- raise
- finally:
- # Roundabout way to avoid orphaned git-daemon processes
- if os.name == "nt":
- os.system("taskkill /f /im git-daemon.exe")
+ ret = _local(sys.argv[1:])
+ raise SystemExit(ret)
# vim: expandtab foldlevel=1 foldmethod=marker