Test suite runs and passes!
[zzz-floof.git] / floof / websetup.py
1 # -*- coding: utf-8 -*-
2 """Setup the floof application"""
3 import logging
4
5 from floof.config.environment import load_environment
6
7 log = logging.getLogger(__name__)
8
9 from pylons import config
10 from elixir import *
11 from floof import model as model
12
13 import os
14
15 def setup_app(command, conf, vars):
16 """Place any commands to setup floof here"""
17 load_environment(conf.global_conf, conf.local_conf)
18
19 # We try to recreate the db when it already exists, like, a lot. This
20 # fucks everything. Do a dumb check for it.
21 assert not model.User.table.exists(), \
22 "Database is already initialized; please purge it first."
23
24 ### Database schema
25 model.metadata.create_all()
26
27 ### Sample data
28 # Users
29 identity_url = model.IdentityURL(url=u'http://eevee.livejournal.com/')
30 user = model.User(name=u'eevee', display_name=u'Eevee')
31 user.identity_urls.append(identity_url)
32
33 model.Session.commit()
34
35 ### Filesystem stuff
36 # Only necessary if we're using the filesystem for storage.
37 # And we are!
38 art_path = os.path.join(config['app_conf']['static_root'], 'art')
39 # Test that we can write to the art directory
40 if os.access(art_path, os.W_OK | os.X_OK):
41 # Create directories for various image sizes
42 for subdir in ['original', 'medium', 'thumbnail']:
43 path = os.path.join(art_path, subdir)
44 # If it exists, it should be writeable. If not, create it.
45 if os.path.exists(path):
46 if not os.access(path, os.W_OK | os.X_OK):
47 print "*** WARNING: Can't write to the art/{0} " \
48 "directory!".format(subdir)
49 continue
50 os.makedirs(path)
51 else:
52 print "*** WARNING: Can't write to the art directory!"