VStorage now looks for <doc> if it couldn't find <doc>.xml
[redakcja.git] / deployment.py
1 #!/srv/library/redakcja/pythonenv/bin/python
2 from __future__ import with_statement
3
4 import shutil
5 import os
6 import sys
7
8 from string import Template
9
10 def render_template(source, dest, context={}):
11     print "Rendering template:",
12     with open(source, 'rb') as source_file:
13         t = Template(source_file.read())
14     with open(dest, 'wb') as dest_file:
15         dest_file.write(t.safe_substitute(context))
16     print "done."
17
18 def restart_wsgi():
19     print "Restarting wsgi application:",
20     os.system("touch %s" % WSGI_TARGET)
21     print "done."
22
23 def update_application():
24     print "Updating repository.",
25     os.system("cd %s; git pull" % PROJECT_ROOT)
26     print "Installing requirements"
27     os.system("pip install -r %s" % os.path.join(PROJECT_ROOT, 'requirements.txt'))
28     print "Installing local requirements"
29     os.system("pip install -r %s" % os.path.join(ROOT, 'etc', 'requirements.txt'))
30     print "done."
31
32
33 PYTHON = os.path.join(ROOT, 'pythonenv', 'bin', 'python')
34 PYTHON_SITE = os.path.join(ROOT, 'pythonenv', 'lib', 'python2.6', 'site-packages')
35
36 PROJECT_NAME = 'redakcja'
37 PROJECT_ROOT = os.path.join(ROOT, 'application')
38
39 MEDIA_ROOT = os.path.join(ROOT, 'www', 'media')
40
41 ADMIN_EMAIL = 'lrekucki@gmail.com'
42
43 WSGI_TARGET = os.path.join(ROOT, 'www', 'wsgi', PROJECT_NAME + '.wsgi')
44 WSGI_DIR = os.path.dirname(WSGI_TARGET)
45
46 WSGI_USER = PROJECT_NAME
47 WSGI_PROCESSES = 5
48 WSGI_THREADS = 1
49
50 DOMAIN = 'redakcja.wolnelektury.pl'
51 DOMAIN_ALIASES = 'redakcja.nowoczesnapolska.org.pl'
52
53 #
54 # Load local configuration
55 #
56 sys.path = [ os.path.join(ROOT, 'etc') ] + sys.path
57
58 from local_deployment import *
59
60 if __name__ == '__main__':
61     update_application()
62     render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.wsgi.template'), WSGI_TARGET, context=globals())
63     render_template(os.path.join(PROJECT_ROOT, PROJECT_NAME + '.vhost.template'), os.path.join(ROOT, 'etc', PROJECT_NAME + '.vhost'), context=globals())
64     restart_wsgi()