mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
12510 review changes
This commit is contained in:
parent
53b3875e82
commit
b45fc0e851
@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.choices import ManagedFileRootPathChoices
|
||||
from core.models import ManagedFile
|
||||
from extras.utils import is_script_or_report
|
||||
from extras.utils import is_script
|
||||
from netbox.models.features import JobsMixin, EventRulesMixin
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from .mixins import PythonModuleMixin
|
||||
@ -72,7 +72,7 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
|
||||
for cls in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
for name, cls in inspect.getmembers(module, is_script_or_report):
|
||||
for name, cls in inspect.getmembers(module, is_script):
|
||||
if cls not in ordered:
|
||||
scripts[_get_name(cls)] = cls
|
||||
|
||||
|
@ -257,7 +257,7 @@ class IPNetworkVar(ScriptVariable):
|
||||
# Scripts
|
||||
#
|
||||
|
||||
class BaseScript(object):
|
||||
class BaseScript:
|
||||
"""
|
||||
Base model for custom scripts. User classes should inherit from this model if they want to extend Script
|
||||
functionality for use in other subclasses.
|
||||
@ -510,15 +510,12 @@ class BaseScript(object):
|
||||
|
||||
return data
|
||||
|
||||
def run_test_scripts(self, job):
|
||||
def run_tests(self, job):
|
||||
"""
|
||||
Run the report and save its results. Each test method will be executed in order.
|
||||
"""
|
||||
self.logger.info(f"Running report")
|
||||
|
||||
# Perform any post-run tasks
|
||||
self.pre_run()
|
||||
|
||||
try:
|
||||
for method_name in self.test_methods:
|
||||
self._current_method = method_name
|
||||
@ -529,12 +526,12 @@ class BaseScript(object):
|
||||
self._current_method = 'unassigned'
|
||||
raise e
|
||||
|
||||
# Perform any post-run tasks
|
||||
self.post_run()
|
||||
self._current_method = 'unassigned'
|
||||
|
||||
def run(self, data, commit):
|
||||
self.run_test_scripts()
|
||||
self.pre_run()
|
||||
self.run_tests()
|
||||
self.post_run()
|
||||
|
||||
def pre_run(self):
|
||||
"""
|
||||
|
@ -51,28 +51,8 @@ def is_script(obj):
|
||||
"""
|
||||
Returns True if the object is a Script.
|
||||
"""
|
||||
from .scripts import Script
|
||||
try:
|
||||
return issubclass(obj, Script) and obj != Script
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def is_report(obj):
|
||||
"""
|
||||
Returns True if the given object is a Report.
|
||||
"""
|
||||
from .reports import Report
|
||||
try:
|
||||
return issubclass(obj, Report) and obj != Report
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def is_script_or_report(obj):
|
||||
"""
|
||||
Returns True if the given object is a Report.
|
||||
"""
|
||||
# TODO: Deprecated legacy reports support
|
||||
from .reports import Report
|
||||
from .scripts import Script
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user