#25419: Management commands: allow to set exit code, without calling sys.exit
--------------------------------------------+--------------------
Reporter: blueyed | Owner: nobody
Type: New feature | Status: new
Component: Core (Management commands) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+--------------------
With a Command like the following, it would be nice to be able to specify
the exit code in case of errors:
{{{
class Command(LabelCommand):
def handle_label(self, username, **options):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
self.stderr.write("{}: user not found,
skipping.".format(username))
self.exitcode = 5
return
result = do_something()
self.stdout.write("{}: {}".format(username, result))
}}}
While you could call `sys.exit(5)` directly in this case, the use case
would be to handle all existing users from the labels, but exit non-zero
in case of any errors.
I could imagine having `exitcode = 0` on the `BaseCommand` class and then
use this in the end with `sys.exit()`.
--
Ticket URL: <https://code.djangoproject.com/ticket/25419>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.6e7bfb262dec42c5464e85218d4c8d8f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.