remove old management tool in favour of didier/management-tools

This commit is contained in:
Didier Slof 2023-04-28 17:28:53 +02:00
parent 515035fcf7
commit e8099b4f17
4 changed files with 0 additions and 141 deletions

3
man
View file

@ -1,3 +0,0 @@
#!/bin/sh
python3 tools/manager/main.py $@

View file

@ -1,3 +0,0 @@
# example neorc file
PREF_SHELL=zsh
USE_DOCK_MAN=yes

View file

@ -1,107 +0,0 @@
import glob
import os
import argparse
from savefile import SaveFile
# Spaghetti code to replace the shell script
PROJECT_NAME = os.environ.get("PROJECT_NAME", "neo")
files = glob.glob("docker-compose.*.yml")
def dc(cmd: str):
fopts = ""
for f in files:
fopts += f"-f {f} "
# print(f"docker-compose {fopts}{cmd}")
os.system(f"docker-compose -p {PROJECT_NAME} {fopts} {cmd}")
def main():
global files
ap = argparse.ArgumentParser()
ap.add_argument("--savefile", help="The savefile to use",
default=os.path.expanduser("~/.local/faulty/neo.save"))
ap.add_argument("--del-savefile", "--rm-save", help="Delete the savefile",
action="store_true")
ap.add_argument("--ignore-savefile", "--no-load", help="Ignore the savefile",
action="store_true")
# -x, --exclude: e.g. -x this -x that
ap.add_argument("-x", "--exclude", help="Exclude a file from the list",
action="append", default=[])
# -i, --include: e.g. -i this -i that
ap.add_argument("-i", "--include", help="Include a file from the list",
action="append", default=[])
ap.add_argument('--save', help="Save the list of files to the savefile", action="store_true")
ap.add_argument('action', help="The action to perform on the files",
nargs="?", default="up")
ap.add_argument('args', help="Extra arguments for the action",
nargs=argparse.REMAINDER)
args = ap.parse_args()
if args.del_savefile:
os.remove(args.savefile)
return
if not args.ignore_savefile:
savefile = SaveFile(args.savefile)
else:
savefile = SaveFile(os.path.expanduser("~/.local/faulty/neo.save"))
# load the savefile
if not args.ignore_savefile:
files = savefile.get("files", files)
if len(args.include) > 0:
files = []
for i in args.include:
files.append(f"docker-compose.{i}.yml")
if len(args.exclude) > 0:
for i in args.exclude:
files.remove(f"docker-compose.{i}.yml")
if args.save:
savefile["files"] = files
def handle_aliases(fnlist: dict, name: str):
return fnlist.get(name, lambda: print("does not exist"))
def dump_data():
print(f"savefile: {args.savefile}")
print(f"del_savefile: {args.del_savefile}")
print(f"ignore_savefile: {args.ignore_savefile}")
print(f"exclude: {args.exclude}")
print(f"include: {args.include}")
print(f"save: {args.save}")
print(f"action: {args.action}")
print(f"args: {args.args}")
print(f"files: {files}")
def update():
os.system("git pull")
os.system("git submodule update --recursive --remote --init")
fnlist = {
"up": lambda: dc(f"up -d {' '.join(args.args)}"),
"upr": lambda: dc(f"up -d --build {' '.join(args.args)}"),
"logs": lambda: dc(f"logs --tail=20 -f {' '.join(args.args)}"),
"default": lambda: dc(f"{' '.join(args.args)}"),
"delete-project-files": lambda: os.system(f"sudo rm -rf /srv/{args.args[0]}"),
"pull": lambda: update(),
"_dump": lambda: dump_data(),
"backup": lambda: os.system(f"tar cvf {args.args[0]} /srv /docker"),
"dpf": lambda: handle_aliases(fnlist, "delete-project-files")()
}
fnlist.get(args.action, lambda: dc(f"{args.action} {' '.join(args.args)}"))()
if __name__ == "__main__":
main()

View file

@ -1,28 +0,0 @@
import json
import os
class SaveFile(dict):
def __init__(self, file: str) -> None:
super().__init__()
self.path: str = file
_dir = os.path.dirname(self.path)
if not os.path.exists(_dir):
os.makedirs(_dir)
if os.path.exists(self.path):
with open(self.path, 'r') as f:
self.update(json.loads(f.read()))
else:
self.save()
def save(self):
with open(self.path, 'w+') as f:
f.write(json.dumps(self))
def __getitem__(self, key):
return super().__getitem__(key)
def __setitem__(self, key, value):
super().__setitem__(key, value)
self.save()