From 590565bdf0d64fde2b56eb94500f8d9766047458 Mon Sep 17 00:00:00 2001 From: pycook Date: Mon, 21 Aug 2023 20:08:23 +0800 Subject: [PATCH] Register api and commands with absolute paths --- cmdb-api/api/app.py | 3 +-- cmdb-api/api/resource.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmdb-api/api/app.py b/cmdb-api/api/app.py index 7552a28..e581f7b 100644 --- a/cmdb-api/api/app.py +++ b/cmdb-api/api/app.py @@ -21,7 +21,6 @@ from api.models.acl import User HERE = os.path.abspath(os.path.dirname(__file__)) PROJECT_ROOT = os.path.join(HERE, os.pardir) -API_PACKAGE = "api" @login_manager.user_loader @@ -174,7 +173,7 @@ def register_commands(app): for root, _, files in os.walk(os.path.join(HERE, "commands")): for filename in files: if not filename.startswith("_") and filename.endswith("py"): - module_path = os.path.join(API_PACKAGE, root[root.index("commands"):]) + module_path = os.path.join(HERE, root[root.index("commands"):]) if module_path not in sys.path: sys.path.insert(1, module_path) command = __import__(os.path.splitext(filename)[0]) diff --git a/cmdb-api/api/resource.py b/cmdb-api/api/resource.py index 3bed92b..43f4bd6 100644 --- a/cmdb-api/api/resource.py +++ b/cmdb-api/api/resource.py @@ -27,7 +27,7 @@ class APIView(Resource): return send_file(*args, **kwargs) -API_PACKAGE = "api" +API_PACKAGE = os.path.abspath(os.path.dirname(__file__)) def register_resources(resource_path, rest_api):