diff options
| author | ?ric Araujo <merwok@netwok.org> | 2011-09-18 20:20:13 +0200 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2011-09-18 20:20:13 +0200 |
| commit | 506cfea8bbd41e865bc36a836bdbc05aae8d74bb (patch) | |
| tree | 3bae418473347324060850aab8d34e162b33ecc9 /distutils2/command | |
| parent | 8c928044705a70bb845cb45f76edb6eb71393866 (diff) | |
| download | disutils2-506cfea8bbd41e865bc36a836bdbc05aae8d74bb.tar.gz | |
Fix the backport fixes.
Backports:
- sysconfig is now always imported from our backports
- when hashlib is not found, our backport is used instead of the md5
module (debatable; we could just drop hashlib)
Version-dependent features:
- PEP 370 features are only enabled for 2.6+
- the check for sys.dont_write_bytecode was fixed to use getattr
with a default value instead of hasattr
Idioms/syntax:
- octal literals lost their extra 0
- misused try/except blocks have been changed back to try/finally
(it?s legal in 2.4 too, it?s only try/except/finally that isn?t)
- exception catching uses the regular 2.x idiom instead of sys.exc_info
- file objects are closed within finally blocks (this causes much
whitespace changes but actually makes diff with packaging easier)
Renamed modules:
- some missed renamings (_thread, Queue, isAlive, urllib.urlsplit, etc.)
were fixed
Other:
- a few false positive replacements of ?packaging? by ?distutils2? in
comments or docstrings were reverted
- util.is_packaging regained its name
- assorted whitespace/comment/import changes to match packaging
Diffstat (limited to 'distutils2/command')
| -rw-r--r-- | distutils2/command/__init__.py | 5 | ||||
| -rw-r--r-- | distutils2/command/bdist.py | 12 | ||||
| -rw-r--r-- | distutils2/command/bdist_dumb.py | 15 | ||||
| -rw-r--r-- | distutils2/command/bdist_msi.py | 32 | ||||
| -rw-r--r-- | distutils2/command/bdist_wininst.py | 85 | ||||
| -rw-r--r-- | distutils2/command/build_clib.py | 3 | ||||
| -rw-r--r-- | distutils2/command/build_ext.py | 30 | ||||
| -rw-r--r-- | distutils2/command/build_py.py | 4 | ||||
| -rw-r--r-- | distutils2/command/build_scripts.py | 10 | ||||
| -rw-r--r-- | distutils2/command/cmd.py | 7 | ||||
| -rw-r--r-- | distutils2/command/config.py | 43 | ||||
| -rw-r--r-- | distutils2/command/install_data.py | 5 | ||||
| -rw-r--r-- | distutils2/command/install_dist.py | 12 | ||||
| -rw-r--r-- | distutils2/command/install_distinfo.py | 4 | ||||
| -rw-r--r-- | distutils2/command/install_lib.py | 4 | ||||
| -rw-r--r-- | distutils2/command/install_scripts.py | 2 | ||||
| -rw-r--r-- | distutils2/command/register.py | 12 | ||||
| -rw-r--r-- | distutils2/command/sdist.py | 8 | ||||
| -rw-r--r-- | distutils2/command/upload.py | 23 | ||||
| -rw-r--r-- | distutils2/command/upload_docs.py | 27 |
20 files changed, 182 insertions, 161 deletions
diff --git a/distutils2/command/__init__.py b/distutils2/command/__init__.py index c80dde1..2babdda 100644 --- a/distutils2/command/__init__.py +++ b/distutils2/command/__init__.py @@ -28,8 +28,11 @@ _COMMANDS = { 'bdist_wininst': 'distutils2.command.bdist_wininst.bdist_wininst', 'register': 'distutils2.command.register.register', 'upload': 'distutils2.command.upload.upload', - 'upload_docs': 'distutils2.command.upload_docs.upload_docs'} + 'upload_docs': 'distutils2.command.upload_docs.upload_docs', +} +# XXX use OrderedDict to preserve the grouping (build-related, install-related, +# distribution-related) STANDARD_COMMANDS = set(_COMMANDS) diff --git a/distutils2/command/bdist.py b/distutils2/command/bdist.py index 1d6adea..d45842a 100644 --- a/distutils2/command/bdist.py +++ b/distutils2/command/bdist.py @@ -58,7 +58,7 @@ class bdist(Command): # This is of course very simplistic. The various UNIX family operating # systems have their specific formats, but they are out of scope for us; # bdist_dumb is, well, dumb; it's more a building block for other - # distutils2 tools than a real end-user binary format. + # packaging tools than a real end-user binary format. default_format = {'posix': 'gztar', 'nt': 'zip', 'os2': 'zip'} @@ -75,9 +75,8 @@ class bdist(Command): 'wininst': ('bdist_wininst', "Windows executable installer"), 'zip': ('bdist_dumb', "ZIP file"), - 'msi': ('bdist_msi', "Microsoft Installer") - } - + 'msi': ('bdist_msi', "Microsoft Installer"), + } def initialize_options(self): self.bdist_base = None @@ -109,8 +108,9 @@ class bdist(Command): try: self.formats = [self.default_format[os.name]] except KeyError: - raise PackagingPlatformError("don't know how to create built distributions " + \ - "on platform %s" % os.name) + raise PackagingPlatformError( + "don't know how to create built distributions " + "on platform %s" % os.name) if self.dist_dir is None: self.dist_dir = "dist" diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py index 1a6da38..b15e743 100644 --- a/distutils2/command/bdist_dumb.py +++ b/distutils2/command/bdist_dumb.py @@ -7,11 +7,12 @@ sys.prefix or sys.exec_prefix. import os from shutil import rmtree -from sysconfig import get_python_version from distutils2.util import get_platform from distutils2.command.cmd import Command from distutils2.errors import PackagingPlatformError from distutils2 import logger +from distutils2._backport.sysconfig import get_python_version + class bdist_dumb(Command): @@ -44,10 +45,9 @@ class bdist_dumb(Command): boolean_options = ['keep-temp', 'skip-build', 'relative'] - default_format = { 'posix': 'gztar', - 'nt': 'zip', - 'os2': 'zip' } - + default_format = {'posix': 'gztar', + 'nt': 'zip', + 'os2': 'zip'} def initialize_options(self): self.bdist_dir = None @@ -69,8 +69,9 @@ class bdist_dumb(Command): try: self.format = self.default_format[os.name] except KeyError: - raise PackagingPlatformError(("don't know how to create dumb built distributions " + - "on platform %s") % os.name) + raise PackagingPlatformError( + "don't know how to create dumb built distributions " + "on platform %s" % os.name) self.set_undefined_options('bdist', 'dist_dir', 'plat_name') diff --git a/distutils2/command/bdist_msi.py b/distutils2/command/bdist_msi.py index aa09644..ad96911 100644 --- a/distutils2/command/bdist_msi.py +++ b/distutils2/command/bdist_msi.py @@ -8,7 +8,7 @@ import os import msilib -from sysconfig import get_python_version +from distutils2._backport.sysconfig import get_python_version from shutil import rmtree from distutils2.command.cmd import Command from distutils2.version import NormalizedVersion @@ -391,19 +391,23 @@ class bdist_msi(Command): if self.pre_install_script: scriptfn = os.path.join(self.bdist_dir, "preinstall.bat") f = open(scriptfn, "w") - # The batch file will be executed with [PYTHON], so that %1 - # is the path to the Python interpreter; %0 will be the path - # of the batch file. - # rem =""" - # %1 %0 - # exit - # """ - # <actual script> - f.write('rem ="""\n%1 %0\nexit\n"""\n') - fp = open(self.pre_install_script) - f.write(fp.read()) - fp.close() - f.close() + try: + # The batch file will be executed with [PYTHON], so that %1 + # is the path to the Python interpreter; %0 will be the path + # of the batch file. + # rem =""" + # %1 %0 + # exit + # """ + # <actual script> + f.write('rem ="""\n%1 %0\nexit\n"""\n') + fp = open(self.pre_install_script) + try: + f.write(fp.read()) + finally: + fp.close() + finally: + f.close() add_data(self.db, "Binary", [("PreInstall", msilib.Binary(scriptfn)), ]) diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py index ef32977..81a8391 100644 --- a/distutils2/command/bdist_wininst.py +++ b/distutils2/command/bdist_wininst.py @@ -6,11 +6,11 @@ import sys import os from shutil import rmtree -from sysconfig import get_python_version from distutils2.command.cmd import Command from distutils2.errors import PackagingOptionError, PackagingPlatformError from distutils2 import logger from distutils2.util import get_platform +from distutils2._backport.sysconfig import get_python_version class bdist_wininst(Command): @@ -246,49 +246,56 @@ class bdist_wininst(Command): if bitmap: fp = open(bitmap, "rb") - bitmapdata = fp.read() - fp.close() + try: + bitmapdata = fp.read() + finally: + fp.close() bitmaplen = len(bitmapdata) else: bitmaplen = 0 file = open(installer_name, "wb") - file.write(self.get_exe_bytes()) - if bitmap: - file.write(bitmapdata) + try: + file.write(self.get_exe_bytes()) + if bitmap: + file.write(bitmapdata) - # Convert cfgdata from unicode to ascii, mbcs encoded - if isinstance(cfgdata, unicode): - cfgdata = cfgdata.encode("mbcs") + # Convert cfgdata from unicode to ascii, mbcs encoded + if isinstance(cfgdata, unicode): + cfgdata = cfgdata.encode("mbcs") - # Append the pre-install script - cfgdata = cfgdata + "\0" - if self.pre_install_script: - fp = open(self.pre_install_script) - script_data = fp.read() - fp.close() - cfgdata = cfgdata + script_data + "\n\0" - else: - # empty pre-install script + # Append the pre-install script cfgdata = cfgdata + "\0" - file.write(cfgdata) - - # The 'magic number' 0x1234567B is used to make sure that the - # binary layout of 'cfgdata' is what the wininst.exe binary - # expects. If the layout changes, increment that number, make - # the corresponding changes to the wininst.exe sources, and - # recompile them. - header = struct.pack("<iii", - 0x1234567B, # tag - len(cfgdata), # length - bitmaplen, # number of bytes in bitmap - ) - file.write(header) - file.close() - - fp = open(arcname, "rb") - file.write(fp.read()) - fp.close() + if self.pre_install_script: + fp = open(self.pre_install_script) + try: + script_data = fp.read() + finally: + fp.close() + cfgdata = cfgdata + script_data + "\n\0" + else: + # empty pre-install script + cfgdata = cfgdata + "\0" + file.write(cfgdata) + + # The 'magic number' 0x1234567B is used to make sure that the + # binary layout of 'cfgdata' is what the wininst.exe binary + # expects. If the layout changes, increment that number, make + # the corresponding changes to the wininst.exe sources, and + # recompile them. + header = struct.pack("<iii", + 0x1234567B, # tag + len(cfgdata), # length + bitmaplen, # number of bytes in bitmap + ) + file.write(header) + fp = open(arcname, "rb") + try: + file.write(fp.read()) + finally: + fp.close() + finally: + file.close() def get_installer_filename(self, fullname): # Factored out to allow overriding in subclasses @@ -344,6 +351,8 @@ class bdist_wininst(Command): filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) fp = open(filename, "rb") - content = fp.read() - fp.close() + try: + content = fp.read() + finally: + fp.close() return content diff --git a/distutils2/command/build_clib.py b/distutils2/command/build_clib.py index 677a2ee..0a8807f 100644 --- a/distutils2/command/build_clib.py +++ b/distutils2/command/build_clib.py @@ -16,7 +16,7 @@ distribution and needed by extension modules. import os from distutils2.command.cmd import Command from distutils2.errors import PackagingSetupError -from distutils2.compiler import customize_compiler +from distutils2.compiler import customize_compiler, new_compiler from distutils2 import logger @@ -93,7 +93,6 @@ class build_clib(Command): return # Yech -- this is cut 'n pasted from build_ext.py! - from distutils2.compiler import new_compiler self.compiler = new_compiler(compiler=self.compiler, dry_run=self.dry_run, force=self.force) diff --git a/distutils2/command/build_ext.py b/distutils2/command/build_ext.py index ad2077b..8b61533 100644 --- a/distutils2/command/build_ext.py +++ b/distutils2/command/build_ext.py @@ -1,9 +1,5 @@ """Build extension modules.""" -# FIXME Is this module limited to C extensions or do C++ extensions work too? -# The docstring of this module said that C++ was not supported, but other -# comments contradict that. - import os import re import sys @@ -20,7 +16,10 @@ from distutils2.compiler.extension import Extension from distutils2 import logger import site -HAS_USER_SITE = True +if sys.version_info[:2] >= (2, 6): + HAS_USER_SITE = True +else: + HAS_USER_SITE = False if os.name == 'nt': from distutils2.compiler.msvccompiler import get_build_version @@ -363,12 +362,11 @@ class build_ext(Command): for ext in self.extensions: try: self.build_extension(ext) - except (CCompilerError, PackagingError, CompileError): + except (CCompilerError, PackagingError, CompileError), e: if not ext.optional: raise logger.warning('%s: building extension %r failed: %s', - self.get_command_name(), ext.name, - sys.exc_info()[1]) + self.get_command_name(), ext.name, e) def build_extension(self, ext): sources = ext.sources @@ -608,8 +606,7 @@ class build_ext(Command): template = "python%d%d" if self.debug: template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] @@ -623,22 +620,19 @@ class build_ext(Command): # not at this time - AIM Apr01 #if self.debug: # template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "cygwin": template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "atheos": template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # Get SHLIBS from Makefile extra = [] for lib in sysconfig.get_config_var('SHLIBS').split(): @@ -656,8 +650,8 @@ class build_ext(Command): else: if sysconfig.get_config_var('Py_ENABLE_SHARED'): - pythonlib = 'python%s.%s' % ( - sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff) + template = 'python%d.%d' + sys.abiflags + pythonlib = template % sys.version_info[:2] return ext.libraries + [pythonlib] else: return ext.libraries diff --git a/distutils2/command/build_py.py b/distutils2/command/build_py.py index f9b6787..fec81a9 100644 --- a/distutils2/command/build_py.py +++ b/distutils2/command/build_py.py @@ -388,12 +388,12 @@ class build_py(Command, Mixin2to3): self.build_module(module, module_file, package) def byte_compile(self, files): - if hasattr(sys, 'dont_write_bytecode') and sys.dont_write_bytecode: + if getattr(sys, 'dont_write_bytecode', False): logger.warning('%s: byte-compiling is disabled, skipping.', self.get_command_name()) return - from distutils2.util import byte_compile + from distutils2.util import byte_compile # FIXME use compileall prefix = self.build_lib if prefix[-1] != os.sep: prefix = prefix + os.sep diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py index a61f382..8a48e07 100644 --- a/distutils2/command/build_scripts.py +++ b/distutils2/command/build_scripts.py @@ -130,9 +130,11 @@ class build_scripts(Command, Mixin2to3): "from the script encoding (%s)" % ( shebang, encoding)) outf = open(outfile, "wb") - outf.write(shebang) - outf.writelines(f.readlines()) - outf.close() + try: + outf.write(shebang) + outf.writelines(f.readlines()) + finally: + outf.close() if f: f.close() else: @@ -146,7 +148,7 @@ class build_scripts(Command, Mixin2to3): logger.info("changing mode of %s", file) else: oldmode = os.stat(file).st_mode & 07777 - newmode = (oldmode | 00555) & 07777 + newmode = (oldmode | 0555) & 07777 if newmode != oldmode: logger.info("changing mode of %s from %o to %o", file, oldmode, newmode) diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py index 8fe2e7b..9076906 100644 --- a/distutils2/command/cmd.py +++ b/distutils2/command/cmd.py @@ -5,6 +5,7 @@ import re from shutil import copyfile, move from distutils2 import util from distutils2 import logger +from distutils2.util import make_archive from distutils2.errors import PackagingOptionError @@ -403,9 +404,9 @@ class Command(object): def make_archive(self, base_name, format, root_dir=None, base_dir=None, owner=None, group=None): - return util.make_archive(base_name, format, root_dir, - base_dir, dry_run=self.dry_run, - owner=owner, group=group) + return make_archive(base_name, format, root_dir, + base_dir, dry_run=self.dry_run, + owner=owner, group=group) def make_file(self, infiles, outfile, func, args, exec_msg=None, skip_msg=None, level=1): diff --git a/distutils2/command/config.py b/distutils2/command/config.py index 3386dd4..e3af2e5 100644 --- a/distutils2/command/config.py +++ b/distutils2/command/config.py @@ -111,14 +111,16 @@ class config(Command): def _gen_temp_sourcefile(self, body, headers, lang): filename = "_configtest" + LANG_EXT[lang] file = open(filename, "w") - if headers: - for header in headers: - file.write("#include <%s>\n" % header) - file.write("\n") - file.write(body) - if body[-1] != "\n": - file.write("\n") - file.close() + try: + if headers: + for header in headers: + file.write("#include <%s>\n" % header) + file.write("\n") + file.write(body) + if body[-1] != "\n": + file.write("\n") + finally: + file.close() return filename def _preprocess(self, body, headers, include_dirs, lang): @@ -208,14 +210,17 @@ class config(Command): pattern = re.compile(pattern) file = open(out) - match = False - while True: - line = file.readline() - if line == '': - break - if pattern.search(line): - match = True - break + try: + match = False + while True: + line = file.readline() + if line == '': + break + if pattern.search(line): + match = True + break + finally: + file.close() self._clean() return match @@ -347,5 +352,7 @@ def dump_file(filename, head=None): else: logger.info(head) file = open(filename) - logger.info(file.read()) - file.close() + try: + logger.info(file.read()) + finally: + file.close() diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 78cb6e2..c1fd462 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -2,7 +2,7 @@ # Contributed by Bastian Kleineidam -import os, sys +import os from shutil import Error from distutils2 import logger from distutils2.util import convert_path @@ -48,8 +48,7 @@ class install_data(Command): self.mkpath(dir_dest) try: out = self.copy_file(_file[0], dir_dest)[0] - except Error: - e = sys.exc_info()[1] + except Error, e: logger.warning('%s: %s', self.get_command_name(), e) out = destination diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py index 5c591b1..89ea15f 100644 --- a/distutils2/command/install_dist.py +++ b/distutils2/command/install_dist.py @@ -295,9 +295,9 @@ class install_dist(Command): self.dump_dirs("post-expand_dirs()") - # Create directories in the home dir: + # Create directories under USERBASE if HAS_USER_SITE and self.user: - self.create_home_path() + self.create_user_dirs() # Pick the actual directory to install all modules to: either # install_purelib or install_platlib, depending on whether this @@ -494,14 +494,12 @@ class install_dist(Command): attr = "install_" + name setattr(self, attr, change_root(self.root, getattr(self, attr))) - def create_home_path(self): - """Create directories under ~.""" - if HAS_USER_SITE and not self.user: - return + def create_user_dirs(self): + """Create directories under USERBASE as needed.""" home = convert_path(os.path.expanduser("~")) for name, path in self.config_vars.items(): if path.startswith(home) and not os.path.isdir(path): - os.makedirs(path, 00700) + os.makedirs(path, 0700) # -- Command execution methods ------------------------------------- diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index 8beabd4..50382a3 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -8,7 +8,7 @@ import os import re try: import hashlib -except ImportError: #<2.5 +except ImportError: from distutils2._backport import hashlib from distutils2.command.cmd import Command @@ -32,7 +32,7 @@ class install_distinfo(Command): ('no-record', None, "do not generate a RECORD file"), ('no-resources', None, - "do not generate a RESSOURCES list installed file") + "do not generate a RESSOURCES list installed file"), ] boolean_options = ['requested', 'no-record', 'no-resources'] diff --git a/distutils2/command/install_lib.py b/distutils2/command/install_lib.py index ef02c14..028e1aa 100644 --- a/distutils2/command/install_lib.py +++ b/distutils2/command/install_lib.py @@ -114,7 +114,7 @@ class install_lib(Command): return outfiles def byte_compile(self, files): - if hasattr(sys, 'dont_write_bytecode'): + if getattr(sys, 'dont_write_bytecode', False): # XXX do we want this? because a Python runs without bytecode # doesn't mean that the *dists should not contain bytecode #--or does it? @@ -122,7 +122,7 @@ class install_lib(Command): self.get_command_name()) return - from distutils2.util import byte_compile + from distutils2.util import byte_compile # FIXME use compileall # Get the "--root" directory supplied to the "install_dist" command, # and use it as a prefix to strip off the purported filename diff --git a/distutils2/command/install_scripts.py b/distutils2/command/install_scripts.py index e8cb332..3bed33c 100644 --- a/distutils2/command/install_scripts.py +++ b/distutils2/command/install_scripts.py @@ -48,7 +48,7 @@ class install_scripts(Command): if self.dry_run: logger.info("changing mode of %s", file) else: - mode = (os.stat(file).st_mode | 00555) & 07777 + mode = (os.stat(file).st_mode | 0555) & 07777 logger.info("changing mode of %s to %o", file, mode) os.chmod(file, mode) diff --git a/distutils2/command/register.py b/distutils2/command/register.py index 6f28585..de69a2f 100644 --- a/distutils2/command/register.py +++ b/distutils2/command/register.py @@ -2,14 +2,13 @@ # Contributed by Richard Jones -import sys import getpass -import urlparse import urllib2 +import urlparse from distutils2 import logger from distutils2.util import (read_pypirc, generate_pypirc, DEFAULT_REPOSITORY, - DEFAULT_REALM, get_pypirc_path, encode_multipart) + DEFAULT_REALM, get_pypirc_path, encode_multipart) from distutils2.command.cmd import Command class register(Command): @@ -246,13 +245,12 @@ Your selection [default 1]: ''') data = '' try: result = opener.open(req) - except urllib2.HTTPError: - e = sys.exc_info()[1] + except urllib2.HTTPError, e: if self.show_response: data = e.fp.read() result = e.code, e.msg - except urllib2.URLError: - result = 500, str(sys.exc_info()[1]) + except urllib2.URLError, e: + result = 500, str(e) else: if self.show_response: data = result.read() diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py index d03a448..b124f73 100644 --- a/distutils2/command/sdist.py +++ b/distutils2/command/sdist.py @@ -9,7 +9,7 @@ from shutil import rmtree from distutils2 import logger from distutils2.util import resolve_name, get_archive_formats from distutils2.errors import (PackagingPlatformError, PackagingOptionError, - PackagingModuleError, PackagingFileError) + PackagingModuleError, PackagingFileError) from distutils2.command import get_command_names from distutils2.command.cmd import Command from distutils2.manifest import Manifest @@ -143,8 +143,8 @@ class sdist(Command): continue try: builder = resolve_name(builder) - except ImportError: - raise PackagingModuleError(sys.exc_info()[1]) + except ImportError, e: + raise PackagingModuleError(e) builders.append(builder) @@ -337,7 +337,7 @@ class sdist(Command): """ return self.archive_files - def create_tree(self, base_dir, files, mode=00777, verbose=1, + def create_tree(self, base_dir, files, mode=0777, verbose=1, dry_run=False): need_dir = set() for file in files: diff --git a/distutils2/command/upload.py b/distutils2/command/upload.py index 6c9d69a..0bdac4a 100644 --- a/distutils2/command/upload.py +++ b/distutils2/command/upload.py @@ -1,6 +1,6 @@ """Upload a distribution to a project index.""" -import os, sys +import os import socket import logging import platform @@ -16,7 +16,7 @@ from urllib2 import urlopen, Request from distutils2 import logger from distutils2.errors import PackagingOptionError from distutils2.util import (spawn, read_pypirc, DEFAULT_REPOSITORY, - DEFAULT_REALM, encode_multipart) + DEFAULT_REALM, encode_multipart) from distutils2.command.cmd import Command @@ -105,8 +105,10 @@ class upload(Command): # Fill in the data - send all the metadata in case we need to # register a new release f = open(filename, 'rb') - content = f.read() - f.close() + try: + content = f.read() + finally: + f.close() data = self.distribution.metadata.todict() @@ -123,8 +125,10 @@ class upload(Command): if self.sign: fp = open(filename + '.asc') - sig = fp.read() - fp.close() + try: + sig = fp.read() + finally: + fp.close() data['gpg_signature'] = [ (os.path.basename(filename) + ".asc", sig)] @@ -156,11 +160,10 @@ class upload(Command): result = urlopen(request) status = result.code reason = result.msg - except socket.error: - logger.error(sys.exc_info()[1]) + except socket.error, e: + logger.error(e) return - except HTTPError: - e = sys.exc_info()[1] + except HTTPError, e: status = e.code reason = e.msg diff --git a/distutils2/command/upload_docs.py b/distutils2/command/upload_docs.py index 7f3523f..2f813d3 100644 --- a/distutils2/command/upload_docs.py +++ b/distutils2/command/upload_docs.py @@ -1,6 +1,6 @@ """Upload HTML documentation to a project index.""" -import os, sys +import os import base64 import socket import zipfile @@ -11,7 +11,7 @@ from StringIO import StringIO from distutils2 import logger from distutils2.util import (read_pypirc, DEFAULT_REPOSITORY, DEFAULT_REALM, - encode_multipart) + encode_multipart) from distutils2.errors import PackagingFileError from distutils2.command.cmd import Command @@ -20,13 +20,15 @@ def zip_dir(directory): """Compresses recursively contents of directory into a BytesIO object""" destination = StringIO() zip_file = zipfile.ZipFile(destination, "w") - for root, dirs, files in os.walk(directory): - for name in files: - full = os.path.join(root, name) - relative = root[len(directory):].lstrip(os.path.sep) - dest = os.path.join(relative, name) - zip_file.write(full, dest) - zip_file.close() + try: + for root, dirs, files in os.walk(directory): + for name in files: + full = os.path.join(root, name) + relative = root[len(directory):].lstrip(os.path.sep) + dest = os.path.join(relative, name) + zip_file.write(full, dest) + finally: + zip_file.close() return destination @@ -88,7 +90,8 @@ class upload_docs(Command): content_type, body = encode_multipart(fields, files) credentials = self.username + ':' + self.password - auth = "Basic " + base64.encodebytes(credentials.encode()).strip() + # FIXME should use explicit encoding + auth = "Basic " + base64.encodestring(credentials.encode()).strip() logger.info("Submitting documentation to %s", self.repository) @@ -110,8 +113,8 @@ class upload_docs(Command): conn.endheaders() conn.send(body) - except socket.error: - logger.error(sys.exc_info()[1]) + except socket.error, e: + logger.error(e) return r = conn.getresponse() |
