Anonymous avatar Anonymous committed ed266e7

[project @ 357]
Script for adding photos.

Comments (0)

Files changed (1)

scripts/add_photos.py

+#!/usr/bin/python
+import sys
+import os
+
+sys.path = sys.path + ['/home/luke/httpd/www.cciw.co.uk/django/','/home/luke/httpd/www.cciw.co.uk/django_src/', '/home/luke/httpd/www.cciw.co.uk/misc_src/']
+os.environ['DJANGO_SETTINGS_MODULE'] = 'cciw.settings_calvin'
+#sys.path = sys.path + ['/home2/cciw/webapps/django_app/', '/home2/cciw/src/django-mr/', '/home2/cciw/src/misc/']
+#os.environ['DJANGO_SETTINGS_MODULE'] = 'cciw.settings'
+
+import re
+
+from cciw.cciwmain.models import Photo, Gallery, Camp
+from cciw.cciwmain.views.camps import get_gallery_for_camp
+
+
+
+def usage():
+    return """
+Usage: add_photos.py photo1.jpeg [photo2.jpeg...]
+"""
+
+
+camp_re = re.compile('^(?P<year>\d{4})-(?P<number>\d+)') 
+
+def main():
+    if len(sys.argv) == 1:
+        print usage()
+        sys.exit(1)
+
+    for photoname in sys.argv[1:]:
+        # Parse the photoname
+        m = camp_re.match(photoname)
+        if m is None:
+            raise Exception("Photo %s is not in the form yyyy-n-*" % photoname)
+    
+        try:
+            camp = Camp.objects.get(year=int(m.groupdict()['year']), 
+                                    number=int(m.groupdict()['number']))
+        except Camp.DoesNotExist:
+            raise Exception("Camp %s could not be found" % m.group())
+
+        gallery = get_gallery_for_camp(camp)
+        
+        try:
+            p = Photo.objects.get(gallery=gallery, filename=photoname)
+        except Photo.DoesNotExist:
+            p = None
+        if p is None:
+            p = Photo.create_default_photo(photoname, gallery)
+            print "Created photo %s." % photoname
+        else:
+            print "Warning: Photo %s already exists." % photoname
+    
+if __name__ == '__main__':
+    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.