]> Shamusworld >> Repos - ardour-manual-diverged/blobdiff - implode.py
Update to minimal build.
[ardour-manual-diverged] / implode.py
index 46c26e5ff984b40313f317d79442f2f95612c358..fcc0e21318d59f1283d6e39c078858f0a27a0ac2 100755 (executable)
@@ -11,7 +11,38 @@ import os
 import re
 import shutil
 
+lineCount = 0
+
+
+#
+# Parse headers into a dictionary
+#
+def ParseHeader(fileObj):
+       global lineCount
+       header = {}
+
+       while (True):
+               hdrLine = fileObj.readline().rstrip('\r\n')
+               lineCount = lineCount + 1
+
+               # Break out of the loop if we hit the end of header marker
+               if hdrLine.startswith('---'):
+                       break
+
+               # Check to see that we have a well-formed header construct
+               match = re.findall(': ', hdrLine)
+
+               if match:
+                       # Parse out foo: bar pairs & put into header dictionary
+                       a = re.split(': ', hdrLine, 1)
+                       header[a[0]] = a[1]
 
+       return header
+
+
+#
+# Check to see if a given file has a header (it shouldn't)
+#
 def CheckForHeader(fn):
        check = open(fn)
 
@@ -24,7 +55,6 @@ def CheckForHeader(fn):
        return False
 
 
-lineCount = 0
 fileCount = 0
 delList = []
 
@@ -51,20 +81,8 @@ for line in master:
        # Do any header parsing if needed...
        if line.startswith('---'):
 
-               header = {}
                noMove = False
-
-               while (True):
-                       hdrLine = master.readline().rstrip('\r\n')
-                       lineCount = lineCount + 1
-
-                       # Break out of the loop if we hit the end of header marker
-                       if hdrLine.startswith('---'):
-                               break
-
-                       # Parse out foo: bar pairs & put into header dictionary
-                       a = re.split(': ', hdrLine, 1)
-                       header[a[0]] = a[1]
+               header = ParseHeader(master)
 
                # Pull in files and write the result to the master file
                implode.write('\n---\n' + 'title: ' + header['title'] + '\n')
@@ -79,6 +97,8 @@ for line in master:
                        if 'style' in header:
                                implode.write('style: ' + header['style'] + '\n')
 
+                       implode.write('file: ' + header['include'] + '\n')
+
                        if ('exclude' in header) and ('include' in header):
                                noMove = True
                                implode.write('include: ' + header['include'] + '\n')
@@ -102,6 +122,7 @@ for line in master:
                                        os.rename('master-doc.bak', 'master-doc.txt')
                                        exit(-1)
 
+#eventually this will go away, as this will never happen again...
                                if CheckForHeader(inclFile) == True:
 
                                        # Skip the header
@@ -123,6 +144,7 @@ implode.close()
 print('Processed ' + str(lineCount) + ' lines.')
 print('Imploded master document from ' + str(fileCount) + ' files.')
 
+# Cleanup after successful implode
 os.remove('master-doc.bak')
 
 for name in delList: