change PyappApplication to PyApplication

This commit is contained in:
2025-09-02 16:29:28 +08:00
parent d70eaf383b
commit 7e520e685a
3 changed files with 10 additions and 10 deletions

View File

@@ -1,11 +1,11 @@
from pyapp.utils.log import Log
application_class = {}
def PyappApplication(arg=None):
def PyApplication(arg=None):
if callable(arg):
cls = arg
if "default" in application_class:
Log.error("Multiple classes annotated with default @PyappApplication, require a 'name' parameter.", True)
Log.error("Multiple classes annotated with default @PyApplication, require a 'name' parameter.", True)
application_class["default"] = cls
return cls
@@ -13,9 +13,9 @@ def PyappApplication(arg=None):
name = arg
def decorator(cls):
if name is None:
raise Log.error("The 'name' parameter is required when using @PyappApplication with arguments.", True)
raise Log.error("The 'name' parameter is required when using @PyApplication with arguments.", True)
if name in application_class:
raise Log.error(f"Multiple classes annotated with @PyappApplication with the same name '{name}' found.", True)
raise Log.error(f"Multiple classes annotated with @PyApplication with the same name '{name}' found.", True)
application_class[name] = cls
return cls
return decorator

View File

@@ -17,19 +17,19 @@ def run():
app_name = "default"
if len(application_class) == 0:
Log.error("No class annotated with @PyappApplication found.", True)
Log.error("No class annotated with @PyApplication found.", True)
if len(sys.argv) < 3 and "default" not in application_class:
Log.error("No default @PyappApplication found. Please specify the 'name' parameter.", True)
Log.error("No default @PyApplication found. Please specify the 'name' parameter.", True)
if len(sys.argv) == 3:
app_name = sys.argv[2]
app_cls = application_class.get(app_name)
if app_cls is None:
Log.error(f"No class annotated with @PyappApplication found with the name '{app_name}'.", True)
Log.error(f"No class annotated with @PyApplication found with the name '{app_name}'.", True)
if not hasattr(app_cls, "start"):
Log.error("The class annotated with @PyappApplication should have a 'start' method.", True)
Log.error("The class annotated with @PyApplication should have a 'start' method.", True)
Log.info(f"Application '{app_cls.__name__}' started.")
timer = Timer(f"Application({app_name})")

View File

@@ -66,7 +66,7 @@ def run_application():
if app_cls is None:
Log.error(
f"No class annotated with @PyappApplication found with the name '{app_name}'.",
f"No class annotated with @PyApplication found with the name '{app_name}'.",
True,
)
return jsonify(
@@ -78,7 +78,7 @@ def run_application():
if not hasattr(app_cls, "start"):
Log.error(
"The class annotated with @PyappApplication should have a 'start' method.",
"The class annotated with @PyApplication should have a 'start' method.",
True,
)
return jsonify(