1#!/usr/bin/env python
2
3from __future__ import print_function
4
5
6import re
7import sys
8import distutils
9from distutils import core, log
10from glob import glob
11
12import os
13import io
14
15sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
16
17__version__ = os.getenv('VERSION', default=os.getenv('PVR', default='9999'))
18
19cwd = os.getcwd()
20
21# Python files that need `__version__ = ""` subbed, relative to this dir:
22python_scripts = [os.path.join(cwd, path) for path in (
23 'esearch/__init__.py',
24)]
25
26class set_version(core.Command):
27 """Set python __version__ and bash VERSION to our __version__."""
28 description = "hardcode scripts' version using VERSION from environment"
29 user_options = [] # [(long_name, short_name, desc),]
30
31 def initialize_options (self):
32 pass
33
34 def finalize_options (self):
35 pass
36
37 def run(self):
38 ver = 'vcs' if __version__ == '9999' else __version__
39 print("Settings version to %s" % ver)
40 def sub(files, pattern):
41 for f in files:
42 updated_file = []
43 with io.open(f, 'r', 1, 'utf_8') as s:
44 for line in s:
45 newline = re.sub(pattern, '"%s"' % ver, line, 1)
46 if newline != line:
47 log.info("%s: %s" % (f, newline))
48 updated_file.append(newline)
49 with io.open(f, 'w', 1, 'utf_8') as s:
50 s.writelines(updated_file)
51 quote = r'[\'"]{1}'
52 python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote
53 sub(python_scripts, python_re)
54
55
56packages = [
57 str('.'.join(root.split(os.sep)[1:]))
58 for root, dirs, files in os.walk('./esearch')
59 if '__init__.py' in files
60]
61
62core.setup(
63 name='esearch',
64 version=__version__,
65 description='Replacement for emerge --search',
66 author='',
67 author_email='',
68 maintainer='Gentoo Portage Tools Team',
69 maintainer_email='tools-portage@gentoo.org',
70 url='http://www.gentoo.org/proj/en/portage/tools/index.xml',
71 download_url='http://distfiles.gentoo.org/distfiles/esearch-%s.tar.gz'\
72 % __version__,
73 package_dir={'': '.'},
74 packages=packages,
75 scripts=(glob('bin/*')),
76 data_files=(
77 (os.path.join('share/man/man1'), glob('man/en/*')),
78 (os.path.join('share/man/fr/man1'), glob('man/fr/*')),
79 (os.path.join('share/man/it/man1'), glob('man/it/*')),
80 ),
81 cmdclass={
82 'set_version': set_version,
83 },
84)
85
86# vim: set ts=4 sw=4 tw=79:
87