diff options
Diffstat (limited to 'distutils2/database.py')
| -rw-r--r-- | distutils2/database.py | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/distutils2/database.py b/distutils2/database.py index db5988a..3fafafd 100644 --- a/distutils2/database.py +++ b/distutils2/database.py @@ -6,7 +6,10 @@ import re import csv import sys import zipimport -from hashlib import md5 +try: + from hashlib import md5 +except ImportError: + from _backport.hashlib import md5 from distutils2 import logger from distutils2.errors import PackagingError from distutils2.version import suggest_normalized_version, VersionPredicate @@ -158,25 +161,27 @@ class Distribution(object): def _get_records(self, local=False): results = [] - with self.get_distinfo_file('RECORD') as record: - record_reader = csv.reader(record, delimiter=',', - lineterminator='\n') - for row in record_reader: - missing = [None for i in range(len(row), 3)] - path, checksum, size = row + missing - if local: - path = path.replace('/', os.sep) - path = os.path.join(sys.prefix, path) - results.append((path, checksum, size)) + record = self.get_distinfo_file('RECORD') + record_reader = csv.reader(record, delimiter=',', + lineterminator='\n') + for row in record_reader: + missing = [None for i in range(len(row), 3)] + path, checksum, size = row + missing + if local: + path = path.replace('/', os.sep) + path = os.path.join(sys.prefix, path) + results.append((path, checksum, size)) + record.close() return results def get_resource_path(self, relative_path): - with self.get_distinfo_file('RESOURCES') as resources_file: - resources_reader = csv.reader(resources_file, delimiter=',', - lineterminator='\n') - for relative, destination in resources_reader: - if relative == relative_path: - return destination + resources_file = self.get_distinfo_file('RESOURCES') + resources_reader = csv.reader(resources_file, delimiter=',', + lineterminator='\n') + for relative, destination in resources_reader: + if relative == relative_path: + return destination + resources_file.close() raise KeyError( 'no resource file with relative path %r is installed' % relative_path) @@ -325,8 +330,9 @@ class EggInfoDistribution(object): self.metadata = Metadata(path=meta_path) try: req_path = os.path.join(path, 'EGG-INFO', 'requires.txt') - with open(req_path, 'r') as fp: - requires = fp.read() + fp = open(req_path, 'r') + requires = fp.read() + fp.close() except IOError: requires = None else: @@ -346,8 +352,9 @@ class EggInfoDistribution(object): if os.path.isdir(path): path = os.path.join(path, 'PKG-INFO') try: - with open(os.path.join(path, 'requires.txt'), 'r') as fp: - requires = fp.read() + fp = open(os.path.join(path, 'requires.txt'), 'r') + requires = fp.read() + fp.close() except IOError: requires = None self.metadata = Metadata(path=path) @@ -409,8 +416,9 @@ class EggInfoDistribution(object): def list_installed_files(self, local=False): def _md5(path): - with open(path, 'rb') as f: - content = f.read() + f = open(path, 'rb') + content = f.read() + f.close() return md5(content).hexdigest() def _size(path): |
