Test suite runs and passes!
[zzz-floof.git] / floof / websetup.py
index b1611c9..8f3d896 100644 (file)
@@ -10,23 +10,43 @@ from pylons import config
 from elixir import *
 from floof import model as model
 
 from elixir import *
 from floof import model as model
 
+import os
+
 def setup_app(command, conf, vars):
     """Place any commands to setup floof here"""
     load_environment(conf.global_conf, conf.local_conf)
 def setup_app(command, conf, vars):
     """Place any commands to setup floof here"""
     load_environment(conf.global_conf, conf.local_conf)
-    model.metadata.create_all()
 
 
-    # Initialisation here ... this sort of stuff:
+    # We try to recreate the db when it already exists, like, a lot.  This
+    # fucks everything.  Do a dumb check for it.
+    assert not model.User.table.exists(), \
+           "Database is already initialized; please purge it first."
+
+    ### Database schema
+    model.metadata.create_all()
 
 
+    ### Sample data
     # Users
     # Users
-    from floof.model.users import IdentityURL, User
-    identity_url = IdentityURL(url=u'http://eevee.livejournal.com/')
-    user = User(name=u'Eevee')
+    identity_url = model.IdentityURL(url=u'http://eevee.livejournal.com/')
+    user = model.User(name=u'eevee', display_name=u'Eevee')
     user.identity_urls.append(identity_url)
 
     user.identity_urls.append(identity_url)
 
-
-    # some_entity = model.Session.query(model.<modelfile>.<Some_Entity>).get(1)
-    # e.g. foo = model.Session.query(model.identity.User).get(1)
-    # from datetime import datetime
-    # some_entity.poked_on = datetime.now()
-    # model.Session.add(some_entity)
     model.Session.commit()
     model.Session.commit()
+
+    ### Filesystem stuff
+    # Only necessary if we're using the filesystem for storage.
+    # And we are!
+    art_path = os.path.join(config['app_conf']['static_root'], 'art')
+    # Test that we can write to the art directory
+    if os.access(art_path, os.W_OK | os.X_OK):
+        # Create directories for various image sizes
+        for subdir in ['original', 'medium', 'thumbnail']:
+            path = os.path.join(art_path, subdir)
+            # If it exists, it should be writeable.  If not, create it.
+            if os.path.exists(path):
+                if not os.access(path, os.W_OK | os.X_OK):
+                    print "*** WARNING: Can't write to the art/{0} " \
+                          "directory!".format(subdir)
+                continue
+            os.makedirs(path)
+    else:
+        print "*** WARNING: Can't write to the art directory!"