be104da4b1d563ceb8fdeab81e3bde3f0e94a47c
[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 ### Database schema
20 model.metadata.create_all()
21
22 ### Sample data
23 # Users
24 from floof.model.users import IdentityURL, User
25 if not User.query.filter_by(name=u'eevee').count:
26 identity_url = IdentityURL(url=u'http://eevee.livejournal.com/')
27 user = User(name=u'eevee')
28 user.identity_urls.append(identity_url)
29
30 ### Make the canonical user-page
31 from floof.model import UserPage
32 UserPage.make_primary_template()
33
34 model.Session.commit()
35
36 ### Filesystem stuff
37 # Only necessary if we're using the filesystem for storage.
38 # And we are!
39 art_path = os.path.join(config['app_conf']['static_root'], 'art')
40 # Test that we can write to the art directory
41 if os.access(art_path, os.W_OK | os.X_OK):
42 # Create directories for various image sizes
43 for subdir in ['original', 'medium', 'thumbnail']:
44 path = os.path.join(art_path, subdir)
45 # If it exists, it should be writeable. If not, create it.
46 if os.path.exists(path):
47 if not os.access(path, os.W_OK | os.X_OK):
48 print "*** WARNING: Can't write to the art/{0} " \
49 "directory!".format(subdir)
50 continue
51 os.makedirs(path)
52 else:
53 print "*** WARNING: Can't write to the art directory!"