From ad95826c33ea378db2807a268363ccfbf0ea8273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarek=20Ziad=C3=A9?= Date: Thu, 9 Apr 2009 21:36:44 +0000 Subject: [PATCH] Fixed #5731: Distutils bdist_wininst no longer worked on non-Windows platforms --- Lib/distutils/command/bdist_wininst.py | 11 ++++++--- Lib/distutils/tests/test_bdist_wininst.py | 29 +++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Lib/distutils/tests/test_bdist_wininst.py diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py index ad6eee8ea82..8a6eca59d83 100644 --- a/Lib/distutils/command/bdist_wininst.py +++ b/Lib/distutils/command/bdist_wininst.py @@ -342,10 +342,15 @@ class bdist_wininst (Command): directory = os.path.dirname(__file__) # we must use a wininst-x.y.exe built with the same C compiler # used for python. XXX What about mingw, borland, and so on? - if self.plat_name == 'win32': - sfix = '' + + # if plat_name starts with "win" but is not "win32" + # we want to strip "win" and leave the rest (e.g. -amd64) + # for all other cases, we don't want any suffix + if self.plat_name != 'win32' and self.plat_name[:3] == 'win': + sfix = self.plat_name[3:] else: - sfix = self.plat_name[3:] # strip 'win' - leaves eg '-amd64' + sfix = '' + filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) return open(filename, "rb").read() # class bdist_wininst diff --git a/Lib/distutils/tests/test_bdist_wininst.py b/Lib/distutils/tests/test_bdist_wininst.py new file mode 100644 index 00000000000..d851d6c7994 --- /dev/null +++ b/Lib/distutils/tests/test_bdist_wininst.py @@ -0,0 +1,29 @@ +"""Tests for distutils.command.bdist_wininst.""" +import unittest + +from distutils.command.bdist_wininst import bdist_wininst +from distutils.tests import support + +class BuildWinInstTestCase(support.TempdirManager, + unittest.TestCase): + + def test_get_exe_bytes(self): + + # issue5731: command was broken on non-windows platforms + # this test makes sure it works now for every platform + # let's create a command + pkg_pth, dist = self.create_dist() + cmd = bdist_wininst(dist) + cmd.ensure_finalized() + + # let's run the code that finds the right wininst*.exe file + # and make sure it finds it and returns its content + # no matter what platform we have + exe_file = cmd.get_exe_bytes() + self.assert_(len(exe_file) > 10) + +def test_suite(): + return unittest.makeSuite(BuildWinInstTestCase) + +if __name__ == '__main__': + test_support.run_unittest(test_suite()) diff --git a/Misc/NEWS b/Misc/NEWS index 5fcfab942a2..9acbea2f138 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -216,6 +216,9 @@ Core and Builtins Library ------- +- Issue #5731: Distutils bdist_wininst no longer worked on non-Windows + platforms. Initial patch by Paul Moore. + - Issue #2254: Fix CGIHTTPServer information disclosure. Relative paths are now collapsed within the url properly before looking in cgi_directories.