~mhall119/canonical-identity-provider/test-consumer-yubikey

« back to all changes in this revision

Viewing changes to payload/__init__.py

  • Committer: Tarmac
  • Author(s): Ricardo Kirkner
  • Date: 2011-03-11 21:02:26 UTC
  • mfrom: (137.1.1 deploy-translations)
  • Revision ID: tarmac@199959.czyzykowski.com-20110311210226-cwwan8wswqjxzk7l
added target for deploying package and translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from __future__ import absolute_import
4
4
 
5
5
import os.path
 
6
import shutil
6
7
import sys
7
8
import textwrap
 
9
from datetime import datetime
8
10
 
9
11
from fabric.api import (
10
12
    env,
11
13
    local,
12
14
)
13
15
from fabric.context_managers import cd
 
16
from fabric.contrib.files import exists
14
17
 
15
 
from .virtualenv import *
16
18
from .postgresql import *
17
19
from .upgrade_from_package import *
 
20
from .virtualenv import *
18
21
 
19
22
# make sure the virtualenv is automatically activated
20
23
setup_virtualenv()
29
32
 
30
33
# translations
31
34
APPS = ["identityprovider"]
32
 
LANGUAGES = ["es", "de", "pl", "zh_CN", "sw", "pt_BR"]
 
35
TRANSLATIONS_BRANCH = 'lp:canonical-identity-provider/translations'
33
36
 
34
37
 
35
38
# fab targets
95
98
 
96
99
 
97
100
# deploy
98
 
def translate():
 
101
def makemessages():
99
102
    """Create/Update translation strings in .po files."""
 
103
    django_settings = get_django_settings('SUPPORTED_LANGUAGES')
 
104
    supported_languages = django_settings['SUPPORTED_LANGUAGES']
100
105
    for app in APPS:
101
 
        for lang in LANGUAGES:
 
106
        for lang in supported_languages:
102
107
            with cd(app):
103
108
                cmd = ("python ../django_project/manage.py makemessages "
104
109
                    "-l %s -e .html,.txt")
105
110
                virtualenv(cmd % lang, capture=False)
106
111
 
107
112
 
108
 
def compile():
 
113
def compilemessages(args=''):
109
114
    """Compile .po translation files into binary (.mo)."""
 
115
    cmd = 'python ../django_project/manage.py compilemessages'
 
116
    if args:
 
117
        cmd += " %s" % args
110
118
    for app in APPS:
111
119
        with cd(app):
112
 
            virtualenv('python ../django_project/manage.py compilemessages',
113
 
                capture=False)
 
120
            virtualenv(cmd, capture=False)
 
121
 
 
122
 
 
123
def deploy(config_branch):
 
124
    """Deploy latest code and translations."""
 
125
    build_and_install_deb(config_branch)
 
126
    deploy_translations()
 
127
 
 
128
 
 
129
def deploy_translations():
 
130
    """Update and compile translations and deploy to server."""
 
131
    tmp_dir = os.tempnam()
 
132
    local("bzr branch %s %s" % (TRANSLATIONS_BRANCH, tmp_dir))
 
133
    try:
 
134
        args =_setup_locale_basedir(tmp_dir)
 
135
        compilemessages(args)
 
136
        _submit_translations(tmp_dir)
 
137
        update_translations(TRANSLATIONS_BRANCH)
 
138
    finally:
 
139
        shutil.rmtree(tmp_dir)
114
140
 
115
141
 
116
142
# helpers
169
195
    with file('django_project/local.cfg', 'w') as local_cfg:
170
196
        local_cfg.write(config)
171
197
 
 
198
 
 
199
def _setup_locale_basedir(translations_path):
 
200
    """Prepare the locale_paths."""
 
201
    locale_paths = '\n'.join(["%s/locale/%s" % (translations_path, app)
 
202
        for app in APPS])
 
203
    args = "--django_locale_paths=\"%s\"" % locale_paths
 
204
    return args
 
205
 
 
206
 
 
207
def _submit_translations(translations_path):
 
208
    """Push updated stable translations to upstream branch."""
 
209
    with cd(translations_path):
 
210
        output = local("bzr status")
 
211
        if output:
 
212
            output = local("bzr revno %s" % TRANSLATIONS_BRANCH)
 
213
            revno = int(output.strip())
 
214
            commit_message = ("compiled latest translations (%s@%d)" %
 
215
                (TRANSLATIONS_BRANCH, revno))
 
216
            local("bzr commit -m '%s'" % commit_message)
 
217
            local("bzr push %s" % TRANSLATIONS_BRANCH)
 
218
        else:
 
219
            print 'Nothing to do; translations are up to date.'
 
220
 
 
221
 
 
222