Add manage.py collectscripts to copy scripts from plugins to SCRIPTS_ROOT #7732

Closed
opened 2025-12-29 20:27:37 +01:00 by adam · 3 comments
Owner

Originally created by @amyasnikov on GitHub (Mar 7, 2023).

NetBox version

v.3.4.5

Feature type

New functionality

Proposed functionality

Netbox plugin may have its own custom scripts related to the plugin purpose. Usually these scripts are part of the plugin package. Some average plugin git repository may look like this:

plugin_name/
   scripts/    <-- folder with custom scripts
       custom_script_1.py
       custom_script_2.py
   models/
   views/
   ...

At this moment there is no one convenient way for moving these scripts into SCRIPTS_ROOT folder when you deploy netbox.
Plugin developer has to write some annoying instructions in the README.md like "please move the contents of this folder into your SCRIPTS_ROOT directory" or do some arbitrary automation of this process.

I suggest ./manage.py collectscripts command to solve this problem. This command might act exactly like collectstatic acts for static files.
We can define settings variable like SCRIPTFILES_DIRS to define the list of folders to collect custom scripts from.
I think it would be convenient if this variable could accept both filesystem paths and python import paths
Example:

SCRIPTFILES_DIRS = ['plugin1.scripts', 'plugin2.custom_scripts', '/some/filesystem/folder']

After that you can execute ./manage.py collectscripts and get the contents of 3 folders listed inside SCRIPTFILES_DIRS copied into SCRIPTS_ROOT

Use case

  1. Define SCRIPTFILES_DIRS
# configuration.py

SCRIPTFILES_DIRS = ['plugin1.scripts', 'plugin2.custom_scripts', '/some/filesystem/folder']
...
  1. Run ./manage.py collectscripts
  2. Scripts from folders listed in SCRIPTFILES_DIRS are copied into SCRIPTS_ROOT

This command would facilitate complex netbox deployments with several plugins and several custom_scripts source locations.

Database changes

no changes required

External dependencies

no external dependencies required

Originally created by @amyasnikov on GitHub (Mar 7, 2023). ### NetBox version v.3.4.5 ### Feature type New functionality ### Proposed functionality Netbox plugin may have its own custom scripts related to the plugin purpose. Usually these scripts are part of the plugin package. Some average plugin git repository may look like this: ``` plugin_name/ scripts/ <-- folder with custom scripts custom_script_1.py custom_script_2.py models/ views/ ... ``` At this moment there is no one convenient way for moving these scripts into SCRIPTS_ROOT folder when you deploy netbox. Plugin developer has to write some annoying instructions in the README.md like "please move the contents of this folder into your SCRIPTS_ROOT directory" or do some arbitrary automation of this process. I suggest `./manage.py collectscripts` command to solve this problem. This command might act exactly like **collectstatic** acts for static files. We can define settings variable like SCRIPTFILES_DIRS to define the list of folders to collect custom scripts from. I think it would be convenient if this variable could accept both filesystem paths and python import paths Example: ``` SCRIPTFILES_DIRS = ['plugin1.scripts', 'plugin2.custom_scripts', '/some/filesystem/folder'] ``` After that you can execute `./manage.py collectscripts` and get the contents of 3 folders listed inside SCRIPTFILES_DIRS copied into SCRIPTS_ROOT ### Use case 1. Define SCRIPTFILES_DIRS ``` # configuration.py SCRIPTFILES_DIRS = ['plugin1.scripts', 'plugin2.custom_scripts', '/some/filesystem/folder'] ... ``` 2. Run `./manage.py collectscripts` 3. Scripts from folders listed in SCRIPTFILES_DIRS are copied into SCRIPTS_ROOT This command would facilitate complex netbox deployments with several plugins and several custom_scripts source locations. ### Database changes no changes required ### External dependencies no external dependencies required
adam added the type: feature label 2025-12-29 20:27:37 +01:00
adam closed this issue 2025-12-29 20:27:37 +01:00
Author
Owner

@amyasnikov commented on GitHub (Mar 13, 2023):

Moreover, the same command for reports may be implemented (./manage.py collectreports)
I can do it by myself if you agree with this feature

@amyasnikov commented on GitHub (Mar 13, 2023): Moreover, the same command for reports may be implemented (`./manage.py collectreports`) I can do it by myself if you agree with this feature
Author
Owner

@jeremystretch commented on GitHub (Mar 16, 2023):

The SCRIPTS_ROOT and REPORTS_ROOT paths exist to identify and load user-provided reports and scripts. If these are being provided by a plugin, they already exist within the Python environment: There should be no need to duplicate the files.

It sounds like what you're ultimately after is a mechanism for plugins to register reports and custom scripts. This was proposed back in #4573 but it never found traction, nor was any specific implementation proposed. It would be worth revisiting the topic if you'd like to propose one. (If so, please open a new FR.)

@jeremystretch commented on GitHub (Mar 16, 2023): The `SCRIPTS_ROOT` and `REPORTS_ROOT` paths exist to identify and load user-provided reports and scripts. If these are being provided by a plugin, they already exist within the Python environment: There should be no need to duplicate the files. It sounds like what you're ultimately after is a mechanism for plugins to register reports and custom scripts. This was proposed back in #4573 but it never found traction, nor was any specific implementation proposed. It would be worth revisiting the topic if you'd like to propose one. (If so, please open a new FR.)
Author
Owner

@amyasnikov commented on GitHub (Mar 21, 2023):

@jeremystretch this is exactly the thing I'm proposing: a very simple mechanism for a plugin to register reports and custom scripts. The same feature is mentioned in #4573, but there is no any implementation details in this issue.

I suggest the same mechanism as the already existing one for static files. Each django application (either local or installed from pip) may have its own staticfiles, and you have a manage.py command to collect the files from all apps into one folder.

The current custom scripts loading mechanism implies the presence of all scripts in one separate folder (SCRIPTS_ROOT), exactly as serving static files mechanism does. So, we can implement the same procedure of collecting scripts into one folder as it is implemented for static files by django.

@amyasnikov commented on GitHub (Mar 21, 2023): @jeremystretch this is exactly the thing I'm proposing: a very simple mechanism for a plugin to register reports and custom scripts. The same feature is mentioned in #4573, but there is no any implementation details in this issue. I suggest the same mechanism as the already existing one for static files. Each django application (either local or installed from pip) may have its own staticfiles, and you have a manage.py command to collect the files from all apps into one folder. The current custom scripts loading mechanism implies the presence of all scripts in one separate folder (SCRIPTS_ROOT), exactly as serving static files mechanism does. So, we can implement the same procedure of collecting scripts into one folder as it is implemented for static files by django.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7732