An unofficial Django utility tool that tracks management scripts execution.
What does it mean "to track script execution"?
Scripts tracker watches manage.py scripts located in your_app/management/commands
directory and just after you pull some new code and apply its migrations - you will get notified about new (or modified) manage.py scripts that should be applied for the project to work properly.
Home page: https://krzysiek555.github.io/django-scripts-tracker
Step 1 - decorate your management script handle() method with @tracked_script
decorator and push it to repository:
class Command(BaseCommand):
help = 'Some sample script help text'
@tracked_script
def handle(self, *args, **options):
# (...)
Step 2 - anyone who pulls your changes and runs migrations, will get a notification message:
$ python manage.py migrate
(...)
Running migrations:
(...)
Checking management scripts:
You have 1 new and 0 modified management scripts to be applied.
New scripts (1):
your_app/management/commands/sample_management_script.py
Some sample script help text
Install the app using
pip
package manager:pip install django-scripts-tracker
Add
django_scripts_tracker
to yourINSTALLED_APPS
setting:# your_app/settings.py INSTALLED_APPS = [ # (...) 'django_scripts_tracker', ]
Run migrations in order to create tracker models:
python manage.py migrate
Configure directories that should be scanned for management scripts:
# your_app/settings.py COMMANDS_DIRS = [ 'your_app/management/commands', 'another_app/management/commands', ]
- Create a new management script under a tracked
(...)/management/commands/
directory (tracked directories are defined inCOMMANDS_DIRS
). - Decorate either
handle()
orhandle_noargs()
Command method with a@tracked_script
decorator. - Make sure that the created script file is not ingored and is within a tracked directory.
Script checking process takes place every time you perform DB migrations, but you can also invoke it manually:
python manage.py check_scripts
Scripts are automatically marked as applied ones just after their execution.
If there are some scripts that have already been applied but the tracker lists them - it is possible to mark them manually as applied ones.
To mark scripts as "applied" ones type in the following command:
python manage.py check_scripts --mark-all-applied
By default script tracker just warns about new management scripts that should be applied (after performing migrations). However you can also enable automatic execution of all unapplied scripts through adding a setting in your settings.py file:
SCRIPTS_TRACKER = {
'auto_run': True,
}
Scripts tracker also provides a @required_preceeding_script decorator for defining script dependencies.
For more information visit home page: