a4e935fa34d01e0703b4d1e661e52e9e0acedbc8
[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 identity_url = IdentityURL(url=u'http://eevee.livejournal.com/')
26 user = User(name=u'eevee')
27 user.identity_urls.append(identity_url)
28
29 model.Session.commit()
30
31
32 ### Filesystem stuff
33 # Only necessary if we're using the filesystem for storage.
34 # And we are!
35 art_path = os.path.join(config['app_conf']['static_root'], 'art')
36 # Test that we can write to the art directory
37 if os.access(art_path, os.W_OK | os.X_OK):
38 # Create directories for various image sizes
39 for subdir in ['original', 'medium', 'thumbnail']:
40 path = os.path.join(art_path, subdir)
41 # If it exists, it should be writeable. If not, create it.
42 if os.path.exists(path):
43 if not os.access(path, os.W_OK | os.X_OK):
44 print "*** WARNING: Can't write to the art/{0} " \
45 "directory!".format(subdir)
46 continue
47 os.makedirs(path)
48 else:
49 print "*** WARNING: Can't write to the art directory!"