-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
230 lines (201 loc) · 7.95 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.api import local, settings, hide, task, abort, sudo, lcd
from fabric.colors import red, green, yellow
from fabric.utils import indent
from jbcore.object import JBObject, JBError
from jbcore.sql import JBDB
jaskinia_path = '/home/jaskinia'
realms_path = '%s/realms' % jaskinia_path
lib_path = '%s/lib' % jaskinia_path
locale_path = '%s/locale/%s/LC_MESSAGES/%s.mo' % (jaskinia_path, '%s', '%s')
config_path = '%s/config' % jaskinia_path
realms_conf_path = '%s/jbcore/include/conf.realms.ini' % lib_path
realms_db_conf_path = '%s/dbpass.ini' % config_path
lighttpd_config_path = '%s/lighttpd.inc' % config_path
source_path = '%s/blx/example' % realms_path
user = 'jaskinia'
def realm_path(realm):
return '%(rp)s/%(r)s' % {'rp': realms_path, 'r': realm}
@task
def copy(dest_dir):
"""
Creates new directory for realm (realms/dest_dir) with proper permissions
@param string dest_dir destination directory name
"""
dest_path = realm_path(dest_dir)
with settings(hide('warnings'), warn_only=True):
if local("test -d %s" % dest_path).succeeded:
return
local('sudo su jaskinia -c "cp -r %s %s"' % (source_path, dest_path))
local('sudo su jaskinia -c "chmod g+w -R %s"' % dest_path)
@task(alias='rcf')
def remove_blx_common_files(dest_dir):
"""
Removes common Blx files that are linked from magazyn/blx
@param string dest_dir destination directory (realms/dest_dir/magazyn)
"""
dest_path = realm_path(dest_dir)
with lcd(dest_path):
with lcd('magazyn/css'):
local('rm content.css editor.css elements.css form.css')
with lcd('magazyn/js'):
local('rm site.js xinha xinha_conf.js')
local('rm -r xinha-0.96.1')
@task
def pliki(dest_dir):
"""
Creates new directory in "pliki" (realms/pliki/dest_dir)
with proper permissions
@param string dest_dir destination directory name
"""
files_path = '%s/pliki/%s' % (realms_path, dest_dir)
with settings(hide('warnings'), warn_only=True):
if local("test -d %s" % files_path).succeeded:
return
local('sudo su jaskinia -c "mkdir %s"' % files_path)
local('sudo su jaskinia -c "chmod g+w -R %s"' % files_path)
@task
def magazyn(source_dir, dest_dir):
"""
Creates symlink from realms/source_dir/magazyn do realms/magazyn/dest_dir
@param string source_dir source directory name
@param string dest_dir destination directory name
"""
source_path = '%s/magazyn' % realm_path(source_dir)
dest_path = '%s/magazyn/%s' % (realms_path, dest_dir)
local("test -d %s" % source_path)
with settings(hide('warnings'), warn_only=True):
if local("test -d %s" % dest_path).succeeded:
return
local('ln -s %s %s' % (source_path, dest_path))
def test_config(cmd, msg, hint, expect_fail=False):
response = green('OK ')
hint_tmp = ''
with settings(hide('running', 'warnings', 'stdout', 'stderr'),\
warn_only=True):
result = local(cmd, capture=True)
if result.failed != expect_fail:
response = red('ERROR')
hint_tmp = '\n' + indent('HINT: %s' % hint, 6)
print response, msg, hint_tmp
def test_jbcore_realm_config(realm):
test_config('grep "\[%s\]" %s' % (realm, realms_conf_path),\
'Checking if realm is set in jbcore configuration',\
'Add missing configuration to %s' % realms_conf_path)
def test_jbcore_realm_db_config(realm):
test_config('grep "\[%s\]" %s' % (realm, realms_db_conf_path),\
'Checking if DB connection for realm is set',\
'Add missing configuration to %s' % realms_db_conf_path)
def test_lighttpd_config(realm):
test_config('grep "var\.realm = \\"%s\\"" %s' % \
(realm,lighttpd_config_path),\
'Checking if realm is set in lighttpd configuration',\
'Add missing configuration to %s' % lighttpd_config_path)
def test_admin_group(dest_dir):
source_dir = '%s/run.php' % realm_path(dest_dir)
test_config('grep "$adminGroup = 5140;" %s' % source_dir,\
'Checking if admin group is set',\
'Update site`s administration group in %s' % source_dir,
expect_fail=True)
print indent('HINT: check if proper group is set in %s' % source_dir, 6)
def test_realms_list(realm):
"""
Checks whether realm is added to list of realms displayed on main page
"""
source_dir = '/home/jaskinia/realms/heroes/app/realms.php'
test_config('grep "\'%s\'" %s' % (realm, source_dir),\
'Checking if realm is displayed on main page',\
'Add realm to list of realms displayed on main page in %s' % source_dir)
def test_generate_board_list(realm):
path = '%s/pylib/pyapps/queue_proxy/handlers/generate_board_list.php' % \
jaskinia_path
print yellow('INFO '), 'Checking if latest discussions are generated for '\
+ 'used board'
print indent('HINT: check manually in %s' % path, 6);
@task
def mine(id, name, path, group):
"""
Creates public chamber with given id, name and path for given group.
@param string id chamber ID
@param string name chamber name
@param string path path inside /home/jaskinia/realms/pliki -without it!
@param int group group that will manage new chamber
"""
print 'Creating mine chamber'
try:
JBObject.setRealm('kopalnia')
except JBError:
abort('Couldn`t set realm')
db = JBDB.instance()
cur = db.cursor()
query='insert into chambers values (%s, %s, %s, %s::int[], %s::int[], ' \
+ '%s::int[], %s::int[], %s::int[], %s::int[], %s)'
params = (id, name, path, None, [group], [group], \
None, None, None, False)
cur.execute(query, params)
db.connect().commit()
@task
def lang(source_dir, dest_realm, lang='pl_PL'):
"""
Compiles locale file (lang.po) for given realm (realms/source_dir/locale/)
and saves result (.mo) into given directory
(locale/lang/LC_MESSAGES/dest_realm.mo)
@param string source_dir source realm dir (realms/source_dir/locale/)
@param string dest_realm destination realm name (dest_realm.mo)
@param string lang language file to compile (pl_PL by default)
"""
lang_path = '%s/locale/%s.po' % (realm_path(source_dir), lang)
dest_path = locale_path % (lang, dest_realm)
local('test -e %s' % lang_path)
local('sudo su jaskinia -c "msgfmt %s -o %s"' % (lang_path, dest_path))
local('sudo /etc/rc.d/init.d/fcgi restart jaskinia')
@task
def db(realm):
"""
Creates default pages/articles in blx.pages
@param string realm realm that will own pages
"""
print 'Creating default pages'
try:
JBObject.setRealm(realm)
except JBError:
pass
db = JBDB.instance()
cur = db.cursor()
query = 'select blx.set_page(%s, %s, %s, %s, %s)'
params = [('index.html', realm, u'Strona główna', 108, u'[news]'),\
('_special.html', realm, u'Strony specjalne', 108, \
u'<ul><li><a href="/_special/menu.html">Menu (PL)</li></ul>'),
('_special/menu.html', realm, u'Menu (PL)', 108, \
u'<ul><li>Forum</li><li>O stronie</li></ul>')]
cur.executemany(query, params)
db.connect().commit()
@task
def test(realm, dest_dir):
"""
Tests verious configuration files (realms, dbpass, lighttpd)
@param string realm realm to check
@param string dest_dir destination directory of service
"""
test_jbcore_realm_config(realm)
test_jbcore_realm_db_config(realm)
test_lighttpd_config(realm)
test_generate_board_list(realm)
test_admin_group(dest_dir)
test_realms_list(realm)
@task(default=True)
def deploy(realm, group):
"""
Performs complete deployment of application
@param realm
@param group
"""
copy(realm)
remove_blx_common_files(realm)
lang(realm, realm)
pliki(realm)
magazyn(realm, realm)
mine(realm, realm.capitalize(), realm, group)
db(realm)
test(realm, realm)