{{{
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.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
This seems a bit specialized to me.
You can implement it as follows:
{{{
class ExitCodeCommand(BaseCommand):
def handle(self, *args, **kwargs):
self.exit_code = 0
self.handle_internal(*args, **kwargs) # may set self.exit_code
sys.exit(self.exit_code)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25419#comment:1>
* status: new => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/25419#comment:2>