[Piglit] [Patch v2] generated_tests: Catch exception in os.makedirs
Mark Janes
mark.a.janes at intel.com
Fri Dec 12 16:28:07 PST 2014
Thanks, this is a superior implementation imho.
-Mark
Dylan Baker <baker.dylan.c at gmail.com> writes:
> +
> +def safe_makedirs(dirs):
> + """A safe function for creating a directory tree.
> +
> + This function wraps os.makedirs, and provides a couple of sanity checks,
> + first, if the directory already exists it doesn't try to create it, and
> + second if the directory comes into existence between the check and creation
> + time (like if another generator creates it) then the exception will be
> + caught.
> +
> + """
> + if not os.path.exists(dirs):
> + try:
> + os.makedirs(dirs)
> + except OSError as e:
> + if e.errno == errno.EEXIST:
> + pass
> + raise
More information about the Piglit
mailing list