add the gitmanager

This commit is contained in:
randomuser 2021-07-19 23:42:27 -05:00
parent 839d0afdea
commit 3631577fc2
3 changed files with 155 additions and 0 deletions

View File

@ -1,3 +1,5 @@
install:
cp -f phman/phman.py $(PREFIX)$(DESTDIR)/phman
chmod +x $(PREFIX)$(DESTDIR)/phman
cp -f gitman/gitman.py $(PREFIX)$(DESTDIR)/phman
chmod +x $(PREFIX)$(DESTDIR)/gitman

150
gitman/gitman.py Executable file
View File

@ -0,0 +1,150 @@
#!/usr/bin/python3
# hi there traveler, you are reading the messy source code for
# my git directory generator
# in order for this to works, you need the python package
# gitpython (i installed it via `sudo pip3 install gitpython`)
# also, you need git config pull.rebase true set in your
# git settings
# thanks
import git
import time
from os import listdir
from os import mkdir
from os.path import isfile
from os.path import isdir
def search(dir):
l = listdir(dir)
b = []
for i in l:
pre = dir + "/" + i
if isfile(pre): b.append(pre)
elif isdir(pre): b += search(pre)
return b
def dategt(a, b):
if a.tm_year > b.tm_year: return a
if a.tm_mon > b.tm_mon: return a
if a.tm_mday > b.tm_mday: return a
# yes, this is intended behaviour
return b
host = "beepboop.systems"
header = "git project listing for {}".format(host)
port = 70
chartusers = ["randomuser"]
directory = "/var/gopher/raw"
destination = "/var/gopher/git"
repos = []
chartdata = {}
for i in chartusers:
chartdata[i] = []
for i in listdir(directory):
gitlocation = directory + "/" + i
gophermap = destination + "/" + i
files = listdir(gitlocation)
try:
with open(gitlocation + "/.git/description", "r") as fd:
lines = [i.rstrip() for i in fd.readlines()]
description = lines[0]
group = lines[1]
except:
description = "default description"
group = "default"
readme = ""
for j in listdir(directory + "/" + i):
if j[0:6].lower() == "readme": readme = j
if readme == "": readme = None
if readme: readme = "{}/{}/{}".format(directory, i, readme)
name = i
print(i)
try: r = git.Repo(gitlocation)
except git.exc.InvalidGitRepositoryError:
print("no git repo here")
continue
r.git.pull()
branch = ""
for j in r.heads:
if "main" == j.name:
branch = "main"
elif "master" == j.name:
branch = "master"
if branch == "": branch = r.heads[0].name
try:
mkdir(gophermap)
except:
pass
fd = open(gophermap + "/gophermap", "w")
fd.write("1back to git root\t/git\t{}\t{}\n".format(host, str(port)))
fd.write("1back to system root\t/\t{}\t{}\n\n".format(host, str(port)))
fd.write(name + " - " + description + "\n\n")
fd.write("files\n~~~~~\n")
for j in files:
fd.write(" - " + j + "\n")
fd.write("\nrecent commits\n~~~~~~~~~~~~~~\n")
for j in r.iter_commits(branch, max_count=10):
fd.write(' '.join([j.author.name, j.hexsha[0:6], j.message.split('\n')[0]]) + "\n")
for j in r.iter_commits(branch):
if j.author.name in chartusers: chartdata[j.author.name].append(time.gmtime(j.committed_date))
if readme:
fd.write("\n0readme\t/git/{}/readme.txt\t{}\t{}\n".format(i, host, str(port)))
with open(readme, "r") as a:
with open(gophermap + "/readme.txt", "w") as b:
for i in a.readlines():
b.write(i)
fd.write("\n0generated by gophergit at {}\t/git/source.py\t{}\t{}".format(time.time(), host, str(port)))
fd.close()
f = search(gitlocation)
for i in range(len(f)):
f[i] = f[i].replace("/var/gopher", "gopher://{}/9".format(host))
fd = open(gophermap + "/files", "w")
for i in f:
fd.write(i + "\n")
fd.close()
repos.append([name, description, group])
repos.sort()
final = {}
for i in repos:
try: final[i[2]].append([i[0], i[1]])
except: final[i[2]] = [[i[0], i[1]]]
fd = open(destination + "/gophermap", "w")
fd.write("{}\n".format(header))
fd.write("1back to the root\t/\t{}\t{}\n\n".format(host, str(port)))
for i in final:
fd.write("{}\n".format(i.upper()))
for j in final[i]:
fd.write("1 {} - {}\t/git/{}/\t{}\t{}\n".format(j[0], j[1], j[0], host, str(port)))
fd.write("\n")
fd.write("\n0generated by gophergit at {}\t/git/source.py\t{}\t{}".format(time.time(), host, str(port)))

View File

@ -4,3 +4,6 @@ printf "warning: if you can, use the makefile instead\n"
cp -f phman/phman.py /usr/bin/phman
chmod +x /usr/bin/phman
cp -f gitman/gitman.py $(PREFIX)$(DESTDIR)/phman
chmod +x $(PREFIX)$(DESTDIR)/gitman