Skip to content

Instantly share code, notes, and snippets.

@rvause
Created August 23, 2012 16:31
Show Gist options
  • Select an option

  • Save rvause/3438336 to your computer and use it in GitHub Desktop.

Select an option

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
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