Handle directories in zuul.d/ configs

Prior to this change zuul-sphinx would error if there were directories
in zuul.d that needed to be processed recursively. This is because it
would try to open the directory as a normal file. Fix this by using
os.walk instead of os.listdir to iterate through the contents of the
zuul.d directory.

Additionally filter for .yaml files only as Zuul does this as well.

Change-Id: Id2d828d7842a86b7f89a2ce28a084e70f91d3f55
This commit is contained in:
Clark Boylan 2020-04-29 09:10:46 -07:00
parent 6a29830441
commit 38bf2470b8
1 changed files with 16 additions and 13 deletions

View File

@ -103,19 +103,22 @@ class ZuulDirective(Directive):
def parse_zuul_d(self, path):
layout = Layout()
for conf in os.listdir(path):
conf_path = os.path.join(path, conf)
with open(conf_path) as f:
data = yaml.load(f, Loader=ZuulSafeLoader)
if data is None:
raise SphinxError(
"File %s in Zuul dir is empty", conf_path)
for obj in data:
if 'job' in obj:
layout.jobs.append(obj['job'])
if 'project-template' in obj:
layout.project_templates.append(
ProjectTemplate(obj['project-template']))
# zuul.d configs are recursively loaded in zuul so we recursively
# load them here too.
for (dirpath, dirnames, filenames) in os.walk(path):
for conf in filter(lambda x: x.endswith('.yaml'), filenames):
conf_path = os.path.join(dirpath, conf)
with open(conf_path) as f:
data = yaml.load(f, Loader=ZuulSafeLoader)
if data is None:
raise SphinxError(
"File %s in Zuul dir is empty", conf_path)
for obj in data:
if 'job' in obj:
layout.jobs.append(obj['job'])
if 'project-template' in obj:
layout.project_templates.append(
ProjectTemplate(obj['project-template']))
return layout
def _parse_zuul_layout(self):