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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2004-2009 Zuza Software Foundation
#
# This file is part of Pootle.
#
# 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 2 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/>.
# TODO: Make this less ugly
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'
import optparse
import django
from django.core.servers.basehttp import AdminMediaHandler
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import call_command
from translate import __version__ as toolkitversion
from translate.misc import wsgi
class PootleOptionParser(optparse.OptionParser):
def __init__(self):
optparse.OptionParser.__init__(self)
self.set_default('instance', 'Pootle')
self.add_option('',
'--version',
dest='action',
action='store_const',
const='version',
default='runwebserver',
help="show version information then exit",
)
self.add_option(
'',
'--refreshstats',
dest='action',
action='store_const',
const='refreshstats',
default='runwebserver',
help='refresh the stats files instead of running the webserver',
)
self.add_option(
'',
'--port',
action='store',
type='int',
dest='port',
default='8080',
help='The TCP port on which the server should listen for new connections.',
)
def checkversions():
"""Checks that version dependencies are met."""
if not hasattr(toolkitversion, 'build') or toolkitversion.ver < (1,5,0):
raise RuntimeError('requires Translate Toolkit version >= 1.5.0. Current installed version is: %s'
% toolkitversion.sver)
def display_versions():
from pootle.__version__ import sver as pootle_ver
from translate.__version__ import sver as translate_ver
from django import get_version as django_ver
print "Pootle %s" % pootle_ver
print "Translate Toolkit %s" % translate_ver
print "Django %s" % django_ver()
def run_pootle(options, args):
"""Run the requested action."""
if options.action == 'runwebserver':
path = django.__path__[0] + '/contrib/admin/media'
handler = AdminMediaHandler(WSGIHandler(), path)
wsgi.launch_server('0.0.0.0', options.port, handler)
elif options.action == 'refreshstats':
call_command('refresh_stats')
elif options.action == 'version':
display_versions()
def main():
# run the web server
checkversions()
parser = PootleOptionParser()
(options, args) = parser.parse_args()
if options.action != 'runwebserver':
options.servertype = 'dummy'
else:
print "Starting server, listening on port %d." % options.port
run_pootle(options, args)
if __name__ == '__main__':
main()
|