From 3d6a583ce4eca7b52acc4c3cf1a05512f7acadda Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 13 Aug 2019 09:09:12 -0400 Subject: [PATCH] Allow user to override module name --- docs/additional-features/custom-scripts.md | 6 ++++++ netbox/extras/scripts.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/docs/additional-features/custom-scripts.md b/docs/additional-features/custom-scripts.md index 5caeb66a3..41aeb8fb1 100644 --- a/docs/additional-features/custom-scripts.md +++ b/docs/additional-features/custom-scripts.md @@ -37,6 +37,12 @@ Defining variables is optional: You may create a script with only a `run()` meth Returning output from your script is optional. Any raw output generated by the script will be displayed under the "output" tab in the UI. +## Module Attributes + +### `name` + +You can define `name` within a script module (the Python file which contains one or more scripts) to set the module name. If `name` is not defined, the filename will be used. + ## Script Attributes Script attributes are defined under a class named `Meta` within the script. These are optional, but encouraged. diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 794a9edb4..c5bb674f5 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -233,6 +233,8 @@ def get_scripts(): # defined. for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]): module = importer.find_module(module_name).load_module(module_name) + if hasattr(module, 'name'): + module_name = module.name module_scripts = OrderedDict() for name, cls in inspect.getmembers(module, is_script): module_scripts[name] = cls