summaryrefslogtreecommitdiff
path: root/chip/push
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-06-14 17:16:45 -0700
committerBen Sima <ben@bsima.me>2019-06-16 01:53:35 +0000
commitcfd075cfdd7ed5b98770f1fdab1af3e51030bf5e (patch)
tree5718b7e95fcf863ac2d10f6bc5439d1eefab0ac9 /chip/push
parent79a4fc76167f57a5ae65be789980dd2f7ee8b635 (diff)
chip: refactor push to have a shell function
This handles subprocess errors better and makes the code easier to follow.
Diffstat (limited to 'chip/push')
-rwxr-xr-xchip/push27
1 files changed, 15 insertions, 12 deletions
diff --git a/chip/push b/chip/push
index 96cc893..1b8c1f8 100755
--- a/chip/push
+++ b/chip/push
@@ -6,6 +6,14 @@ import subprocess
import tempfile
import importlib.util
+def shell(*args):
+ "Run a shell command and capture the output."
+ try:
+ proc = subprocess.run(args, check=True, capture_output=True)
+ except subprocess.CalledProcessError as e:
+ raise RuntimeError(f'{e.cmd} error {e.returncode}: {e.output}')
+ return proc.stdout.strip().decode('utf8')
+
cli = argparse.ArgumentParser(description='deploy a thing')
cli.add_argument('depo', type=str,
help='the depo roun to deploy')
@@ -20,22 +28,17 @@ out = f"{bild_dir}/{args.depo}"
# bild
-subprocess.run(["nix-build", "-A", f"depo.{args.depo}",
- "--out-link", out])
+shell("nix-build", "-A", f"depo.{args.depo}", "--out-link", out)
print("bilt")
-# get roun
-p = subprocess.run(["chip/roun", args.depo, "-i"],
- stdout=subprocess.PIPE)
-ip = p.stdout.decode()
-
# push
-subprocess.run(["nix", "copy", "--to", f"ssh://root@{ip}", f"{out}"])
+shell("nix", "copy", "--to", f"ssh://root@{args.depo}", f"{out}")
print("sent")
# switch
-subprocess.run(["ssh", f"root@{ip}", "sudo",
- f"{os.readlink(out)}/bin/switch-to-configuration",
- "switch"])
+shell("ssh", f"root@{args.depo}", "sudo",
+ f"{os.readlink(out)}/bin/switch-to-configuration",
+ "switch")
+print("switched")
-print(f"pushed {args.depo} -> {ip}")
+print(f"pushed {args.depo}")