Skip to content

Instantly share code, notes, and snippets.

@joestump
Created August 29, 2009 22:31
Show Gist options
  • Save joestump/177706 to your computer and use it in GitHub Desktop.
Save joestump/177706 to your computer and use it in GitHub Desktop.
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import AppCache
from django.conf import settings
import simpledb
class Command(BaseCommand):
help = ("Sync all of the SimpleDB domains.")
def handle(self, *args, **options):
apps = AppCache()
check = []
for module in apps.get_apps():
for d in module.__dict__:
ref = getattr(module, d)
if isinstance(ref, simpledb.models.ModelMetaclass):
domain = ref.Meta.domain.name
if domain not in check:
check.append(domain)
sdb = simpledb.SimpleDB(settings.AWS_KEY, settings.AWS_SECRET)
domains = [d.name for d in list(sdb)]
for c in check:
if c not in domains:
sdb.create_domain(c)
print "Creating domain %s ..." % c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment