forked from ikus060/rdiffweb
/
setup.py
190 lines (161 loc) · 6 KB
/
setup.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# rdiffweb, A web interface to rdiff-backup repositories
# Copyright (C) 2014 rdiffweb contributors
#
# 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/>.
try:
from setuptools import setup
except ImportError:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup
import sys
import os
from distutils.command.build import build as build_
from babel.messages.frontend import compile_catalog, extract_messages, update_catalog, init_catalog
from distutils.cmd import Command
from distutils.dist import DistributionMetadata
from distutils.log import error, info
from distutils.util import split_quoted
from string import strip, Template
# < Python 2.4 does not have the package_data setup keyword, so it is unsupported
pythonVersion = sys.version_info[0] + sys.version_info[1] / 10.0
if pythonVersion < 2.4:
print 'Python version 2.3 and lower is not supported.'
sys.exit(1)
DistributionMetadata.templates = None
class fill_template(Command):
"""
Custom distutils command to fill text templates with release meta data.
"""
description = "Fill placeholders in documentation text file templates"
user_options = [
('templates=', None, "Template text files to fill")
]
def initialize_options(self):
self.templates = ''
self.template_ext = '.in'
def finalize_options(self):
if isinstance(self.templates, basestring):
self.templates = split_quoted(self.templates)
self.templates += getattr(self.distribution.metadata, 'templates', None) or []
for tmpl in self.templates:
if not tmpl.endswith(self.template_ext):
raise ValueError(
"Template file '%s' does not have expected " +
"extension '%s'." % (tmpl, self.template_ext))
def run(self):
metadata = self.get_metadata()
for infilename in self.templates:
try:
info("Reading template '%s'...", infilename)
with open(infilename) as infile:
tmpl = Template(infile.read())
outfilename = infilename.rstrip(self.template_ext)
info("Writing filled template to '%s'.", outfilename)
with open(outfilename, 'w') as outfile:
outfile.write(tmpl.safe_substitute(metadata))
except:
error("Could not open template '%s'.", infilename)
def get_metadata(self):
data = dict()
for attr in self.distribution.metadata.__dict__:
if not callable(attr):
data[attr] = getattr(self.distribution.metadata, attr)
return data
class compile_all_catalogs(Command):
"""
This is implementation of command which complies all catalogs
(dictionaries).
"""
description = 'compile message catalogs for all languages to binary MO files'
user_options = [
('domain=', 'D',
"domain of PO file (default 'messages')"),
('directory=', 'd',
'path to base directory containing the catalogs'),
('locales=', 'l',
'locale of the catalogs to compile'),
('use-fuzzy', 'f',
'also include fuzzy translations'),
('statistics', None,
'print statistics about translations')
]
boolean_options = ['use-fuzzy', 'statistics']
def initialize_options(self):
self.domain = None
self.directory = None
self.locales = None
self.use_fuzzy = False
self.statistics = False
def finalize_options(self):
self.locales = map(strip, self.locales.split(','))
def run(self):
for locale in self.locales:
compiler = compile_catalog(self.distribution)
compiler.initialize_options()
compiler.domain = self.domain
compiler.directory = self.directory
compiler.locale = locale
compiler.use_fuzzy = self.use_fuzzy
compiler.statistics = self.statistics
compiler.finalize_options()
compiler.run()
class build(build_):
"""
This is modification of build command, compile_all_catalogs
is added as last/first command
"""
sub_commands = build_.sub_commands[:]
sub_commands.insert(0, ('compile_all_catalogs', None))
setup(
name='rdiffweb',
version='0.8.3',
description='A web interface to rdiff-backup repositories',
author='Patrik Dufresne',
author_email='info@patrikdufresne.com',
url='http://www.patrikdufresne.com/en/rdiffweb/',
license="GPLv3",
packages=['rdiffweb'],
include_package_data=True,
entry_points={"console_scripts": ["rdiffweb = rdiffweb.main:start"]},
# new commands added and build command modified
cmdclass={
'build': build,
'compile_catalog': compile_catalog,
'extract_messages': extract_messages,
'update_catalog': update_catalog,
'init_catalog': init_catalog,
'compile_all_catalogs': compile_all_catalogs,
'filltmpl': fill_template,
},
templates=['sonar-project.properties.in'],
install_requires=[
"CherryPy>=3.2.2",
"pysqlite>=2.6.3",
"Jinja2>=2.6",
"yapsy>=1.10.423",
"babel>=0.9",
],
# required packages for build process
setup_requires=[
"babel>=0.9",
],
# requirement for testing
tests_require=[
"mockldap>=0.2.6",
"python-ldap>=2.4.21",
]
)