Fix eshowkw traceback on prefix enviroments (Bug 411599).
[gentoolkit.git] / setup.py
index ce4d959a57aee2cef74ea60914169fb4cee08b85..1efba94d8d0b76b212bd4e6f427a5e06281056bc 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -10,6 +10,7 @@ from distutils import core, log
 from glob import glob
 
 import os
+import io
 
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
 
@@ -20,14 +21,14 @@ cwd = os.getcwd()
 # Load EPREFIX from Portage, fall back to the empty string if it fails 
 try: 
        from portage.const import EPREFIX 
-except AttributeError: 
+except ImportError: 
        EPREFIX='' 
 
 
 # Bash files that need `VERSION=""` subbed, relative to this dir:
 bash_scripts = [os.path.join(cwd, path) for path in (
        'bin/euse',
-       'bin/revdep-rebuild'
+       'bin/revdep-rebuild.sh'
 )]
 
 # Python files that need `__version__ = ""` subbed, relative to this dir:
@@ -36,8 +37,10 @@ python_scripts = [os.path.join(cwd, path) for path in (
        'bin/epkginfo',
        'bin/glsa-check',
        'pym/gentoolkit/eclean/cli.py',
-       'pym/gentoolkit/analyse/__init__.py',
-       'pym/gentoolkit/equery/__init__.py'
+       'pym/gentoolkit/enalyze/__init__.py',
+       'pym/gentoolkit/equery/__init__.py',
+       'pym/gentoolkit/eshowkw/__init__.py',
+       'pym/gentoolkit/revdep_rebuild/__init__.py'
 )]
 
 
@@ -58,13 +61,13 @@ class set_version(core.Command):
                def sub(files, pattern):
                        for f in files:
                                updated_file = []
-                               with open(f) as s:
+                               with io.open(f, 'r', 1, 'utf_8') as s:
                                        for line in s:
                                                newline = re.sub(pattern, '"%s"' % ver, line, 1)
                                                if newline != line:
                                                        log.info("%s: %s" % (f, newline))
                                                updated_file.append(newline)
-                               with open(f, 'w') as s:
+                               with io.open(f, 'w', 1, 'utf_8') as s:
                                        s.writelines(updated_file)
                quote = r'[\'"]{1}'
                bash_re = r'(?<=VERSION=)' + quote + '[^\'"]*' + quote
@@ -94,13 +97,20 @@ def load_test():
 
        return test
 
-
 packages = [
        str('.'.join(root.split(os.sep)[1:]))
        for root, dirs, files in os.walk('pym/gentoolkit')
        if '__init__.py' in files
 ]
 
+test_data = {
+       'gentoolkit': [
+               'test/eclean/Packages',
+               'test/eclean/testdistfiles.tar.gz',
+               'test/eclean/distfiles.exclude'
+       ]
+}
+
 core.setup(
        name='gentoolkit',
        version=__version__,
@@ -114,12 +124,13 @@ core.setup(
                % __version__,
        package_dir={'': 'pym'},
        packages=packages,
+       package_data = test_data,
        scripts=(glob('bin/*')),
        data_files=(
-               (EPREFIX + '/etc/env.d', ['data/99gentoolkit-env']),
-               (EPREFIX + '/etc/revdep-rebuild', ['data/revdep-rebuild/99revdep-rebuild']),
-               (EPREFIX + '/etc/eclean', glob('data/eclean/*')),
-               (EPREFIX + '/usr/share/man/man1', glob('man/*'))
+               (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/env.d'), ['data/99gentoolkit-env']),
+               (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/revdep-rebuild'), ['data/revdep-rebuild/99revdep-rebuild']),
+               (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/eclean'), glob('data/eclean/*')),
+               (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'usr/share/man/man1'), glob('man/*')),
        ),
        cmdclass={
                'test': load_test(),