fix lib_files generation
authorBrian Dolbec <dolsen@gentoo.org>
Fri, 7 Jun 2013 14:42:27 +0000 (07:42 -0700)
committerW. Trevor King <wking@tremily.us>
Tue, 11 Jun 2013 13:50:17 +0000 (09:50 -0400)
Move data_file generation out of setup().
Rework file() to yield the files in the correct form.
wking: Use dirpath directly.
wking: Remove unneeded list() use.
wking: Use relative paths.

setup.py

index fe05d067efd53a8b8cd59ea3b05d128f99cafe8a..f3aa7b43895cdc817110efd97f92f8fd84294b8a 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,7 @@ package_name = 'catalyst'
 tag = '{0}-{1}'.format(package_name, __version__)
 
 
-def files(root):
+def files(root, target):
        """Iterate through all the file paths under `root`
 
        Distutils wants all paths to be written in the Unix convention
@@ -42,12 +42,29 @@ def files(root):
 
        [1]: http://docs.python.org/2/distutils/setupscript.html#writing-the-setup-script
        """
+       def ensure_slash(path):
+               if _os.path.sep != '/':
+                       path.replace(_os.path.sep, '/')
+               return path
+       filedict = {}
        for dirpath, dirnames, filenames in _os.walk(root):
-               for filename in filenames:
-                       path = _os.path.join(dirpath, filename)
-                       if _os.path.sep != '/':
-                               path = path.replace(_os.path.sep, '/')
-                       yield path
+               key = _os.path.join(target, dirpath)
+               filepaths = []
+               for _file in filenames:
+                       _filepath = ensure_slash(_os.path.join(dirpath, _file))
+                       filepaths.append(_filepath)
+               filedict[key] = filepaths
+       for key in sorted(filedict):
+               if len(filedict[key]):
+                       yield (key, filedict[key])
+
+
+_data_files = [('/etc/catalyst', ['etc/catalyst.conf','etc/catalystrc']),
+       ('/usr/share/man/man1', ['files/catalyst.1']),
+       ('/usr/share/man/man5', ['files/catalyst-config.5', 'files/catalyst-spec.5'])
+       ]
+_data_files.extend(files('livecd', 'lib/catalyst/'))
+_data_files.extend(files('targets', 'lib/catalyst/'))
 
 
 class set_version(Command):
@@ -105,16 +122,7 @@ _setup(
                '{0}.base'.format(package_name),
                '{0}.targets'.format(package_name),
                ],
-       data_files=[
-               ('/etc/catalyst', [
-                       'etc/catalyst.conf',
-                       'etc/catalystrc',
-                       ]),
-               ('lib/catalyst/', list(_itertools.chain(
-                       files('livecd'),
-                       files('targets'),
-                       ))),
-               ],
+       data_files=_data_files,
        provides=[package_name],
        cmdclass = {
                'set_version': set_version