]> Shamusworld >> Repos - ardour-manual-diverged/commitdiff
Should be final version of Python build script.
authorShamus Hammons <jlhamm@acm.org>
Wed, 1 Feb 2017 19:13:36 +0000 (13:13 -0600)
committerShamus Hammons <jlhamm@acm.org>
Wed, 1 Feb 2017 19:13:36 +0000 (13:13 -0600)
build.py
explode.py
implode.py
include/favorite-plugins-window.html
master-doc.txt

index e3eeef3ca8135376ada362f4b0d8262bd4b5c7f4..ec09ad657393f4e2ac4bd77146132355cdc029db 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -15,6 +15,7 @@
 import os
 import re
 import shutil
+import argparse
 
 
 #
@@ -183,13 +184,32 @@ def FindTopLevelNodes(fs):
 
 
 #
-# Internal links are of the form '@link-name', which are references to the
+# Find all header links and create a dictionary out of them
+#
+def FindInternalLinks(fs):
+       linkDict = {}
+
+       for hdr in fs:
+               if 'link' in hdr:
+                       linkDict['@@' + hdr['link']] = '/' + hdr['filename'] + '/'
+
+       return linkDict
+
+
+#
+# Internal links are of the form '@@link-name', which are references to the
 # 'link:' field in the part header. We have to find all occurances and replace
 # them with the appropriate link.
 #
-def FixInternalLinks(content):
-#make a dictionary ahead of time of <link:, filename:> pairs
-       return content
+def FixInternalLinks(links, content):
+
+       # Make key1|key2|key3|... out of our links keys
+       pattern = re.compile('|'.join(links.keys()))
+
+       # Use a lambda callback to substitute each occurance found
+       result = pattern.sub(lambda x: links[x.group()], content)
+
+       return result
 
 
 #
@@ -237,11 +257,23 @@ def CreateLinkSidebar(fs, pos, childList):
 
 # Preliminaries
 
+# We have command line arguments now, so deal with them
+parser = argparse.ArgumentParser(description='A build script for the Ardour Manual')
+parser.add_argument('-v', '--verbose', action='store_true', help='Display the high-level structure of the manual')
+parser.add_argument('-q', '--quiet', action='store_true', help='Suppress all output (overrides -v)')
+args = parser.parse_args()
+verbose = args.verbose
+quiet = args.quiet
+
+if quiet:
+       verbose = False
+
+
 roman = [ '0', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X',
        'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
        'XXI', 'XXII', 'XXIII', 'XXIV', 'XXV', 'XXVI', 'XXVII', 'XXVIII', 'XXIX', 'XXX' ]
 
-verbose = True
+#verbose = False
 level = 0
 fileCount = 0
 levelNums = [0]*6
@@ -253,7 +285,9 @@ pageNumber = 0
 siteDir = './website/'
 
 if os.access(siteDir, os.F_OK):
-       print('Removing stale HTML data...')
+       if not quiet:
+               print('Removing stale HTML data...')
+
        shutil.rmtree(siteDir)
 
 shutil.copytree('./source', siteDir)
@@ -275,20 +309,30 @@ template = template.replace('{{page.page_title}}', 'The Ardour Manual')
 
 # Parse out the master docuemnt's structure into a dictionary list
 fileStruct = GetFileStructure()
+
+# Build a quasi-tree structure listing children at level + 1 for each node
 nodeChildren = FindChildren(fileStruct)
 
-# Here we go!
+# Create a dictionary for translation of internal links to real links
+links = FindInternalLinks(fileStruct)
 
-master = open('master-doc.txt')
-firstLine = master.readline().rstrip('\r\n')
-master.close()
+if not quiet:
+       print('Found ' + str(len(links)) + ' internal link target', end='')
+       print('.') if len(links) == 1 else print('s.')
 
-if firstLine == '<!-- exploded -->':
-       print('Parsing exploded file...')
-elif firstLine == '<!-- imploded -->':
-       print('Parsing imploded file...')
-else:
-       print('Parsing unknown type...')
+if not quiet:
+       master = open('master-doc.txt')
+       firstLine = master.readline().rstrip('\r\n')
+       master.close()
+
+       if firstLine == '<!-- exploded -->':
+               print('Parsing exploded file...')
+       elif firstLine == '<!-- imploded -->':
+               print('Parsing imploded file...')
+       else:
+               print('Parsing unknown type...')
+
+# Here we go!
 
 for header in fileStruct:
        fileCount = fileCount + 1
