forked from hhj/subscript_template
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
|
import importlib.util
|
||
|
import os
|
||
|
|
||
|
|
||
|
version = "0.0.1_alpha"
|
||
|
|
||
|
|
||
|
def get_subscription():
|
||
|
apps_folder = "apps"
|
||
|
apps = get_global_vars_from_apps(apps_folder)
|
||
|
return {
|
||
|
"version": version,
|
||
|
"apps": apps,
|
||
|
}
|
||
|
|
||
|
|
||
|
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))
|