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)
return False
-lineCount = 0
fileCount = 0
delList = []
# 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')
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')
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
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: