mirror of https://github.com/kurisufriend/komandr
commit
1b98ad9155
@ -0,0 +1 @@ |
|||||||
|
__pycache__ |
@ -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 |
@ -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) |
@ -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") |
@ -0,0 +1,4 @@ |
|||||||
|
from bprint import p |
||||||
|
test_var = 123 |
||||||
|
def test_func(): |
||||||
|
p("test!") |
@ -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 |
||||||
|
|
@ -0,0 +1,3 @@ |
|||||||
|
depends = ["bprint", "meido"] |
||||||
|
def run(l): |
||||||
|
l["bprint"].p(f"found {len(l['meido'].instance.get_boards())} boards") |
@ -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() |
Loading…
Reference in new issue