🗝
summary refs log tree commit diff
path: root/packages/local.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/local.py')
-rw-r--r--packages/local.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/local.py b/packages/local.py
new file mode 100644
index 0000000..3ef4ea9
--- /dev/null
+++ b/packages/local.py
@@ -0,0 +1,51 @@
+import os
+import shutil
+import subprocess
+import sys
+
+from commia.prelude import *
+from commia.ssh import ssh_args, ssh_opt_args
+
+
+def build_push(name):
+    path = Path(f"packages/{name}")
+    git_ignore = (path / ".gitignore").exists()
+    for pkg in path.glob("*.pkg.tar"):
+        os.remove(pkg)
+    env = {"PKGEXT": ".pkg.tar", **os.environ}
+    run_check(["makepkg", "--clean", "--syncdeps", "--cleanbuild"], cwd=path, env=env)
+    for pkg in path.glob("*.pkg.tar"):
+        run_sc(["scp", *ssh_opt_args(), pkg.as_posix(), f"asylum:/tmp/{pkg.name}"])
+        run_check(
+            [*ssh_args(), "pacman", "-U", f"/tmp/{pkg.name}"], input="y\n".encode()
+        )
+        run_sc(
+            ["sftp", "-b", "-", *ssh_opt_args(), "asylum"],
+            input=f"rm /tmp/{pkg.name}".encode(),
+        )
+        os.remove(pkg)
+    if git_ignore:
+        ignored = subprocess.check_output(
+            [
+                "git",
+                "ls-files",
+                "--others",
+                "--directory",
+                "--ignored",
+                "--exclude-from=.gitignore",
+            ],
+            cwd=path,
+            text=True,
+        )
+        for name in ignored.splitlines():
+            if ".." in name or name.startswith("/"):
+                continue
+            if (path / name).is_dir():
+                shutil.rmtree(path / name)
+            else:
+                os.remove(path / name)
+
+
+if __name__ == "__main__":
+    for name in sys.argv[1:]:
+        build_push(name)