Commits

Ned Batchelder committed 745797f

Haven't even run it yet, just getting started.

  • Participants

Comments (0)

Files changed (4)

+syntax: glob
+
+# Files that can appear anywhere in the tree.
+*.pyc
+*.pyo
+*.bak
+
+# Stuff in the root.
+build
+*.egg-info
+dist
+MANIFEST
+# setup.py for the fixtar setup.py command
+
+"""fixtar - A setup.py command to correct permissions in tar kits
+
+Say more here.
+"""
+
+import sys
+
+from setuptools import setup, find_packages
+
+__version__ = "1.0"
+
+trove_classifiers=[
+    "Framework :: Setuptools Plugin",
+    "Development Status :: 5 - Production/Stable",
+    "License :: OSI Approved :: MIT License",
+    "License :: DFSG approved",
+    "Intended Audience :: Developers",
+    "Operating System :: OS Independent",
+    "Natural Language :: English",
+    "Programming Language :: Python",
+    "Topic :: Utilities",
+    "Topic :: Software Development :: Libraries",
+    ]
+
+doclines = __doc__.split('\n')
+
+PKG = 'setuptools_fixtar'
+
+setup(
+    name = 'setuptools_fixtar',
+    version = __version__,
+    description = doclines[0],
+    long_description = '\n'.join(doclines[2:]),
+    author = 'Ned Batchelder',
+    author_email = 'ned@nedbatchelder.com',
+    url = 'http://nedbatchelder.com/blog/201009/making_good_tar_files_on_windows.html',
+    license = 'MIT',
+    packages = find_packages(),
+    classifiers = trove_classifiers,
+    keywords = 'distutils setuptools setup',
+    entry_points = {
+        'distutils.commands': [ 'fixtar = setuptools_fixtar.fixtar.py:FixtarCommand', ],
+        },
+    )

setuptools_fixtar/__init__.py

Empty file added.

setuptools_fixtar/fixtar.py

+"""Add a 'fixtar' command to setup.py.
+
+This lets us have proper permissions in tar files made on Windows.
+
+"""
+from distutils.core import Command
+import shutil, tarfile
+
+class fixtar(Command):
+    """A new setup.py command to fix tar file permissions."""
+
+    description = "Re-pack the tar file to have correct permissions."
+
+    user_options = []
+
+    def initialize_options(self):
+        """Required by Command, even though I have nothing to add."""
+        pass
+
+    def finalize_options(self):
+        """Required by Command, even though I have nothing to add."""
+        pass
+
+    def run(self):
+        """The body of the command."""
+        for _, _, filename in self.distribution.dist_files:
+            if filename.endswith(".tar.gz"):
+                self.repack_tar(filename, "temp.tar.gz")
+                shutil.move("temp.tar.gz", filename)
+
+    def repack_tar(self, infilename, outfilename):
+        """Re-pack `infilename` as `outfilename`.
+
+        Permissions and owners are set the way we like them.
+        Also deletes the source directory, due to unfortunate setup.py
+        mechanics.
+
+        """
+        itar = tarfile.open(infilename, "r:gz")
+        otar = tarfile.open(outfilename, "w:gz")
+        the_dir = None
+        for itarinfo in itar:
+            otarinfo = otar.gettarinfo(itarinfo.name)
+            if the_dir is None:
+                n = itarinfo.name.rstrip("/")
+                assert "/" not in n
+                the_dir = n
+            if itarinfo.isfile():
+                otarinfo.mode = 0644
+            else:
+                otarinfo.mode = 0755
+            otarinfo.uid = 100
+            otarinfo.gid = 100
+            otarinfo.uname = "ned"
+            otarinfo.gname = "coverage"
+            otar.addfile(otarinfo, itar.extractfile(itarinfo))
+        itar.close()
+        otar.close()
+
+        # To make this work, sdist has to be run with the --keep-temp option.
+        # But the clean command doesn't clean up the temp directory.
+        # Delete it here.
+        shutil.rmtree(the_dir)