From c605d53b75584861051c445b45cdb0eccfd2a7d9 Mon Sep 17 00:00:00 2001 From: John Reese Date: Tue, 18 Nov 2008 10:16:32 -0500 Subject: [PATCH] Large overall improvement to docbook build scripts. -a, --all, --html, --pdf options allow selecting what to build -d, --delete allow specifying to delete install dir before rebuilding -f, --force allows repo script to ignore last-commit timestamps --- docbook-manual-repo.py | 59 ++++++++++++++++++++++++++++++++++------ docbook-manual.py | 62 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 106 insertions(+), 15 deletions(-) diff --git a/docbook-manual-repo.py b/docbook-manual-repo.py index 1d06647..e90fb76 100755 --- a/docbook-manual-repo.py +++ b/docbook-manual-repo.py @@ -6,6 +6,7 @@ import os, sys from os import path +import getopt import re # Absolute path to docbook-manual.py @@ -18,8 +19,19 @@ '-1\.1\.[\w\d]+' ]) +# Script options +options = "hfda" +long_options = [ "help", "force", "delete", "all", "pdf", "html" ] + def usage(): - print '''Usage: docbook-manual-repo /path/to/mantisbt/repo /path/to/install [ ...]''' + print '''Usage: docbook-manual-repo /path/to/mantisbt/repo /path/to/install [ ...] + Options: -h | --help Print this usage message + -f | --force Ignore timestamps and force building + -d | --delete Delete install directories before building + --html Build HTML manual + --pdf Build PDF manual + -a | --all Build all manual types''' +#end usage() def ignore( ref ): '''Decide which refs to ignore based on regexen listed in 'ignorelist'. @@ -33,16 +45,46 @@ def ignore( ref ): #end ignore() def main(): - if len(sys.argv) < 3: + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options) + except getopt.GetoptError, err: + print str(err) + usage() + sys.exit(2) + + force = False + pass_opts = "" + + for opt, val in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(0) + + elif opt in ("-f", "--force"): + force = True + + elif opt in ("-d", "--delete"): + pass_opts += " -d" + + elif opt in ("-a", "--all"): + pass_opts += " -a" + + elif opt == "--html": + pass_opts += " --html" + + elif opt == "--pdf": + pass_opts += " --pdf" + + if len(args) < 2: usage() sys.exit(1) - repo = sys.argv[1] - installroot = sys.argv[2] + repo = args[0] + installroot = args[1] languages = [] - if len(sys.argv) > 3: - languages = sys.argv[3:] + if len(sys.argv) > 2: + languages = args[2:] # Update repo from default remote os.chdir(repo) @@ -74,8 +116,9 @@ def main(): lastbuild = f.read() f.close() - if lastchange > lastbuild: - buildcommand = '%s %s %s %s'%(manualscript, path.abspath('docbook'), manualpath, ' '.join(languages)) + if lastchange > lastbuild or force: + buildcommand = '%s %s %s %s %s'%(manualscript, pass_opts, path.abspath('docbook'), manualpath, ' '.join(languages)) + print "Calling: " + buildcommand if(os.system(buildcommand)): print 'here' diff --git a/docbook-manual.py b/docbook-manual.py index 3561d84..54bb4bb 100755 --- a/docbook-manual.py +++ b/docbook-manual.py @@ -3,23 +3,70 @@ import os, sys from os import path +import getopt + +# Script options +options = "hda" +long_options = [ "help", "delete", "all", "pdf", "html" ] + def usage(): - print '''Usage: docbook-manual /path/to/mantisbt/docbook /path/to/install [ ...]''' + print '''Usage: docbook-manual /path/to/mantisbt/docbook /path/to/install [ ...] + Options: -h | --help Print this usage message + -d | --delete Delete install directory before building + --html Build HTML manual + --pdf Build PDF manual + -a | --all Build all manual types''' +#end usage() def main(): - if len(sys.argv) < 3: + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options) + except getopt.GetoptError, err: + print str(err) + usage() + sys.exit(2) + + delete = False + types = "html pdf" + + for opt, val in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(0) + + elif opt in ("-d", "--delete"): + delete = True + + elif opt in ("-a", "--all"): + types = "html html_onefile html.tar.gz text pdf ps" + + elif opt == "--html": + types = "html html_onefile html.tar.gz" + + elif opt == "--pdf": + types = "pdf" + + if len(args) < 2: usage() sys.exit(1) - docroot = sys.argv[1] - installroot = sys.argv[2] + docroot = args[0] + installroot = args[1] languages = [] - if len(sys.argv) > 3: - languages = sys.argv[3:] + if len(sys.argv) > 2: + languages = args[2:] os.chdir( docroot ) + if delete and installroot != "/" and path.isdir( installroot ): + print "Deleting install directory " + installroot + for root, dirs, files in os.walk( installroot, topdown=False ): + for name in files: + os.remove( path.join( root, name ) ) + for name in dirs: + os.rmdir( path.join( root, name ) ) + for dir in os.listdir( docroot ): if dir == '.svn' or dir == 'template': continue @@ -34,10 +81,11 @@ def main(): for lang in langs: builddir = path.join( docroot, dir, lang ) installdir = path.join( installroot, lang ) + if path.isdir( builddir ): print "Building manual in " + builddir os.chdir( builddir ) - os.system( 'make clean html 2>&1 && make INSTALL_DIR=' + installdir + ' install 2>&1' ) + os.system( 'make clean %s 2>&1 && make INSTALL_DIR=%s install 2>&1'%(types, installdir) ) #end main if __name__ == '__main__':