aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Volkhart <Marius@volkhart.com>2019-02-06 16:30:41 +0900
committerMarius Volkhart <Marius@volkhart.com>2019-02-06 16:41:56 +0900
commit28ffdb84b1f0673f8ea8a0cdedc02aeb46fdb94d (patch)
tree8aac431ea386324f754b8e5619d5209f81de8cfa
parentMinor changes. (diff)
downloadgoldilocks-28ffdb84b1f0673f8ea8a0cdedc02aeb46fdb94d.tar.xz
goldilocks-28ffdb84b1f0673f8ea8a0cdedc02aeb46fdb94d.zip
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.
-rw-r--r--src/generator/template.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/generator/template.py b/src/generator/template.py
index ce127a3..c40ba29 100644
--- a/src/generator/template.py
+++ b/src/generator/template.py
@@ -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