From 1b98ad91552444bb107f86400562e29b8a58967d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 6 Jun 2022 19:55:08 -0400 Subject: [PATCH] first commit --- .gitignore | 1 + core/__init__.py | 0 core/komandr.py | 39 +++++++++++++++++++++++++++++++++++++++ libs/bprint.py | 4 ++++ libs/meido.py | 16 ++++++++++++++++ libs/test_lib.py | 4 ++++ main.py | 2 ++ notes.txt | 16 ++++++++++++++++ plugins/dpt.py | 3 +++ plugins/test_plugin.py | 6 ++++++ 10 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 core/__init__.py create mode 100644 core/komandr.py create mode 100644 libs/bprint.py create mode 100644 libs/meido.py create mode 100644 libs/test_lib.py create mode 100644 main.py create mode 100644 notes.txt create mode 100644 plugins/dpt.py create mode 100644 plugins/test_plugin.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/komandr.py b/core/komandr.py new file mode 100644 index 0000000..5ea3ce7 --- /dev/null +++ b/core/komandr.py @@ -0,0 +1,39 @@ +from sys import path as sys_path +from os import listdir +from threading import Thread + +################################################## +# TODO: THIS IS DUMB, FIGURE OUT ANOTHER WAY TO LET US DO IT WITHOUT INFRINGING ON PLUGINSPACE +################################################## +from inspect import stack +from os.path import basename +def bprint(*args): + print(f"[{basename(stack()[1].filename)}/{stack()[1].function}]:", *args) +################################################## + +class komandr(): + def __init__(self): + self.libs_loaded = self.load_modules_to_dict("libs") + self.plugins_loaded = self.load_modules_to_dict("plugins") + + for p in self.plugins_loaded.values(): + depends_correct = True + for d in p.depends: + if d not in self.libs_loaded.keys(): bprint(f"{p.__name__} requires {d} library! plugin will not be started.");depends_correct = False + if not depends_correct: continue + + Thread(target = p.run, args = (self.libs_loaded,)).start() + bprint("started plugin", p.__name__) + def load_modules_to_dict(self, fro): + res = {} + sys_path.append(sys_path[0]+f"/{fro}") + modules = [name.split(".py")[0] for name in listdir(sys_path[-1]) if name.endswith(".py")] + for mod in modules: + try: temp_mod = __import__(mod) + except: continue + # TODO: CHECK FOR VALIDITY ACCORDING TO RULES + res[mod] = temp_mod + bprint(f"loaded module {mod} from {fro}") + return res + def run(self): + pass \ No newline at end of file diff --git a/libs/bprint.py b/libs/bprint.py new file mode 100644 index 0000000..10477c9 --- /dev/null +++ b/libs/bprint.py @@ -0,0 +1,4 @@ +from inspect import stack +from os.path import basename +def p(*args): + print(f"[{basename(stack()[1].filename)}/{stack()[1].function}]:", *args) \ No newline at end of file diff --git a/libs/meido.py b/libs/meido.py new file mode 100644 index 0000000..582e2a6 --- /dev/null +++ b/libs/meido.py @@ -0,0 +1,16 @@ +import requests +import json +class driver(): + def __init__(self, endpoin, image, static): + self.endpoint = endpoin + self.image_endpoint = image + self.static_endpoint = static + def get_boards(self): + return self.wrap_route("/boards.json") + def get_threads(self, board): + return self.wrap_route(f"/{board}/threads.json") + def get_catalog(self, board): + return self.wrap_route(f"/{board}/catalog.json") + def wrap_route(self, route): + return json.loads(requests.get(self.endpoint+route).text) +instance = driver("https://a.4cdn.org", "https://i.4cdn.org", "https://s.4cdn.org") \ No newline at end of file diff --git a/libs/test_lib.py b/libs/test_lib.py new file mode 100644 index 0000000..bddf130 --- /dev/null +++ b/libs/test_lib.py @@ -0,0 +1,4 @@ +from bprint import p +test_var = 123 +def test_func(): + p("test!") \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..68f2b65 --- /dev/null +++ b/main.py @@ -0,0 +1,2 @@ +from core.komandr import komandr +komandr().run() \ No newline at end of file diff --git a/notes.txt b/notes.txt new file mode 100644 index 0000000..b906960 --- /dev/null +++ b/notes.txt @@ -0,0 +1,16 @@ +an automation platform + +>libs: + ex: fortune + ex: notifications +>>plugins + ex: notify when /dpt/ is up + +so: +core; libs; plugins + +SO WHAT DOES THE CORE NEED TO DO????2: + >load libs into dict (?), make it available to plugins + >load plugins & start their processes + >make some variable space available to plugins + diff --git a/plugins/dpt.py b/plugins/dpt.py new file mode 100644 index 0000000..ccf5aa0 --- /dev/null +++ b/plugins/dpt.py @@ -0,0 +1,3 @@ +depends = ["bprint", "meido"] +def run(l): + l["bprint"].p(f"found {len(l['meido'].instance.get_boards())} boards") \ No newline at end of file diff --git a/plugins/test_plugin.py b/plugins/test_plugin.py new file mode 100644 index 0000000..909fcdc --- /dev/null +++ b/plugins/test_plugin.py @@ -0,0 +1,6 @@ +depends = ["bprint", "test_lib"] +def run(l): + if "test_lib" not in l.keys(): print("requires test_lib library!");return + l["bprint"].p(f"printing out the test value woot woot: {l['test_lib'].test_var}") + l["bprint"].p("callign the test function woot woot") + l["test_lib"].test_func() \ No newline at end of file