diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7bf676c --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +test: + python3 main.py +pip: + sudo pip3 install -r requirements.txt +deploy: pip + cp sample.service new.service + # yes, this exists because I'm too lazy to escape regex + inline 'sed' + python3 sed.py + sudo mv new.service /etc/systemd/system/webforge.service + sudo systemctl daemon-reload + sudo systemctl enable --now webforge.service +undeploy: + sudo systemctl stop webforge.service + sudo systemctl disable webforge.service + sudo rm /etc/systemd/system/webforge.service + sudo systemctl daemon-reload +update: + make undeploy + git pull + make deploy diff --git a/main.py b/main.py index 11a8ea7..19d0c89 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ # Stdlib -import os,yaml +import os, yaml # Pip import flask_login -from flask import Flask,render_template,request,redirect,make_response +from flask import Flask, render_template, request, redirect, make_response +from flask_login import login_required # In-house from utils import run_command_shell @@ -23,6 +24,7 @@ mlc = mlcmgr() class User(flask_login.UserMixin): pass + @login_manager.user_loader def user_loader(uid): if not db.check_user_exists(uid): @@ -81,14 +83,56 @@ def logout(): flask_login.logout_user() return redirect("/") + @app.route("/") def main(): if not flask_login.current_user.is_authenticated: pc = "Login" else: - pc = f"
Hi, {flask_login.current_user.id}
" + render_template("logout.html") + pc = f"Hi, {flask_login.current_user.id}
" + render_template( + "logout.html" + ) + "{mlc.dump_pkgbuild(name, repo)}
",
+ )
+
+
if __name__ == "__main__":
- app.run(host="127.0.0.1", port=6969, debug=True)
\ No newline at end of file
+ app.run(host="127.0.0.1", port=6969, debug=True)
diff --git a/mlcmanager.py b/mlcmanager.py
index e3904e7..e0ab0ee 100644
--- a/mlcmanager.py
+++ b/mlcmanager.py
@@ -1,4 +1,4 @@
-import os,yaml,contextlib
+import os, yaml, contextlib
import subprocess
@@ -21,7 +21,7 @@ class mlcmgr:
subdirs = []
has_subdirs = input("Does your repo have subdirs? (Y/n): ")
if has_subdirs != "n":
- newd = 'foo'
+ newd = "foo"
while newd != "done":
newd = input("Subdir (or 'done'): ")
if newd == "done":
@@ -36,7 +36,7 @@ class mlcmgr:
"src": src,
"dst": dst,
"has_subdirs": has_subdirs,
- "subdirs": subdirs
+ "subdirs": subdirs,
}
with open("config.yml", "w") as f:
f.write(yaml.dump(settings))
@@ -47,52 +47,116 @@ class mlcmgr:
def init_workspace(self):
if not os.path.exists(self.config["dst"]):
os.system(f"git clone {self.config['src']} {self.config['dst']}")
- if not self.config['has_subdirs']:
+ if not self.config["has_subdirs"]:
os.system(f"cd {self.config['dst']} && mlc init")
else:
- for subdir in self.config['subdirs']:
- os.system(f"cd {self.config['dst']} && cd {subdir} && mlc init && cd ../")
+ for subdir in self.config["subdirs"]:
+ os.system(
+ f"cd {self.config['dst']} && cd {subdir} && mlc init && cd ../"
+ )
def pull_all(self):
- if self.config['has_subdirs']:
- for subdir in self.config['subdirs']:
- os.system(f"cd {self.config['dst']} && cd {subdir} && mlc pull && cd ../")
+ if self.config["has_subdirs"]:
+ for subdir in self.config["subdirs"]:
+ os.system(
+ f"cd {self.config['dst']} && cd {subdir} && mlc pull && cd ../"
+ )
else:
os.system(f"cd {self.config['dst']} && mlc pull && cd ../")
return "Done"
def get_info(self, subdir=None):
- extra = self.config['dst']
+ extra = self.config["dst"]
if subdir is not None:
extra += "/" + subdir
with pushd(extra):
- out = subprocess.check_output(["mlc","info"]).decode('utf-8')
+ out = subprocess.check_output(["mlc", "info"]).decode("utf-8")
return out
def list_packages(self, subdir=None):
- extra = self.config['dst']
+ extra = self.config["dst"]
if subdir is not None:
extra += "/" + subdir
- return os.listdir(extra)
+ all_files = os.listdir(extra)
+ bad = ["mlc.toml", "README.md"]
+ for thing in bad:
+ if thing in all_files:
+ all_files.remove(thing)
+ return all_files
def build(self, package, subdir=None):
- p = self.config['dst']
+ p = self.config["dst"]
if subdir is not None:
p += "/" + subdir
with pushd(p):
os.system(f"mlc build {package}")
def gen_repo(self, subdir=None):
- p = self.config['dst']
+ p = self.config["dst"]
if subdir is not None:
p += "/" + subdir
with pushd(p):
os.system("mlc repo-gen")
+ def html_list_packages(self, subdir=None):
+ raw = self.list_packages(subdir)
+ html = "- {pkg}
{info['pkgname']}
Version: {info['pkgver']}
Rel: {info['pkgrel']}
Desc: {info['pkgdesc']}
URL: {s_url}
" + html += f"You can view the whole pkgbuild here
" + return html + + def list_repos(self): + if not self.config['has_subdirs']: + return [] + else: + return self.config['subdirs'] + + def html_repo_list(self): + repos = self.list_repos() + html = "