-
Notifications
You must be signed in to change notification settings - Fork 3
/
freeze.py
47 lines (38 loc) · 1.35 KB
/
freeze.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
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Freeze the Who Goes First web app."""
import os
import subprocess
import flask_frozen
import whogoesfirst
def create_mo_files():
"""
https://stackoverflow.com/a/37906830
"""
data_files = []
localedir = whogoesfirst.LOCALEDIR
po_dirs = [
localedir / l / 'LC_MESSAGES'
for l in next(os.walk(localedir))[1]]
for d in po_dirs:
mo_files = []
po_files = [f
for f in next(os.walk(d))[2]
if os.path.splitext(f)[1] == '.po']
for po_file in po_files:
filename, _ = os.path.splitext(po_file)
mo_file = filename + '.mo'
msgfmt_cmd = 'msgfmt {} -o {}'.format(d / po_file, d / mo_file)
subprocess.call(msgfmt_cmd, shell=True)
mo_files.append(d / mo_file)
data_files.append((d, mo_files))
return data_files
freezer = flask_frozen.Freezer(whogoesfirst.app)
whogoesfirst.app.config['FREEZER_DESTINATION'] = './public'
whogoesfirst.app.config['FREEZER_REDIRECT_POLICY'] = 'error'
if __name__ == '__main__':
create_mo_files()
whogoesfirst.initialize()
freezer.freeze()