[Rivet-svn] r3435 - trunk/bin

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Oct 11 15:13:21 BST 2011


Author: fsiegert
Date: Tue Oct 11 15:13:21 2011
New Revision: 3435

Log:
Add basic booklet function to rivet-mkhtml. Also introduce safeguard for '-o .' to avoid deleting the cwd if somebody misunderstands the -o option (as in the school just now).

Modified:
   trunk/bin/rivet-mkhtml

Modified: trunk/bin/rivet-mkhtml
==============================================================================
--- trunk/bin/rivet-mkhtml	Tue Oct 11 14:24:13 2011	(r3434)
+++ trunk/bin/rivet-mkhtml	Tue Oct 11 15:13:21 2011	(r3435)
@@ -53,6 +53,8 @@
                   default="PDF", help="use PDF as the vector plot format.")
 parser.add_option("--ps", dest="VECTORFORMAT", action="store_const", const="PS",
                   default="PDF", help="use PostScript as the vector plot format.")
+parser.add_option("--booklet", dest="BOOKLET", action="store_true",
+                  default=False, help="create booklet (currently only available for PDF with pdftk).")
 parser.add_option("-i", "--ignore-unvalidated", dest="IGNORE_UNVALIDATED", action="store_true",
                   default=False, help="ignore unvalidated analyses.")
 parser.add_option("-m", "--match", action="append", dest="PATHPATTERNS",
@@ -71,7 +73,7 @@
 
 
 ## Make output directory
-if os.path.exists(opts.OUTPUTDIR):
+if os.path.exists(opts.OUTPUTDIR) and not os.path.realpath(opts.OUTPUTDIR)==os.getcwd():
     import shutil
     shutil.rmtree(opts.OUTPUTDIR)
 try:
@@ -184,7 +186,10 @@
 
 index = open(os.path.join(opts.OUTPUTDIR, "index.html"), "w")
 index.write('<html>\n<head>\n<title>%s</title>\n%s</head>\n<body>' % (opts.TITLE, style))
-index.write('<h2>%s</h2>\n\n' % opts.TITLE)
+if opts.BOOKLET and opts.VECTORFORMAT=="PDF":
+    index.write('<h2><a href="booklet.pdf">%s</a></h2>\n\n' % opts.TITLE)
+else:
+    index.write('<h2>%s</h2>\n\n' % opts.TITLE)
 
 if opts.SINGLE:
     ## Write table of contents
@@ -293,3 +298,11 @@
         print "Calling make-plots with the following options:"
         print mp_cmd
     Popen(mp_cmd).wait()
+    if opts.BOOKLET and opts.VECTORFORMAT=="PDF":
+        bookletcmd = ["pdftk"]
+        for analysis in analyses:
+            anapath = os.path.join(opts.OUTPUTDIR, analysis)
+            bookletcmd += sorted(glob.glob("%s/*.pdf" % anapath))
+        bookletcmd += ["cat", "output", "%s/booklet.pdf" % opts.OUTPUTDIR]
+        print bookletcmd
+        Popen(bookletcmd).wait()


More information about the Rivet-svn mailing list