-def expand_files(target_dir, dir_name, files):
- global total
- xlen = len(sys.argv[2])
- targdir = target_dir + dir_name[xlen:]
- if not os.path.exists(targdir):
- os.makedirs(targdir)
- env = jinja2.Environment()
- env.trim_blocks = True
- env.lstrip_blocks = True
-
- for f in files:
- if f.endswith(".j2"):
- t = f.replace(".j2", ".yaml")
- source_path = dir_name + '/' + f
- target_path = targdir + '/' + t
- if os.path.isfile(source_path):
- with open(source_path) as fd:
- template = env.from_string(fd.read())
- data = template.render(yaml=yaml)
- fd2 = open(target_path,'w')
- fd2.write(data)
- fd2.write("\n")
- fd2.close()
- print '{0} -> {1}'.format(source_path, target_path)
- total += 1