shithub: choc

Download patch

ref: aca532db25d58f45cbeed909f7eb09717b21b7dc
parent: 93a2a60a3d4643b7f888b0544d27b28f90967edc
author: Simon Howard <fraggle@soulsphere.org>
date: Sun Jul 17 20:02:58 EDT 2016

docgen: Read included templates from relative path.

When interpreting a template file that uses the @include statement, we
must read the included file from a path relative to the first template
file, rather than relative to the working directory when invoking the
script. This will allow us to do out-of-tree builds.

--- a/man/docgen
+++ b/man/docgen
@@ -300,9 +300,7 @@
 # Read list of wiki pages
 
 def read_wikipages():
-    f = open("wikipages")
-
-    try:
+    with open("wikipages") as f:
         for line in f:
             line = line.rstrip()
 
@@ -310,8 +308,6 @@
 
             if not re.match('^\s*$', line):
                 wikipages.append(line)
-    finally:
-        f.close()
 
 # Add wiki page links
 
@@ -352,13 +348,11 @@
 
     raise Exception(param.text)
 
-def process_file(file):
+def process_file(filename):
 
     current_config_file = None
 
-    f = open(file)
-
-    try:
+    with open(filename) as f:
         param = None
         waiting_for_checkparm = False
 
@@ -405,8 +399,6 @@
                     # Start of a normal comment
                     param = Parameter()
                     waiting_for_checkparm = False
-    finally:
-        f.close()
 
 def process_files(path):
     # Process all C source files.
@@ -414,8 +406,8 @@
     if os.path.isdir(path):
         files = glob.glob(path + "/*.c")
 
-        for file in files:
-            process_file(file)
+        for filename in files:
+            process_file(filename)
     else:
         # Special case to allow a single file to be specified as a target
 
@@ -422,20 +414,17 @@
         process_file(path)
 
 def print_template(template_file, content):
-    f = open(template_file)
-
-    try:
+    with open(template_file) as f:
         for line in f:
             match = INCLUDE_STATEMENT_RE.search(line)
             if match:
                 filename = match.group(1)
+                filename = os.path.join(os.path.dirname(template_file),
+                                        filename)
                 print_template(filename, content)
             else:
                 line = line.replace("@content", content)
                 print(line.rstrip())
-
-    finally:
-        f.close()
 
 def manpage_output(targets, template_file):