Merge "Fix leaks of tempdirs."

This commit is contained in:
Jenkins 2015-06-27 21:05:46 +00:00 committed by Gerrit Code Review
commit b2523895ca

View File

@ -16,6 +16,7 @@
# under the License.
import argparse
import contextlib
import os
import pkg_resources
import shlex
@ -115,6 +116,15 @@ def grab_args():
return parser.parse_args()
@contextlib.contextmanager
def tempdir():
try:
reqroot = tempfile.mkdtemp()
yield reqroot
finally:
shutil.rmtree(reqroot)
def main():
args = grab_args()
branch = args.branch
@ -138,7 +148,7 @@ def main():
# build a list of requirements from the global list in the
# openstack/requirements project so we can match them to the changes
reqroot = tempfile.mkdtemp()
with tempdir() as reqroot:
reqdir = os.path.join(reqroot, "openstack/requirements")
if args.zc is not None:
zc = args.zc
@ -171,7 +181,8 @@ def main():
if name in branch_reqs.reqs and req == branch_reqs.reqs[name]:
continue
if name not in os_reqs.reqs:
print("Requirement %s not in openstack/requirements" % str(req))
print(
"Requirement %s not in openstack/requirements" % str(req))
failed = True
continue
# pkg_resources.Requirement implements __eq__() but not __ne__().
@ -182,8 +193,7 @@ def main():
"value %s" % (str(req), str(os_reqs.reqs[name])))
failed = True
# clean up and report the results
shutil.rmtree(reqroot)
# report the results
if failed or os_reqs.failed or head_reqs.failed or branch_reqs.failed:
sys.exit(1)
print("Updated requirements match openstack/requirements.")