import importlib.util import os from global_rules import global_rules key = -1 name = "Test" version = "0.0.2_beta" version_code = 3 def get_subscription(): apps_folder = "apps" apps = get_global_vars_from_apps(apps_folder) apps_arr = [] for app_name in apps: apps_arr.append(apps[app_name][app_name]) return { "key": key, "name": name, "version": version, "versionCode": version_code, "global": global_rules, "apps": apps_arr, } 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))