diff options
Diffstat (limited to 'distutils2/command/install_distinfo.py')
| -rw-r--r-- | distutils2/command/install_distinfo.py | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index fa74448..81de925 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -4,11 +4,7 @@ import os import csv -import codecs -try: - import hashlib -except ImportError: - from distutils2._backport import hashlib +import hashlib from distutils2 import logger from distutils2.command.cmd import Command @@ -89,11 +85,8 @@ class install_distinfo(Command): installer_path = os.path.join(self.install_dir, 'INSTALLER') logger.info('creating %s', installer_path) if not self.dry_run: - f = open(installer_path, 'w') - try: + with open(installer_path, 'w') as f: f.write(self.installer) - finally: - f.close() self.outfiles.append(installer_path) if self.requested: @@ -110,15 +103,12 @@ class install_distinfo(Command): 'RESOURCES') logger.info('creating %s', resources_path) if not self.dry_run: - f = open(resources_path, 'w') - try: + with open(resources_path, 'w') as f: writer = csv.writer(f, delimiter=',', lineterminator='\n', quotechar='"') for row in install_data.get_resources_out(): writer.writerow(row) - finally: - f.close() self.outfiles.append(resources_path) @@ -126,8 +116,7 @@ class install_distinfo(Command): record_path = os.path.join(self.install_dir, 'RECORD') logger.info('creating %s', record_path) if not self.dry_run: - f = codecs.open(record_path, 'w', encoding='utf-8') - try: + with open(record_path, 'w', encoding='utf-8') as f: writer = csv.writer(f, delimiter=',', lineterminator='\n', quotechar='"') @@ -140,19 +129,14 @@ class install_distinfo(Command): writer.writerow((fpath, '', '')) else: size = os.path.getsize(fpath) - fp = open(fpath, 'rb') - try: + with open(fpath, 'rb') as fp: hash = hashlib.md5() hash.update(fp.read()) - finally: - fp.close() md5sum = hash.hexdigest() writer.writerow((fpath, md5sum, size)) # add the RECORD file itself writer.writerow((record_path, '', '')) - finally: - f.close() self.outfiles.append(record_path) def get_outputs(self): |
