/
fabfile.py
133 lines (103 loc) · 2.69 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
import os
import shutil
import json
import web
from config import config
from base import db, auth
from models.tree import create_tree_branch
from fabric.api import task, local
@task
def watch():
'''Watches for changes in scss and compiles them to css'''
local('compass watch templates/scss')
@task
def compile():
'''Compiles scss to css'''
local('compass compile templates/scss')
@task
def i18n_extract():
'''Exctracts messages for translation'''
local('python i18n/extract-messages.py')
@task
def i18n_update():
'''Updates dictionary with new messages'''
local('pybabel update --ignore-obsolete -i i18n/messages.pot -d i18n/')
@task
def i18n_compile():
'''Compiles dictionary files'''
local('pybabel compile -d i18n/ -f --statistics')
@task
def server():
'''Runs server'''
local('python code.py')
@task
def lint():
'''Runs flake8 lint'''
local('flake8 . --exclude venv')
@task
def schema():
'''Creates database schema and fills website with initial data'''
database = config.database['dbn']
schema_commands = open('schema/' + database + '.sql', 'r').read()
for cmd in schema_commands.split(';'):
if cmd.strip():
db.query(cmd)
data = web.storage(json.loads(open('schema/data.json', 'r').read()))
now = web.db.SQLLiteral('CURRENT_TIMESTAMP')
user = auth.create_user(**data.user)
# System root folder
db.insert(
'documents',
user_id=user.id,
created_at=now,
**data.documents_root
)
for p in data.pages:
block = p.pop('block')
page_id = db.insert(
'pages',
is_published=False,
is_navigatable=True,
user_id=user.id,
created_at=now,
**p
)
create_tree_branch(
'blocks',
block,
page_id=page_id,
user_id=user.id,
is_published=True,
created_at=now,
published_at=now,
)
for block in data.template_blocks:
create_tree_branch(
'blocks',
block,
user_id=user.id,
is_published=True,
created_at=now,
published_at=now,
)
@task
def structure():
'''Creates necessary directories'''
shutil.rmtree(config.upload_dir, True)
os.mkdir(config.upload_dir)
shutil.rmtree(config.static_dir + '/i', True)
os.mkdir(config.static_dir + '/i')
@task
def setup():
structure()
schema()
compile()
@task
def deploy():
structure()
compile()
@task
def clean():
'''Removes all .pyc files'''
local('find . -name "*.pyc" -exec rm -rf {} \;')
local('rm static/css/*.css')