@@ -312,7 +356,6 @@ for header in fileStruct:
 
        # This is totally unnecessary, but nice; besides which, you can capture
        # the output to a file to look at later if you like :-)
-       # [TODO: add command line switch, default to False]
        if verbose:
                for i in range(level):
                        print('\t', end='')
@@ -382,6 +425,9 @@ for header in fileStruct:
                        else:
                                content = '[something went wrong]'
 
+       # Fix up any internal links
+       content = FixInternalLinks(links, content)
+
        # Set up the actual page from the template
        if 'style' not in header:
                page = re.sub("{% if page.style %}.*\n.*\n{% endif %}.*\n", "", template)
@@ -421,5 +467,6 @@ tocFile = open(siteDir + 'toc/index.html', 'w')
 tocFile.write(page)
 tocFile.close()
 
-print('Processed ' + str(fileCount) + ' files.')
+if not quiet:
+       print('Processed ' + str(fileCount) + ' files.')
 
index 85eb250147be570ef77d330594a1cc4bc03b56af..13fa6774bcaebfad2c40605cabc38552cd6b2846 100755 (executable)
@@ -86,7 +86,8 @@ for line in master:
                                suffix = suffix + 1
                                inclFile = MakeFilename(header['title']) + str(suffix) + '.html'
 
-               # Pull in files and write the result to the master file
+               # Find all files in the master file and write them out to include/,
+               # while removing it from the master file.
                explode.write('\n---\n' + 'title: ' + header['title'] + '\n')
 
                if header['part'] != 'part':
@@ -119,15 +120,16 @@ for line in master:
 
                                toFile = open('include/' + inclFile, 'w')
                                writingFile = True
-                               toFile.write('---\n' + 'title: ' + header['title'] + '\n')
-
-                               if 'menu_title' in header:
-                                       toFile.write('menu_title: ' + header['menu_title'] + '\n')
-
-                               if 'style' in header:
-                                       toFile.write('style: ' + header['style'] + '\n')
-
-                               toFile.write('---\n')
+#no more headers in separate files ffs...
+#                              toFile.write('---\n' + 'title: ' + header['title'] + '\n')
+#
+#                              if 'menu_title' in header:
+#                                      toFile.write('menu_title: ' + header['menu_title'] + '\n')
+#
+#                              if 'style' in header:
+#                                      toFile.write('style: ' + header['style'] + '\n')
+#
+#                              toFile.write('---\n')
        else:
                if writingFile:
                        toFile.write(line)
index 46c26e5ff984b40313f317d79442f2f95612c358..8906a1d2be8cda33cef9880a29c323ee6aec6f33 100755 (executable)
@@ -102,6 +102,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
index eec0f8eb23428edd47226f1b4dee3c5c692bb23f..6e83d38fd92c3017b1f658a8e192ea7c259de868 100644 (file)
@@ -21,7 +21,7 @@ ow">
 </p>
 
 <ul>
-  <li>Plugins can be dragged from the window to any track or bus <a href="/working-with-plugins/processor-box/"><dfn>processor box</dfn></a>, which will add the plugin to that track or bus at the given position.</li>
+  <li>Plugins can be dragged from the window to any track or bus <a href="@@processor-box"><dfn>processor box</dfn></a>, which will add the plugin to that track or bus at the given position.</li>
   <li>The list includes user-presets for the plugins. Dragging a preset to a given track or bus will load that preset after adding the plugin.</li>
   <li>Double-clicking on a plugin or preset adds the given plugin to all selected tracks/busses pre-fader. Other insert positions are available from the context menu (right click).</li>
   <li>Dragging a plugin from a track into the window will add it to the list and optionally create a new preset from the current settings. The horizontal line in the list shows the spot where the plugin will land.</li>
@@ -30,6 +30,6 @@ ow">
 </ul>
 
 <p class="note">
-  When favorites are added with the <a href="/working-with-plugins/plugin-manager">Plugin Manager</a>, they are appended to the bottom of the list.
+  When favorites are added with the <a href="@@plugin-manager">Plugin Manager</a>, they are appended to the bottom of the list.
 </p>
 
index 9991497efe6e3bd8a9819990b41a61d5f37fa04b..bf8813fad40fd212f5de52e631d6a403839440e7 100644 (file)
@@ -1519,12 +1519,14 @@ part: subchapter
 
 ---
 title: Processor Box
+link: processor-box
 include: _manual/13_working-with-plugins/03_processor-box.html
 part: subchapter
 ---
 
 ---
 title: Plugin Manager
+link: plugin-manager
 include: _manual/13_working-with-plugins/02_plugin-manager.html
 part: subchapter
 ---