Commit ebbc80cb authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 83ad3a30 ca4928ee
#!/bin/sh
nohup $OPENSHIFT_REPO_DIR/openshift/install.sh >$OPENSHIFT_PYTHON_LOG_DIR/install.log 2>&1 </dev/null &
#!/bin/sh
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Don't let OpenShift install weblate and its dependencies directly as this leads to timeouts during gear creation and deploys
if [ -e $OPENSHIFT_REPO_DIR/setup.py ]; then
mv $OPENSHIFT_REPO_DIR/setup.py $OPENSHIFT_REPO_DIR/setup_weblate.py
fi
if [ -e $OPENSHIFT_REPO_DIR/requirements.txt ]; then
mv $OPENSHIFT_REPO_DIR/requirements.txt $OPENSHIFT_REPO_DIR/requirements-mandatory.txt
fi
# Show install/update page, will be replaced with app by install.sh
# Link sources below $OPENSHIFT_REPO_DIR must be relative or they will be invalid after restore/clone operations
mkdir -p $OPENSHIFT_REPO_DIR/wsgi
ln -sf ../openshift/wsgi_install.py $OPENSHIFT_REPO_DIR/wsgi/application
#!/bin/sh
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Work around https://bugzilla.redhat.com/show_bug.cgi?id=1157830
for file in ~/.env/user_vars/*; do
key=$(basename $file)
export $key="$(< $file)"
done
AGE=""
if [ "$WEBLATE_PENDING_AGE" ]; then
if [ $WEBLATE_PENDING_AGE -gt 0 ]; then
AGE="--age=$WEBLATE_PENDING_AGE"
else
exit 0
fi
fi
source ${OPENSHIFT_HOMEDIR}/python/virtenv/bin/activate
python ${OPENSHIFT_REPO_DIR}/openshift/manage.py commit_pending --all $AGE
#!/bin/sh
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Work around https://bugzilla.redhat.com/show_bug.cgi?id=1157830
for file in ~/.env/user_vars/*; do
key=$(basename $file)
export $key="$(< $file)"
done
SECONDS_SINCE_LAST_RUN=`echo \`date +%s\` - 0\`stat -c%Y ${OPENSHIFT_DATA_DIR}/.update_index 2>/dev/null\` | bc`
if [ $SECONDS_SINCE_LAST_RUN -ge 300 ]; then
source ${OPENSHIFT_HOMEDIR}/python/virtenv/bin/activate
python ${OPENSHIFT_REPO_DIR}/openshift/manage.py update_index
touch ${OPENSHIFT_DATA_DIR}/.update_index
fi
......@@ -606,6 +606,182 @@ You should also adjust some settings to match your environment, namely:
* :ref:`production-site`
* :ref:`production-email`
.. _openshift:
Weblate on OpenShift
--------------------
This repository contains a configuration for the OpenShift platform as a service product, which facilitates easy installation
of Weblate on OpenShift Online (https://openshift.com), OpenShift Enterprise (https://www.openshift.com/products/enterprise)
and OpenShift Origin (https://www.openshift.com/products/origin).
Prerequisites
+++++++++++++
1. OpenShift Account
You need an account for OpenShift Online (https://openshift.com) or another OpenShift installation you have access to.
You can register a free account on OpenShift Online, which allows you to host up to 3 applications free of charge.
2. OpenShift Client Tools
In order to follow the examples given in this documentation you need to have the OpenShift Client Tools (RHC) installed:
https://developers.openshift.com/en/getting-started-client-tools.html.
While there are other possibilities to create and configure OpenShift applications, this documentation is based
on the OpenShift Client Tools (RHC) because they provide a consistent interface for all described operations.
Installation
++++++++++++
You can install Weblate on OpenShift directly from Weblate's github repository with the following command:
.. parsed-literal::
rhc -aweblate app create -t python-2.7 --from-code \https://github.com/nijel/weblate.git#weblate-|version| --no-git
The ``-a`` option defines the name of your weblate installation, ``weblate`` in this instance. You are free to specify a different name.
The identifier right of the ``#`` sign identifies the version of Weblate to install. For a list of available versions see here:
https://github.com/nijel/weblate/tags. Please note that only version 2.0 and newer can be installed on OpenShift,
as older versions don't include the necessary configuration files. The ``--no-git`` option skips the creation of a local git repository.
Default Configuration
+++++++++++++++++++++
After installation on OpenShift Weblate is ready to use and preconfigured as follows:
* SQLite embedded database (DATABASES)
* Random admin password
* Random Django secret key (SECRET_KEY)
* Indexing offloading if the cron cartridge is installed (OFFLOAD_INDEXING)
* Committing of pending changes if the cron cartridge is installed (commit_pending)
* Weblate machine translations for suggestions bases on previous translations (MACHINE_TRANSLATION_SERVICES)
* Source language for machine translations set to "en-us" (SOURCE_LANGUAGE)
* Weblate directories (STATIC_ROOT, GIT_ROOT, TTF_PATH, WHOOSH_INDEX, HOME, Avatar cache) set according to OpenShift requirements/conventions
* Django site name and ALLOWED_HOSTS set to DNS name of your OpenShift application
* Email sender addresses set to no-reply@<OPENSHIFT_CLOUD_DOMAIN>, where <OPENSHIFT_CLOUD_DOMAIN> is the domain OpenShift runs under. In case of OpenShift Online it's rhcloud.com.
.. seealso:: :ref:`customize_config`
Retrieve Admin Password
~~~~~~~~~~~~~~~~~~~~~~~
You can retrieve the generated admin password with the following command:
.. code-block:: sh
rhc -aweblate ssh credentials
Indexing Offloading
~~~~~~~~~~~~~~~~~~~
To enable the preconfigured indexing offloading you need to add the cron cartridge to your application and restart it:
.. code-block:: sh
rhc -aweblate add-cartridge cron
rhc -aweblate app stop
rhc -aweblate app start
The fulltext search index will then be updated every 5 minutes.
Restarting with ``rhc restart`` instead will not enable indexing offloading in Weblate.
You can verify that indexing offloading is indeed enabled by visiting the URL ``/admin/performance/`` of your application.
Pending Changes
~~~~~~~~~~~~~~~
Weblate's OpenShift configuration contains a cron job which periodically commits pending changes older than a certain age (24h by default).
To enable the cron job you need to add the cron cartridge and restart Weblate as described in the previous section. You can change the age
parameter by setting the environment variable WEBLATE_PENDING_AGE to the desired number of hours, e.g.:
.. code-block:: sh
rhc -aweblate env set WEBLATE_PENDING_AGE=48
.. _customize_config:
Customize Weblate Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can customize the configuration of your Weblate installation on OpenShift through environment variables.
Override any of Weblate's setting documented under :ref:`config` using ``rhc env set`` by prepending the settings name with ``WEBLATE_``.
For example override the ``ADMINS`` setting like this:
.. code-block:: sh
rhc -aweblate env set WEBLATE_ADMINS='(("John Doe", "jdoe@example.org"),)'
New settings will only take effect after restarting Weblate:
.. code-block:: sh
rhc -aweblate app stop
rhc -aweblate app start
Restarting using ``rhc -aweblate app restart`` does not work. For security reasons only constant expressions are allowed as values.
With the exception of environment variables which can be referenced using ``${ENV_VAR}``. For example:
.. code-block:: sh
rhc -aweblate env set WEBLATE_PRE_COMMIT_SCRIPTS='("${OPENSHIFT_DATA_DIR}/examples/hook-generate-mo",)'
You can check the effective settings Weblate is using by running:
.. code-block:: sh
rhc -aweblate ssh settings
This will also print syntax errors in your expressions.
To reset a setting to its preconfigured value just delete the corresponding environment variable:
.. code-block:: sh
rhc -aweblate env unset WEBLATE_ADMINS
.. seealso:: :ref:`config`
Updating
++++++++
It is recommended that you try updates on a clone of your Weblate installation before running the actual update.
To create such a clone run:
.. code-block:: sh
rhc -aweblate2 app create --from-app weblate
Visit the newly given URL with a browser and wait for the install/update page to disappear.
You can update your Weblate installation on OpenShift directly from Weblate's github repository by executing:
.. parsed-literal::
rhc -aweblate2 ssh update \https://github.com/nijel/weblate.git#weblate-|version|
The identifier right of the ``#`` sign identifies the version of Weblate to install.
For a list of available versions see here: https://github.com/nijel/weblate/tags.
Please note that the update process will not work if you modified the git repository of you weblate installation.
You can force an update by specifying the ``--force`` option to the update script. However any changes you made to the
git repository of your installation will be discarded:
.. parsed-literal::
rhc -aweblate2 ssh update --force \https://github.com/nijel/weblate.git#weblate-|version|
The ``--force`` option is also needed when downgrading to an older version.
Please note that only version 2.0 and newer can be installed on OpenShift,
as older versions don't include the necessary configuration files.
The update script takes care of the following update steps as described under :ref:`generic-upgrade-instructions`.
* Install any new requirements
* manage.py syncdb
* manage.py migrate
* manage.py setupgroups --move
* manage.py setuplang
* manage.py rebuild_index --all
Migrating Weblate to another server
-----------------------------------
......
......@@ -40,6 +40,17 @@ Using prebuilt appliance
#. Everything should be set up immediately after boot, though you will want
to adjust some settings to improve security, see :ref:`appliance`.
Installing on OpenShift
-----------------------
#. You can install Weblate on OpenShift PaaS directly from its git repository using the OpenShift Client Tools:
.. parsed-literal::
rhc -aweblate app create -t python-2.7 --from-code \https://github.com/nijel/weblate.git#weblate-|version| --no-git
#. After installation everything should be preconfigured and you can immediately start to add a translation
project as described below. For more information, including on how to retrieve the generated admin password, see :ref:`openshift`.
Adding translation
------------------
......
#! /bin/sh
cat ${OPENSHIFT_DATA_DIR}/.credentials
#! /bin/sh
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Log and execute given command, identing its output for easy filtering.
sh() {
echo "Executing '$1'"
/bin/sh -c "$1" 2>&1 | sed -u -e 's/^/ /'
}
# Find writable directory in PATH.
find_script_dir() {
SCRIPT_DIR=""
OLDIFS="$IFS"
IFS=:
for DIR in $PATH; do
test -w "$DIR" && SCRIPT_DIR="$DIR" && break
done
IFS="$OLDIFS"
test -n "$SCRIPT_DIR"
}
set -e
trap "rm $OPENSHIFT_DATA_DIR/.install" EXIT
trap 'echo -e "\nInstallation failed!"' ERR
test -e $OPENSHIFT_DATA_DIR/.install && exit 0
touch $OPENSHIFT_DATA_DIR/.install
export PYTHONUNBUFFERED=1
source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate
cd ${OPENSHIFT_REPO_DIR}
sh "python ${OPENSHIFT_REPO_DIR}/setup_weblate.py develop"
# Pin Django version to 1.7 to avoid surprises when 1.8 comes out.
sed -e 's/Django[<>=]\+.*/Django==1.7/' $OPENSHIFT_REPO_DIR/requirements-mandatory.txt >/tmp/requirements.txt
sh "pip install -r /tmp/requirements.txt"
if [ ! -s $OPENSHIFT_DATA_DIR/weblate.db ]; then
rm -f ${OPENSHIFT_DATA_DIR}/.credentials
fi
if [ ! -s $OPENSHIFT_REPO_DIR/weblate/fixtures/site_data.json ]; then
mkdir -p $OPENSHIFT_REPO_DIR/weblate/fixtures
cat <<-EOF >$OPENSHIFT_REPO_DIR/weblate/fixtures/site_data.json
[{
"pk": 1,
"model": "sites.site",
"fields": {
"name": "${OPENSHIFT_APP_DNS}",
"domain":"${OPENSHIFT_APP_DNS}"
}
}]
EOF
fi
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py syncdb --noinput"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py migrate"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py setupgroups --move"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py setuplang"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py compilemessages"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py rebuild_index --all"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py loaddata $OPENSHIFT_REPO_DIR/weblate/fixtures/site_data"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py collectstatic --noinput"
if [ ! -s $OPENSHIFT_DATA_DIR/.credentials ]; then
echo "Generating Weblate admin credentials and writing them to ${OPENSHIFT_DATA_DIR}/.credentials"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py createadmin"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/secure_db.py | tee ${OPENSHIFT_DATA_DIR}/.credentials"
fi
if find_script_dir; then
ln -sf ${OPENSHIFT_REPO_DIR}/openshift/update.sh $SCRIPT_DIR/update
ln -sf ${OPENSHIFT_REPO_DIR}/openshift/credentials.sh $SCRIPT_DIR/credentials
ln -sf ${OPENSHIFT_REPO_DIR}/openshift/settings.sh $SCRIPT_DIR/settings
fi
gear stop
# Link sources below $OPENSHIFT_REPO_DIR must be relative or they will be invalid after restore/clone operations
ln -sf ../openshift/wsgi.py $OPENSHIFT_REPO_DIR/wsgi/application
touch $OPENSHIFT_DATA_DIR/.installed
gear start
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings_openshift")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
#!/usr/bin/env python
# Copyright 2011-2014 Red Hat Inc. and/or its affiliates and other contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import hashlib, inspect, os, random, sys
# Gets the secret token provided by OpenShift
# or generates one (this is slightly less secure, but good enough for now)
def get_openshift_secret_token():
token = os.getenv('OPENSHIFT_SECRET_TOKEN')
name = os.getenv('OPENSHIFT_APP_NAME')
uuid = os.getenv('OPENSHIFT_APP_UUID')
if token is not None:
return token
elif (name is not None and uuid is not None):
return hashlib.sha256(name + '-' + uuid).hexdigest()
return None
# Loop through all provided variables and generate secure versions
# If not running on OpenShift, returns defaults and logs an error message
#
# This function calls secure_function and passes an array of:
# {
# 'hash': generated sha hash,
# 'variable': name of variable,
# 'original': original value
# }
def openshift_secure(default_keys, secure_function = 'make_secure_key'):
# Attempts to get secret token
my_token = get_openshift_secret_token()
# Only generate random values if on OpenShift
my_list = default_keys
if my_token is not None:
# Loop over each default_key and set the new value
for key, value in default_keys.iteritems():
# Create hash out of token and this key's name
sha = hashlib.sha256(my_token + '-' + key).hexdigest()
# Pass a dictionary so we can add stuff without breaking existing calls
vals = { 'hash': sha, 'variable': key, 'original': value }
# Call user specified function or just return hash
my_list[key] = sha
if secure_function is not None:
# Pick through the global and local scopes to find the function.
possibles = globals().copy()
possibles.update(locals())
supplied_function = possibles.get(secure_function)
if not supplied_function:
raise Exception("Cannot find supplied security function")
else:
my_list[key] = supplied_function(vals)
else:
calling_file = inspect.stack()[1][1]
if os.getenv('OPENSHIFT_REPO_DIR'):
base = os.getenv('OPENSHIFT_REPO_DIR')
calling_file.replace(base,'')
sys.stderr.write("OPENSHIFT WARNING: Using default values for secure variables, please manually modify in " + calling_file + "\n")
return my_list
# This function transforms default keys into per-deployment random keys;
def make_secure_key(key_info):
hashcode = key_info['hash']
original = key_info['original']
# These are the legal password characters
# as per the Django source code
# (django/contrib/auth/models.py)
chars = 'abcdefghjkmnpqrstuvwxyz'
chars += 'ABCDEFGHJKLMNPQRSTUVWXYZ'
chars += '23456789'
# Use the hash to seed the RNG
random.seed(int("0x" + hashcode[:8], 0))
# Create a random string the same length as the default
rand_key = ''
for _ in range(len(original)):
rand_pos = random.randint(0,len(chars))
rand_key += chars[rand_pos:(rand_pos+1)]
# Reset the RNG
random.seed()
# Set the value
return rand_key
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.conf import settings
# Use default Django settings
settings.configure()
import os, sqlite3
from openshift.openshiftlibs import make_secure_key, get_openshift_secret_token
from hashlib import sha256
from django.contrib.auth.hashers import make_password
new_pass = make_secure_key({ 'hash': sha256(get_openshift_secret_token()).hexdigest(), 'original': '0' * 12, 'variable': '' })
new_hash = make_password(new_pass)
# Update admin password in database
conn = sqlite3.connect(os.environ['OPENSHIFT_DATA_DIR'] + '/weblate.db')
cursor = conn.cursor()
cursor.execute('UPDATE AUTH_USER SET password = ? WHERE username = ?', [new_hash, 'admin'])
conn.commit()
cursor.close()
conn.close()
# Print the new password info
print "Weblate admin credentials:\n\tuser: admin\n\tpassword: " + new_pass
#!/bin/sh
source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate
${OPENSHIFT_REPO_DIR}/openshift/manage.py diffsettings
#! /bin/sh
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
if [ "$1" = "--force" ]; then
FORCE="--force"
shift
else
FORCE=""
fi
if [ $# -ne 1 ]; then
echo ""
echo "usage:"
echo " update [--force] <git_url>"
echo ""
echo " --force: Force update that could overwrite changes you made to the OpenShift repository. Also necessary when downgrading or switching branches."
echo " <git_url>: URL of git repository to update from. A branch can be specified by appending '#<branch>'"
echo " Example: https://github.com/nijel/weblate.git#master"
echo ""
exit 1
fi
# Split first argument with delimiter '#'
OLDIFS=$IFS
IFS='#'
set -- $1
IFS=$OLDIFS
URL="$1"
BRANCH="${2:-master}"
cd ${OPENSHIFT_HOMEDIR}/git/${OPENSHIFT_APP_NAME}.git
OLD_HEAD=`git rev-parse master`
git fetch $FORCE "$URL" "$BRANCH":master
HEAD=`git rev-parse master`
if [ "$HEAD" == "$OLD_HEAD" ]; then
echo "Already up-to-date."
exit 0
fi
if ! git cat-file -e master:.openshift 2>/dev/null; then
echo "Fatal error: Branch $BRANCH of repository at $URL doesn't contain an OpenShift configuration!" >&2
exit 1
fi
gear deploy --hot-deploy master
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'weblate'))
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'openshift'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'weblate.settings_openshift'
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
from string import Template
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
def application(environ, start_response):
ctype = 'text/html'
response_body = Template('''<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>Installing Weblate</title>
<style>
html {
background: #f5f5f5;
height: 100%;
}
body {
color: #404040;
font-family: "Helvetica Neue",Helvetica,"Liberation Sans",Arial,sans-serif;
font-size: 14px;
line-height: 1.4;
}
h1 {
color: #000;
line-height: 1.38em;
margin: .4em 0 .5em;
font-size: 25px;
font-weight: 300;
border-bottom: 1px solid #fff;
}
h1:after {
content: "";
display: block;
height: 1px;
background-color: #ddd;
}
p {
margin: 0 0 2em;
}
pre {
padding: 13.333px 20px;
margin: 0 0 20px;
font-size: 13px;
line-height: 1.4;
background-color: #fff;
border-left: 2px solid rgba(120,120,120,0.35);
font-family: Menlo,Monaco,"Liberation Mono",Consolas,monospace !important;
}
.content {
display: table;
margin-left: -15px;
margin-right: -15px;
position: relative;
min-height: 1px;
padding-left: 30px;
padding-right: 30px;
}
</style>
</head>
<body>
<div class="content">
<h1>$action1 Weblate</h1>
<p>Weblate is beeing $action2. Please wait a few minutes and refresh this page.</p>
$log
</div>
</body>
</html>''')
if os.path.exists(os.environ['OPENSHIFT_DATA_DIR'] + '/.installed'):
action1 = 'Updating'
action2 = 'updated'
log = ''
else:
action1 = 'Installing'
action2 = 'installed'
log = '<pre>' + os.popen('cat ${OPENSHIFT_PYTHON_LOG_DIR}/install.log | grep \'^[^ ]\\|setup.py install\' | sed \'s,/var/lib/openshift/[a-z0-9]\{24\},~,g\'').read() + '</pre>'
response_body = response_body.substitute(locals())
status = '200 OK'
response_headers = [('Content-Type', ctype), ('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
......@@ -12,7 +12,7 @@ profile=no
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=migrations,south_migrations,settings.py,settings_test.py,settings_test_mysql.py,settings_test_postgresql.py,settings_test_sqlite.py,.git,test-repos,repos,settings_test_nose.py
ignore=migrations,south_migrations,settings.py,settings_openshift.py,settings_test.py,settings_test_mysql.py,settings_test_postgresql.py,settings_test_sqlite.py,.git,test-repos,repos,settings_test_nose.py
# Pickle collected data for later comparisons.
persistent=yes
......
# -*- coding: utf-8 -*-
#
# Copyright © 2014 Daniel Tschan <tschan@puzzle.ch>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
import re
import ast
from string import Template
from openshift.openshiftlibs import openshift_secure
# Import example settings file to get default values for Weblate settings.
from weblate.settings_example import *
DEBUG = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'weblate.db'),
'ATOMIC_REQUESTS': True,
}
}
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TIME_ZONE = None
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'wsgi', 'static')
default_keys = {'SECRET_KEY': SECRET_KEY}
# Replace default keys with dynamic values if we are in OpenShift
use_keys = default_keys
use_keys = openshift_secure(default_keys)
SECRET_KEY = use_keys['SECRET_KEY']
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
'avatar': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(
os.environ['OPENSHIFT_DATA_DIR'], 'avatar-cache'
),
'TIMEOUT': 604800,
'OPTIONS': {
'MAX_ENTRIES': 1000,
},
}
}
GIT_ROOT = os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'repos')
# Offload indexing: if the cron cartridge is installed the preconfigured job
# in .openshift/cron/minutely/update_index updates the index.
if os.environ.get('OPENSHIFT_CRON_DIR', False):
OFFLOAD_INDEXING = True
else:
OFFLOAD_INDEXING = False
# Where to put Whoosh index
WHOOSH_INDEX = os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'whoosh-index')
SOURCE_LANGUAGE = 'en-us'
# List of machine translations
MACHINE_TRANSLATION_SERVICES = (
'weblate.trans.machine.weblatetm.WeblateSimilarTranslation',
'weblate.trans.machine.weblatetm.WeblateTranslation',
)
if os.environ.get('OPENSHIFT_CLOUD_DOMAIN', False):
SERVER_EMAIL = 'no-reply@%s' % os.environ['OPENSHIFT_CLOUD_DOMAIN']
DEFAULT_FROM_EMAIL = 'no-reply@%s' % os.environ['OPENSHIFT_CLOUD_DOMAIN']
ALLOWED_HOSTS = [os.environ['OPENSHIFT_APP_DNS']]
TTF_PATH = os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'weblate', 'ttf')
os.environ['HOME'] = os.environ['OPENSHIFT_DATA_DIR']
# Import environment variables prefixed with WEBLATE_ as weblate settings
_this_module = sys.modules[__name__]
weblate_var = re.compile('^WEBLATE_[A-Za-z0-9_]+$')
for name, value in os.environ.items():
if weblate_var.match(name):
try:
setattr(_this_module, name[8:],
ast.literal_eval(Template(value).substitute(os.environ)))
except ValueError as e:
if not e.args:
e.args = ('',)
e.args = (
"Error parsing %s = '%s': %s" % (name, value, e.args[0]),
) + e.args[1:]
raise
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment