summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-09-04 10:18:16 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-09-04 10:18:16 -0400
commit071177c7ab5f70020f52fb46a910f3a6ed8c4426 (patch)
tree68112e667fb002b2a5e77d5d4daec591a793f3d6
parentf8549b939ee54085e9d810f9fdd4364611432100 (diff)
downloadpython-coveragepy-git-071177c7ab5f70020f52fb46a910f3a6ed8c4426.tar.gz
A custom setup.py command to fix tarfile permissions. Fixes #54.
-rw-r--r--Makefile4
-rw-r--r--allkits.cmd4
-rw-r--r--checkeol.py1
-rw-r--r--distcmd/__init__.py1
-rw-r--r--distcmd/fixtar.py63
5 files changed, 68 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 56d4f9d3..bae4192a 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ clean:
-rm -f setuptools-*.egg distribute-*.egg distribute-*.tar.gz
-rm -rf doc/_build/*
-LINTABLE = coverage setup.py test
+LINTABLE = coverage setup.py test distcmd
lint:
-python -x /Python25/Scripts/pylint.bat --rcfile=.pylintrc $(LINTABLE)
@@ -46,7 +46,7 @@ $(TEST_EGG): test/eggsrc/setup.py test/eggsrc/egg1/egg1.py
cd test/eggsrc; python setup.py -q bdist_egg
kit:
- python setup.py sdist --formats=gztar
+ python setup.py --command-packages=distcmd sdist --keep-temp --formats=gztar fixtar
python setup.py bdist_wininst
pypi:
diff --git a/allkits.cmd b/allkits.cmd
index e27098f4..ac1856a3 100644
--- a/allkits.cmd
+++ b/allkits.cmd
@@ -6,6 +6,4 @@ for %%v in (23 24 25 26 27 31 32) do (
)
call \ned\bin\switchpy c:\vpy\coverage\26
-set TAR_OPTIONS=--group=100
-python setup.py sdist --formats=gztar %1
-set TAR_OPTIONS=
+python setup.py --command-packages=distcmd sdist --keep-temp --formats=gztar fixtar %1
diff --git a/checkeol.py b/checkeol.py
index 5d18d9e3..66c1ba42 100644
--- a/checkeol.py
+++ b/checkeol.py
@@ -33,5 +33,6 @@ check_files("coverage/htmlfiles", ["*.html", "*.css", "*.js"])
check_files("test", ["*.py"])
check_files("test", ["*,cover"], trail_white=False)
check_file("setup.py")
+check_files("distcmd", ["*.py"])
check_files("doc", ["*.rst"])
check_files(".", ["*.txt"])
diff --git a/distcmd/__init__.py b/distcmd/__init__.py
new file mode 100644
index 00000000..9444cab7
--- /dev/null
+++ b/distcmd/__init__.py
@@ -0,0 +1 @@
+"""New custom commands for setup.py"""
diff --git a/distcmd/fixtar.py b/distcmd/fixtar.py
new file mode 100644
index 00000000..1a226cb9
--- /dev/null
+++ b/distcmd/fixtar.py
@@ -0,0 +1,63 @@
+"""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
+ assert n.count("/") == 1 and n.endswith("/")
+ the_dir = n[:-1]
+ 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)