#!/usr/bin/python3 import requests import argparse import subprocess import os gitweb_url = "https://git.marks.kitchen" def list_repos(args): r = requests.get(f"{gitweb_url}/repos.cgi") for line in r.text.splitlines(): title, remote, desc = line.split(",", 2) print(title) print("\t", desc) print("\t", remote) def clone_repo(args): r = requests.get(f"{gitweb_url}/repos.cgi") for line in r.text.splitlines(): title, remote, _ = line.split(",", 2) if title == args["repo"]: subprocess.run(["git", "clone", remote]) def init_repo(args): name = os.path.basename(os.getcwd()) git_dir = f"/srv/git/{name}.git" r = subprocess.run(["ssh", "git@marks.kitchen", f"mkdir {git_dir}"]) if r.returncode == 0: subprocess.run(["ssh", "git@marks.kitchen", f"cd \"{git_dir}\"; git init --bare; touch git-daemon-export-ok"]) subprocess.run(["git", "init"]) subprocess.run(["git", "remote", "add", "origin", f"git@marks.kitchen:{git_dir}"]) #subprocess.run(["git", "branch", "--set-upstream-to=origin/master", "master"]) #subprocess.run(["git", "push", "--set-upstream", "origin", "master"]) else: print("Repo already exists") def main(): parser = argparse.ArgumentParser("wikijscmd") parser.set_defaults(command=None) subparsers = parser.add_subparsers() parser_list = subparsers.add_parser("list", help="list repos") parser_list.set_defaults(command=list_repos) parser_clone = subparsers.add_parser("clone", help="clone a repo") parser_clone.add_argument("repo", type=str, help="repo name") parser_clone.set_defaults(command=clone_repo) parser_init = subparsers.add_parser("init", help="create repos") parser_init.set_defaults(command=init_repo) args = vars(parser.parse_args()) callback = args["command"] if callback is None: parser.print_help() else: del args["command"] callback(args) if __name__ == "__main__": main()