Author: bugman Date: Tue Mar 20 14:41:45 2012 New Revision: 15583 URL: http://svn.gna.org/viewcvs/relax?rev=15583&view=rev Log: The SCons api_manual_html target now adds the Google Analytics JS to all API pages. This is for the API manual at http://www.nmr-relax.com/api/. Modified: 1.3/scons/manuals.py Modified: 1.3/scons/manuals.py URL: http://svn.gna.org/viewcvs/relax/1.3/scons/manuals.py?rev=15583&r1=15582&r2=15583&view=diff ============================================================================== --- 1.3/scons/manuals.py (original) +++ 1.3/scons/manuals.py Tue Mar 20 14:41:45 2012 @@ -20,12 +20,17 @@ # # ############################################################################### - -# Import statements. +# Module docstring. +"""SCons targets for building the relax manuals.""" + +# Python module imports. from glob import glob from os import F_OK, access, chdir, getcwd, listdir, path, remove, rename, sep, system +from re import search import sys +# relax module imports. +from status import Status; status = Status() from version import version @@ -293,6 +298,60 @@ # Close the file. css_file.close() + + # Modify all HTML files. + ######################## + + # Print out. + print("\n\nModifying the <head> tag of all HTML files.\n") + + # The additional head tags. + head_lines = [] + + # The Google analytics JS. + file = open(status.install_path + sep + 'scripts' + sep + 'google_analytics.js') + for line in file.readlines(): + head_lines.append(line) + file.close() + + # Loop over the files. + for file_name in listdir(status.install_path + sep + 'docs' + sep + 'api'): + # The full path. + full_path = status.install_path + sep + 'docs' + sep + 'api' + sep + file_name + + # Skip all non-html files. + if not search('.html$', full_path): + continue + + # Print out. + print(full_path) + + # Open the file and read the data. + file = open(full_path) + lines = file.readlines() + file.close() + + # Modify the original file. + file = open(full_path, 'w') + + # Loop over the lines. + found = False + for i in range(len(lines)): + # Find the position of </head>. + if not found and search('</head>', lines[i]): + # Append the head lines. + for j in range(len(head_lines)): + file.write(head_lines[j]) + + # The found flag. + found = True + + # Append the old line. + file.write(lines[i]) + + # Close the file. + file.close() + # Final print out. print("\n\n\n")