53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import importlib.util
|
|
import os
|
|
from global_rules import global_rules
|
|
|
|
key = -1
|
|
name = "Test Subscription"
|
|
version = "0.0.1_beta"
|
|
|
|
|
|
def get_subscription():
|
|
apps_folder = "apps"
|
|
apps = get_global_vars_from_apps(apps_folder)
|
|
return {
|
|
"key": key,
|
|
"name": name,
|
|
"version": version,
|
|
"apps": apps,
|
|
"global": global_rules,
|
|
}
|
|
|
|
|
|
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))
|