Commits

Steve Losh  committed 710da3d

Initial commit.

  • Participants

Comments (0)

Files changed (2)

+syntax: glob
+
+.DS_Store
+*.pyc
+#!/usr/bin/env python
+from __future__ import with_statement
+
+import os, sys
+if len(sys.argv) == 2:
+    os.chdir(sys.argv[1])
+
+from django.core.management import setup_environ
+import settings as app_settings
+setup_environ(app_settings)
+
+import json
+from django.conf import settings
+from django.core.management.commands.dumpdata import Command as DumpDataCommand
+
+
+if os.path.isfile(settings.BACKUP_DIRECTORY):
+    sys.stderr.write('Backup directory is currently a file!\n')
+    sys.exit(1)
+
+if not os.path.exists(settings.BACKUP_DIRECTORY):
+    os.mkdir(settings.BACKUP_DIRECTORY)
+
+dc = DumpDataCommand()
+data = json.loads(dc.handle(**{'exclude': settings.EXCLUDE_LIST}))
+
+sorting_key = lambda m: (m['model'], m['pk'])
+data.sort(key=sorting_key)
+
+try:
+    backup_filename = settings.BACKUP_FILENAME
+except AttributeError:
+    backup_filename = 'backup.json'
+
+backup_path = os.path.join(BACKUP_DIRECTORY, backup_filename)
+
+with open(backup_path, 'w') as backup_file:
+    output = json.dumps(data, sort_keys=True, indent=4)
+    backup_file.write(output)