Commit 28ffdb84 authored by Marius Volkhart's avatar Marius Volkhart

Fix flaky Python generator

The existing code checked if a directory existed and if it did, it would
not attempt to create it. However, this proved to be flaky on Mac and Linux.
The check would frequently report the directory as not existing, but the
attempt to create the directory would cause an exception.
parent 03977eba
......@@ -56,16 +56,16 @@ author = "Mike Hamburg" # FUTURE
for name in args.files:
_,_,name_suffix = name.rpartition(".")
template0 = open(name,"r").read()
data = per_map[args.per][args.item]
template = template0
outname = args.o
guard = args.guard
if guard is None: guard = outname
header_guard = "__" + guard.replace(".","_").replace("/","_").upper() + "__"
# Extract doxygenation
m = re.match(r"^\s*/\*\*([^*]|\*[^/])+\*/[ \t]*\n",template)
if m:
......@@ -73,12 +73,12 @@ for name in args.files:
doc = re.sub("\\s*\*/","",doc)
template = template[m.end():]
else: doc = ""
ns_doc = dedent(doc).strip().rstrip()
ns_doc = redoc(guard, fillin(ns_doc,data), author)
ns_code = fillin(template,data)
ret = ns_doc + "\n"
if outname.endswith(".h") or outname.endswith(".hxx"):
ns_code = dedent("""\n
#ifndef %(header_guard)s
......@@ -87,11 +87,11 @@ for name in args.files:
#endif /* %(header_guard)s */
""") % { "header_guard" : header_guard, "code": ns_code }
ret += ns_code[1:-1]
if not os.path.exists(os.path.dirname(outname)):
try:
os.makedirs(os.path.dirname(outname))
except OSError as e:
if e.errno != 17: # errno.EEXIST
raise
with open(outname,"w") as f:
f.write(ret + "\n")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment