Fix leaks of tempdirs.
If interrupted tempdirs are currently leaked. Context managers reduce the ability for this to happen. Change-Id: Ia7adf5f2ec8d8a327802194c88f20b22200f12cf
This commit is contained in:
parent
ef696e4ef6
commit
4152062027
@ -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,7 +148,7 @@ 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
|
||||||
@ -171,7 +181,8 @@ def main():
|
|||||||
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(
|
||||||
|
"Requirement %s not in openstack/requirements" % str(req))
|
||||||
failed = True
|
failed = True
|
||||||
continue
|
continue
|
||||||
# pkg_resources.Requirement implements __eq__() but not __ne__().
|
# pkg_resources.Requirement implements __eq__() but not __ne__().
|
||||||
@ -182,8 +193,7 @@ def main():
|
|||||||
"value %s" % (str(req), str(os_reqs.reqs[name])))
|
"value %s" % (str(req), str(os_reqs.reqs[name])))
|
||||||
failed = True
|
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.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user