diff options
| author | David Ripton <dripton@redhat.com> | 2012-10-17 10:35:59 -0400 |
|---|---|---|
| committer | David Ripton <dripton@redhat.com> | 2012-10-17 10:39:02 -0400 |
| commit | 7695f967a3c750642504aa60f748111f64880a07 (patch) | |
| tree | a6797d2a4d129f68c03f54c0e7556643167afada /openstack/common/setup.py | |
| parent | d3ac5316d527f9a80eeecbbd2a064dada36a45a0 (diff) | |
| download | oslo-7695f967a3c750642504aa60f748111f64880a07.tar.gz oslo-7695f967a3c750642504aa60f748111f64880a07.tar.xz oslo-7695f967a3c750642504aa60f748111f64880a07.zip | |
Fix a couple of file handle leaks, using with statements.
In practice unclosed file handle leaks are not a huge deal in CPython code,
because reference counting means they get closed automatically in a timely
manner. But they're bad style, and they can become a real problem if the
code is run with a version of Python that doesn't use reference counting.
Change-Id: Ie54b979e26ffc9dd405871ee07c50b304cb36c67
Diffstat (limited to 'openstack/common/setup.py')
| -rw-r--r-- | openstack/common/setup.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/openstack/common/setup.py b/openstack/common/setup.py index 317e82d..4e2a577 100644 --- a/openstack/common/setup.py +++ b/openstack/common/setup.py @@ -31,13 +31,13 @@ from setuptools.command import sdist def parse_mailmap(mailmap='.mailmap'): mapping = {} if os.path.exists(mailmap): - fp = open(mailmap, 'r') - for l in fp: - l = l.strip() - if not l.startswith('#') and ' ' in l: - canonical_email, alias = [x for x in l.split(' ') - if x.startswith('<')] - mapping[alias] = canonical_email + with open(mailmap, 'r') as fp: + for l in fp: + l = l.strip() + if not l.startswith('#') and ' ' in l: + canonical_email, alias = [x for x in l.split(' ') + if x.startswith('<')] + mapping[alias] = canonical_email return mapping @@ -54,7 +54,8 @@ def canonicalize_emails(changelog, mapping): def get_reqs_from_files(requirements_files): for requirements_file in requirements_files: if os.path.exists(requirements_file): - return open(requirements_file, 'r').read().split('\n') + with open(requirements_file, 'r') as fil: + return fil.read().split('\n') return [] @@ -236,7 +237,8 @@ def read_versioninfo(project): def write_versioninfo(project, version): """Write a simple file containing the version of the package.""" - open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version) + with open(os.path.join(project, 'versioninfo'), 'w') as fil: + fil.write("%s\n" % version) def get_cmdclass(): |
