1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/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 description(args):
name = args["name"]
description = args["description"]
git_dir = f"/srv/git/{name}.git"
subprocess.run([
"ssh", "git@marks.kitchen", f"echo '{description}' > {git_dir}/description"])
def add_gpl(args):
subprocess.run(["wget", "--output-document=LICENSE",
"https://www.gnu.org/licenses/gpl-3.0.txt"])
subprocess.run(["git", "add", "LICENSE"])
subprocess.run(["git", "commit", "-m", "Add LICENSE"])
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)
parser_license = subparsers.add_parser("license", help="add license")
parser_license.set_defaults(command=add_gpl)
parser_description = subparsers.add_parser("description", help="set description")
parser_description.add_argument("name", type=str, help="repo name")
parser_description.add_argument("description", type=str, help="description")
parser_description.set_defaults(command=description)
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()
|