Stop mkdir output on each job write

When JJB write jobs to an output directory, each job would attempt to
mkdir the output directory causing unneccessary system calls:

mkdir("output-parent", 0777)            = -1 EEXIST (File exists)
stat("output-parent", {st_mode=S_IFDIR|0755, ...}) = 0

Create the output directory before the write loop unless it the output
is writable (stdout) or it already exist. That should speed up the test
operation a little bit.

Change-Id: I17495cba51bd85e4a6f86491a992cec6a3024e72
This commit is contained in:
Antoine Musso 2015-03-19 12:41:26 +01:00
parent f14589b14d
commit 750b576246

@ -812,6 +812,15 @@ class Builder(object):
logger.info("Number of jobs generated: %d", len(self.parser.xml_jobs))
self.parser.xml_jobs.sort(key=operator.attrgetter('name'))
if (output and not hasattr(output, 'write')
and not os.path.isdir(output)):
logger.info("Creating directory %s" % output)
try:
os.makedirs(output)
except OSError:
if not os.path.isdir(output):
raise
for job in self.parser.xml_jobs:
if jobs_glob and not matches(job.name, jobs_glob):
continue
@ -830,15 +839,7 @@ class Builder(object):
raise
continue
output_dir = output
try:
os.makedirs(output_dir)
except OSError:
if not os.path.isdir(output_dir):
raise
output_fn = os.path.join(output_dir, job.name)
output_fn = os.path.join(output, job.name)
logger.debug("Writing XML to '{0}'".format(output_fn))
f = open(output_fn, 'w')
f.write(job.output())