change PyappApplication to PyApplication
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
from pyapp.utils.log import Log
|
from pyapp.utils.log import Log
|
||||||
|
|
||||||
application_class = {}
|
application_class = {}
|
||||||
def PyappApplication(arg=None):
|
def PyApplication(arg=None):
|
||||||
if callable(arg):
|
if callable(arg):
|
||||||
cls = arg
|
cls = arg
|
||||||
if "default" in application_class:
|
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
|
application_class["default"] = cls
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ def PyappApplication(arg=None):
|
|||||||
name = arg
|
name = arg
|
||||||
def decorator(cls):
|
def decorator(cls):
|
||||||
if name is None:
|
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:
|
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
|
application_class[name] = cls
|
||||||
return cls
|
return cls
|
||||||
return decorator
|
return decorator
|
||||||
|
|||||||
@@ -17,19 +17,19 @@ def run():
|
|||||||
|
|
||||||
app_name = "default"
|
app_name = "default"
|
||||||
if len(application_class) == 0:
|
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:
|
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:
|
if len(sys.argv) == 3:
|
||||||
app_name = sys.argv[2]
|
app_name = sys.argv[2]
|
||||||
|
|
||||||
app_cls = application_class.get(app_name)
|
app_cls = application_class.get(app_name)
|
||||||
|
|
||||||
if app_cls is None:
|
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"):
|
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.")
|
Log.info(f"Application '{app_cls.__name__}' started.")
|
||||||
timer = Timer(f"Application({app_name})")
|
timer = Timer(f"Application({app_name})")
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ def run_application():
|
|||||||
|
|
||||||
if app_cls is None:
|
if app_cls is None:
|
||||||
Log.error(
|
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,
|
True,
|
||||||
)
|
)
|
||||||
return jsonify(
|
return jsonify(
|
||||||
@@ -78,7 +78,7 @@ def run_application():
|
|||||||
|
|
||||||
if not hasattr(app_cls, "start"):
|
if not hasattr(app_cls, "start"):
|
||||||
Log.error(
|
Log.error(
|
||||||
"The class annotated with @PyappApplication should have a 'start' method.",
|
"The class annotated with @PyApplication should have a 'start' method.",
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
return jsonify(
|
return jsonify(
|
||||||
|
|||||||
Reference in New Issue
Block a user