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. # under the License.
import argparse import argparse
import contextlib
import os import os
import pkg_resources import pkg_resources
import shlex import shlex
@ -115,6 +116,15 @@ def grab_args():
return parser.parse_args() return parser.parse_args()
@contextlib.contextmanager
def tempdir():
try:
reqroot = tempfile.mkdtemp()
yield reqroot
finally:
shutil.rmtree(reqroot)
def main(): def main():
args = grab_args() args = grab_args()
branch = args.branch branch = args.branch
@ -138,52 +148,52 @@ def main():
# build a list of requirements from the global list in the # build a list of requirements from the global list in the
# openstack/requirements project so we can match them to the changes # 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") reqdir = os.path.join(reqroot, "openstack/requirements")
if args.zc is not None: if args.zc is not None:
zc = args.zc zc = args.zc
else: else:
zc = '/usr/zuul-env/bin/zuul-cloner' zc = '/usr/zuul-env/bin/zuul-cloner'
out, err = run_command("%(zc)s " out, err = run_command("%(zc)s "
"--cache-dir /opt/git " "--cache-dir /opt/git "
"--workspace %(root)s " "--workspace %(root)s "
"git://git.openstack.org " "git://git.openstack.org "
"openstack/requirements" "openstack/requirements"
% dict(zc=zc, root=reqroot)) % dict(zc=zc, root=reqroot))
print out print out
print err print err
os.chdir(reqdir) os.chdir(reqdir)
print "requirements git sha: %s" % run_command( print "requirements git sha: %s" % run_command(
"git rev-parse HEAD")[0] "git rev-parse HEAD")[0]
os_reqs = RequirementsList('openstack/requirements') os_reqs = RequirementsList('openstack/requirements')
if branch == 'master' or branch.startswith('feature/'): if branch == 'master' or branch.startswith('feature/'):
include_dev = True include_dev = True
else: else:
include_dev = False include_dev = False
os_reqs.read_all_requirements(include_dev=include_dev, os_reqs.read_all_requirements(include_dev=include_dev,
global_req=True) global_req=True)
# iterate through the changing entries and see if they match the global # iterate through the changing entries and see if they match the global
# equivalents we want enforced # equivalents we want enforced
failed = False failed = False
for req in head_reqs.reqs.values(): for req in head_reqs.reqs.values():
name = req.project_name.lower() name = req.project_name.lower()
if name in branch_reqs.reqs and req == branch_reqs.reqs[name]: if name in branch_reqs.reqs and req == branch_reqs.reqs[name]:
continue continue
if name not in os_reqs.reqs: if name not in os_reqs.reqs:
print("Requirement %s not in openstack/requirements" % str(req)) print(
failed = True "Requirement %s not in openstack/requirements" % str(req))
continue failed = True
# pkg_resources.Requirement implements __eq__() but not __ne__(). continue
# There is no implied relationship between __eq__() and __ne__() # pkg_resources.Requirement implements __eq__() but not __ne__().
# so we must negate the result of == here instead of using !=. # There is no implied relationship between __eq__() and __ne__()
if not (req == os_reqs.reqs[name]): # so we must negate the result of == here instead of using !=.
print("Requirement %s does not match openstack/requirements " if not (req == os_reqs.reqs[name]):
"value %s" % (str(req), str(os_reqs.reqs[name]))) print("Requirement %s does not match openstack/requirements "
failed = True "value %s" % (str(req), str(os_reqs.reqs[name])))
failed = True
# clean up and report the results # report the results
shutil.rmtree(reqroot)
if failed or os_reqs.failed or head_reqs.failed or branch_reqs.failed: if failed or os_reqs.failed or head_reqs.failed or branch_reqs.failed:
sys.exit(1) sys.exit(1)
print("Updated requirements match openstack/requirements.") print("Updated requirements match openstack/requirements.")