Created
August 23, 2012 16:31
-
-
Save rvause/3438336 to your computer and use it in GitHub Desktop.
My Swiss army knife (-like) Django manage command // Hopefully I will find a use for it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.core.management.base import BaseCommand | |
| class Command(BaseCommand): | |
| def handle(self, *args, **options): | |
| if len(args) > 0: | |
| for arg in args: | |
| try: | |
| globals()[arg]() | |
| except KeyError: | |
| try: | |
| globals()['run_%s' % arg]() | |
| except KeyError: | |
| print '%s not found' % arg | |
| else: | |
| for key, value in globals().items(): | |
| if key.startswith('run_') \ | |
| and hasattr(globals()[key], '__call__'): | |
| value() | |
| def run_something(): | |
| print 'I get run automatically' | |
| def something_else(): | |
| print 'You have to pass me as an arg to run me' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment