2024-07-18 10:08:24 +00:00
|
|
|
import importlib.util
|
|
|
|
import os
|
2024-07-19 03:20:30 +00:00
|
|
|
from global_rules import global_rules
|
2024-07-18 10:08:24 +00:00
|
|
|
|
2024-07-19 03:20:30 +00:00
|
|
|
key = -1
|
|
|
|
name = "Test Subscription"
|
|
|
|
version = "0.0.1_beta"
|
2024-07-18 10:08:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_subscription():
|
|
|
|
apps_folder = "apps"
|
|
|
|
apps = get_global_vars_from_apps(apps_folder)
|
|
|
|
return {
|
2024-07-19 03:20:30 +00:00
|
|
|
"key": key,
|
|
|
|
"name": name,
|
2024-07-18 10:08:24 +00:00
|
|
|
"version": version,
|
|
|
|
"apps": apps,
|
2024-07-19 03:20:30 +00:00
|
|
|
"global": global_rules,
|
2024-07-18 10:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def get_global_vars_from_apps(apps_folder):
|
|
|
|
global_vars = {}
|
|
|
|
|
|
|
|
for filename in os.listdir(apps_folder):
|
|
|
|
if filename.endswith(".py"):
|
|
|
|
module_name = filename[:-3]
|
|
|
|
file_path = os.path.join(apps_folder, filename)
|
|
|
|
|
|
|
|
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
|
|
|
module = importlib.util.module_from_spec(spec)
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
|
|
|
|
module_globals = {
|
|
|
|
key: value
|
|
|
|
for key, value in vars(module).items()
|
|
|
|
if not key.startswith("__")
|
|
|
|
}
|
|
|
|
print(
|
|
|
|
"Scanned packageName: %s" % module_globals[module_name]["packageName"]
|
|
|
|
)
|
|
|
|
global_vars[module_name] = module_globals
|
|
|
|
|
|
|
|
return global_vars
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
apps_folder = "apps"
|
|
|
|
apps = get_global_vars_from_apps(apps_folder)
|
|
|
|
print(apps)
|
|
|
|
for app, info in apps:
|
|
|
|
print("%s: %s" % (app, info))
|