forked from fedora-infra/packagedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
427 lines (377 loc) · 14.3 KB
/
pavement.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/python -tt
import pkg_resources
from paver.easy import path as paver_path
from paver.easy import sh as paver_sh
from paver.easy import *
import paver.misctasks
from paver import setuputils
setuputils.install_distutils_tasks()
import sys, os
import re
import glob
import paver.doctools
from setuptools import find_packages, command
from turbogears.finddata import find_package_data
sys.path.insert(0, str(paver_path.getcwd()))
from pkgdb.release import *
options(
setup = Bunch(
name=NAME,
version=VERSION,
description=DESCRIPTION,
author=AUTHOR,
author_email=EMAIL,
url=URL,
download_url=DOWNLOAD_URL,
license=LICENSE,
install_requires = [
'TurboGears[future] >= 1.0',
'TurboMail',
'python_fedora >= 0.3.12',
'SQLAlchemy >= 0.5.5, < 0.7',
# Doesn't use setuptools so not on RHEL5
#'python_bugzilla >= 0.5',
],
scripts = ['start-pkgdb', 'pkgdb.wsgi', 'clients/pkgdb-client',
'server-scripts/pkgdb-sync-yum',
'server-scripts/pkgdb-sync-bugzilla'],
zip_safe=False,
packages=find_packages(),
package_data = find_package_data(where='pkgdb',
package='pkgdb'),
keywords = [
# Use keywords if you'll be adding your package to the
# Python Cheeseshop
# if this has widgets, uncomment the next line
# 'turbogears.widgets',
# if this has a tg-admin command, uncomment the next line
# 'turbogears.command',
'turbogears.app',
],
message_extractors = {
'pkgdb': [('**.py', 'python', None),
('templates/**.html', 'genshi', None),],
},
classifiers = [
'Development Status :: 4 - Beta',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Environment :: Web Environment',
'Framework :: TurboGears',
# if this is an application that you'll distribute through
# the Cheeseshop, uncomment the next line
'Framework :: TurboGears :: Applications',
# if this is a package that includes widgets that you'll distribute
# through the Cheeseshop, uncomment the next line
# 'Framework :: TurboGears :: Widgets',
],
test_suite = 'nose.collector',
entry_points = {
'console_scripts': [
'start-pkgdb = pkgdb.commands:start'
],
},
),
sphinx = Bunch(
docroot='.',
builddir='build-doc',
sourcedir='docs'
),
pylint = Bunch(
module=['pkgdb']
),
publish=Bunch(
doc_location='fedorahosted.org:/srv/web/releases/p/a/packagedb/doc/',
tarball_location='fedorahosted.org:/srv/web/releases/p/a/packagedb/'
),
i18n=Bunch(
builddir='locale',
domain='fedora-packagedb',
),
data = Bunch(
#datafiles=[],
localefiles=['locale'],
docfiles=['docs'],
conffiles=['pkgdb.cfg', 'pkgdb-client.cfg', {'httpd-pkgdb.conf': 'httpd/conf.d/pkgdb.conf'},
'fedmsg.d/pkgdb.py'],
),
### FIXME: Eventually, this should be tied into data and a library that
# finds file location instead.
installdirs = Bunch(
prefix='/usr/local',
execprefix='%(prefix)s',
bindir='%(execprefix)s/bin',
sbindir='%(execprefix)s/sbin',
libexecdir='%(execprefix)s/libexec',
datadir='%(prefix)s/share',
sysconfdir='%(prefix)s/etc',
localstatedir='%(prefix)s/var',
includedir='%(prefix)s/include',
infodir='%(datadir)s/info',
mandir='%(datadir)s/man',
localedir='%(datadir)s/locale',
),
### FIXME: Eventually, this should be tied into data and a library that
# finds file location instead.
substitute = Bunch(
# Files to substitute on
onfiles=['start-pkgdb', 'pkgdb.wsgi', 'server-scripts/pkgdb-sync-yum',
'server-scripts/pkgdb-sync-bugzilla',
'update-schema/pkgdb-0.3.10-0.3.11.py', 'httpd-pkgdb.conf'],
# Strings to substitute inside the files
patterns={'@CONFDIR@': '/usr/local/etc',
'@DATADIR@': '/usr/local/share',
'@SBINDIR@': '/usr/local/sbin'},
),
### FIXME: These are due to a bug in paver-1.0
# http://code.google.com/p/paver/issues/detail?id=24
sdist=Bunch(),
)
#
# Publish tasks -- somewhat site specific
#
@task
@needs(['html'])
def publish_doc():
options.order('publish', add_rest=True)
command = 'rsync -av build-doc/html/ %s' % (options.doc_location,)
dry(command, paver_sh, command)
@task
@needs(['sdist'])
def publish_tarball():
options.order('publish', add_rest=True)
tarname = '%s-%s.tar.bz2' % (options.name, options.version)
command = 'scp dist/%s %s' % (tarname, options.tarball_location)
dry(command, paver_sh, command)
@task
@needs(['publish_doc', 'publish_tarball'])
def publish():
pass
#
# convenience tasks to create all messages catalogs instead of one at a time
#
try:
import babel.messages.frontend
has_babel = True
except ImportError:
has_babel = False
if has_babel:
@task
def make_catalogs():
'''Compile all message catalogs for release'''
options.order('i18n', add_rest=True)
for po_file in glob.glob('po/*.po'):
locale, ext = os.path.splitext(os.path.basename(po_file))
build_dir = paver_path(options.builddir)
build_dir = build_dir.joinpath(locale, 'LC_MESSAGES')
build_dir.makedirs(mode=0755)
if 'compile_catalog' in options.keys():
defaults = options.compile_catalog
else:
defaults = Bunch(domain=options.domain,
directory=options.builddir)
options.compile_catalog = defaults
defaults.update({'input-file': po_file, 'locale': locale})
### FIXME: compile_catalog cannot handle --dry-run on its own
dry('paver compile_catalog -D %(domain)s -d %(directory)s'
' -i %(input-file)s --locale %(locale)s' % defaults,
paver_sh, 'paver compile_catalog -D %(domain)s' \
' -d %(directory)s -i %(input-file)s' \
' --locale %(locale)s' % defaults)
### FIXME: Need to get call_task to call this repeatedly
# because options.compile_catalog has changed
#dry('paver compile_catalog -D %(domain)s -d %(directory)s'
# ' -i %(input-file)s --locale %(locale)s' % defaults,
# call_task, 'babel.messages.frontend.compile_catalog', options)
#
# Install tasks
#
### Backends ###
def _apply_root(args, path):
'''Add the root value to the start of the path'''
if 'root' in args:
if path.startswith('/'):
path = path[1:]
path = paver_path(os.path.join(args['root'], path))
else:
path = paver_path(path)
return path
def _install_catalogs(args, paths):
'''Install message catalogs in their proper location on the filesystem.
Note: To use this with non-default commandline arguments, you must use
'''
# Rebuild message catalogs
if 'skip_build' not in args and 'skip-build' not in args:
call_task('make_catalogs')
options.order('i18n', add_rest=True)
# Setup the install_dir
cat_dir = _apply_root(args, paths.localedir)
for catalog in paver_path(options.builddir).walkfiles('*.mo'):
locale_dir = catalog.dirname()
path = paver_path('.')
for index, nextpath in enumerate(locale_dir.splitall()):
path = path.joinpath(nextpath)
if paver_path(options.builddir).samefile(path):
install_locale = cat_dir.joinpath(os.path.join(
*locale_dir.splitall()[index + 1:]))
install_locale.makedirs(mode=0755)
install_locale = install_locale.joinpath(catalog.basename())
if install_locale.exists():
install_locale.remove()
dry('cp %s %s'% (catalog, install_locale),
catalog.copy, install_locale)
dry('chmod 0644 %s'% install_locale,
install_locale.chmod, 0644)
def _install_conf(args, paths):
'''Install configuration files'''
options.order('setup', add_rest=True)
if 'skip_build' not in args and 'skip-build' not in args:
call_task('substitute')
options.order('data', add_rest=True)
# Setup the install_dir
conf_dir = apply_root(args, paths.sysconfdir)
conf_dir.joinpath(options.name)
if not conf_dir.exists():
conf_dir.makedirs(mode=0755)
for conf_file in options.data.conffiles:
conf_file = paver_path(conf_file)
installfile = conf_dir.joinpath(conf_file)
dry('cp %s %s' % (conf_file, installfile),
conf_file.copy, install_file)
dry('chmod 0644 %s'% install_locale,
install_locale.chmod, 0644)
for catalog in paver_path(options.builddir).walkfiles('*.mo'):
locale_dir = catalog.dirname()
path = paver_path('.')
for index, nextpath in enumerate(locale_dir.splitall()):
path = path.joinpath(nextpath)
if paver_path(options.builddir).samefile(path):
install_locale = cat_dir.joinpath(os.path.join(
*locale_dir.splitall()[index + 1:]))
install_locale.makedirs(mode=0755)
install_locale = install_locale.joinpath(catalog.basename())
if install_locale.exists():
install_locale.remove()
dry('cp %s %s'% (catalog, install_locale),
catalog.copy, install_locale)
dry('chmod 0644 %s'% install_locale,
install_locale.chmod, 0644)
pass
def _install_data(args, paths):
pass
def _install_sbin(args, paths):
pass
# Any install target needs to first look in:
# Commandline
# Default config
@task
def install_doc():
pass
@task
def install_public_code():
pass
@task
def install_private_code():
pass
def _db_autodoc_run(*args, **kwargs):
cmd = subprocess.Popen('/usr/bin/postgresql_autodoc -d pkgdb -u pkgdbadmin -h localhost --password -t dia'.split(' '))
return cmd.wait()
@task
def db_autodoc():
autodocopts = options.module
dry('postgresql_autodoc -d pkgdb -u pkgdbadmin -h localhost --password -t dia', _db_autodoc_run, autodocopts)
### Frontends -- these are what you invoke with paver ###
@task
@cmdopts([('root=', None, 'Base root directory to install into'),
('install-catalogs=', None, 'directory that locale catalogs go in'),
('skip-build', None, 'Skip directly to installing'),
])
def install_catalogs():
_install_catalogs(options.install_catalogs)
pass
### FIXME: setuptools.command.install does not respond to --dry-run
@task
@needs(['setuptools.command.install'])
def install():
'''Override the setuptools install.'''
# First override any paths
for arg in options.install:
if arg in options.installdirs.keys():
options.installdirs[arg] = options.install[arg]
# Then expand all paths
new = Bunch()
num_unexpanded = 0
for path_type in options.installdirs:
options.installdirs[path_type] = options.installdirs[path_type] % \
options.installdirs
new[path_type] = options.installdirs[path_type]
while num_unexpanded != len(options.installdirs):
num_unexpanded = len(options.installdirs)
for path_type in options.installdirs.keys():
options.installdirs[path_type] = options.installdirs[path_type] % \
new
if new[path_type] == options.installdirs[path_type]:
del options.installdirs[path_type]
else:
new[path_type] = options.installdirs[path_type]
if num_unexpanded:
raise PavementError('%s unexpanded path variables. Correct these in pavement.py installdirs: %s' % (num_unexpanded, options.installdirs))
# Then call each individual piece of installation
_install_catalogs(options.install, new)
_install_conf(options.install, new)
_install_data(options.install, new)
_install_sbin(options.install, new)
@task
@needs(['make_catalogs', 'setuptools.command.sdist'])
def sdist():
pass
#
# Generic Tasks
#
### Substitute path variables ###
@task
@cmdopts([
('install-conf=', None, 'Installation directory for configuration files'),
('install-data=', None, 'Installation directory for data files'),
('install-sbin=', None, 'Installation directory for daemons')
])
def substitute():
options.order('substitutions', add_rest=True)
substitutions = options.patterns
if hasattr(options.substitute, 'install_conf'):
substitutions['@CONFDIR@'] = options.substitute.install_conf
if hasattr(options.substitute, 'install_data'):
substitutions['@DATADIR@'] = options.substitute.install_data
if hasattr(options.substitute, 'install_sbin'):
substitutions['@SBINDIR@'] = options.substitute.install_sbin
subRE = re.compile('('+'|'.join(options.patterns.keys())+')+')
for filename in options.onfiles:
infile = paver_path(filename + '.in')
if not infile.exists():
raise PavementError('Nonexistent file listed in substitute: %s' % infile)
outf = paver_path(filename)
contents = []
for line in infile.lines(encoding='utf8'):
matches = subRE.search(line)
if matches:
for pattern in substitutions:
line = line.replace(pattern, substitutions[pattern])
contents.append(line)
outf.write_lines(contents, encoding='utf8')
@task
@needs(['substitute', 'setuptools.command.build'])
def build():
pass
### Pylint ###
try:
from pylint import lint
has_pylint = True
except ImportError:
has_pylint = False
if has_pylint:
@task
def pylint():
'''Check the module you're building with pylint.'''
options.order('pylint', add_rest=True)
pylintopts = options.module
dry('pylint %s' % (" ".join(pylintopts)), lint.Run, pylintopts)