Commits

bren...@yougov.com  committed bc2b62e

recreating missing files from a forgotten addremove

  • Participants
  • Parent commits 184735e

Comments (0)

Files changed (4)

File silk/extras.py

-import os
-import boto
-from boto.s3.key import Key
-
-def push_s3(azn_key, azn_secret, s3bucket, localdir, s3dir):
-    """Recurses through localdir, uploading each file it finds into the corresponding
-    path in s3dir"""
-    conn = boto.connect_s3(azn_key, azn_secret)
-    bucket = conn.get_bucket(s3bucket)
-    tree = os.walk(localdir)
-    for folder in tree:
-        folderpath = folder[0]
-        subfiles = folder[2]
-        for file in subfiles:
-            localfile = os.path.join(folderpath, file)
-            trimmed_dir = folderpath[len(localdir):]
-            #os.path.normpath cleans out any double slashes //
-            #warning: if run from windows the slashes will get turned into backslashes
-            s3file = os.path.normpath("/".join((s3dir, trimmed_dir, file)))
-            print "pushing %s to %s" % (localfile, s3file)
-            k = Key(bucket)
-            k.key = s3file
-            k.set_contents_from_filename(localfile)
-            k.set_acl('public-read')

File silk/extras/__init__.py

Empty file added.

File silk/extras/django.py

+from silk.fabfile import push as real_push
+from silk.utils import run_til_you_die as _run_til_you_die
+from signal import SIGINT
+import silk
+import os
+#SIGH
+
+#time to rewrite code that I wrote last night but is trapped on my laptop because I didn't do an hg addremove
+#SIGH
+#I think the only new file was django.py.
+#which includes collectstatic, and an overwritten push
+
+def _get_proj_dir(root):
+    """Ugly magic function to loop through subdirectories and return the first
+    one that looks like a Django project (has a settings.py)"""
+    #get list of current folder contents
+    paths = [os.path.join(root, folder) for folder in os.listdir(root) if os.path.isdir(os.path.join(os.path.join(root, folder)))]
+    for path in paths:
+        if os.path.isfile(os.path.join(path, 'settings.py')):
+            return path
+
+def collectstatic():
+    """Runs ./manage.py collectstatic, setting current Silk role 
+    as env var so it can be picked up in local_settings"""
+    args = ['./manage.py', 'collectstatic', '--settings=local_settings']
+    proj_dir = _get_proj_dir(silk.lib.get_site_root(os.getcwd()))
+    env_vars = {'SILK_ROLE': silk.lib.get_role()}
+    _run_til_you_die(args, SIGINT, proj_dir, env=env_vars)
+
+def push():
+    collectstatic()
+    real_push()

File silk/extras/s3.py

+import os
+import boto
+from boto.s3.key import Key
+
+def push_s3(azn_key, azn_secret, s3bucket, localdir, s3dir):
+    """Recurses through localdir, uploading each file it finds into the corresponding
+    path in s3dir"""
+    conn = boto.connect_s3(azn_key, azn_secret)
+    bucket = conn.get_bucket(s3bucket)
+    tree = os.walk(localdir)
+    for folder in tree:
+        folderpath = folder[0]
+        subfiles = folder[2]
+        for file in subfiles:
+            localfile = os.path.join(folderpath, file)
+            trimmed_dir = folderpath[len(localdir):]
+            #os.path.normpath cleans out any double slashes //
+            #warning: if run from windows the slashes will get turned into backslashes
+            s3file = os.path.normpath("/".join((s3dir, trimmed_dir, file)))
+            print "pushing %s to %s" % (localfile, s3file)
+            k = Key(bucket)
+            k.key = s3file
+            k.set_contents_from_filename(localfile)
+            k.set_acl('public-read')