From 3bebac3d0e8f24065ecda4abb2a2dad7b1d57164 Mon Sep 17 00:00:00 2001 From: Dirk Baechle Date: Tue, 8 Oct 2013 12:54:45 +0200 Subject: - added an explicit Gs() Builder to the gs.py Tool - updated documentation accordingly and added a (very) simple test --- doc/generated/builders.gen | 21 +++++++++++++++++++++ doc/generated/builders.mod | 4 ++++ doc/generated/tools.gen | 7 ++++++- doc/generated/variables.gen | 18 +++++++++++------- src/engine/SCons/Tool/gs.py | 31 +++++++++++++++++++++---------- src/engine/SCons/Tool/gs.xml | 38 ++++++++++++++++++++++++++++++-------- test/Ghostscript/GS.py | 2 ++ 7 files changed, 95 insertions(+), 26 deletions(-) diff --git a/doc/generated/builders.gen b/doc/generated/builders.gen index 3fdafb6..5cd92f2 100644 --- a/doc/generated/builders.gen +++ b/doc/generated/builders.gen @@ -397,6 +397,27 @@ env.DVI(target = 'ccc.dvi', source = 'ccc.latex') + + + Gs() + + + env.Gs() + + + +A Builder for explicitly calling the gs executable. +Depending on the underlying OS, the different names gs, +gsos2 and gswin32c +are tried. + +env = Environment(tools=['gs']) +env.Gs('cover.jpg','scons-scons.pdf', + GSFLAGS='-dNOPAUSE -dBATCH -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -q') + ) + + + Install() diff --git a/doc/generated/builders.mod b/doc/generated/builders.mod index 59900cc..b8c7d80 100644 --- a/doc/generated/builders.mod +++ b/doc/generated/builders.mod @@ -21,6 +21,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. DocbookXInclude"> DocbookXslt"> DVI"> +Gs"> Install"> InstallAs"> InstallVersionedLib"> @@ -74,6 +75,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. env.DocbookXInclude"> env.DocbookXslt"> env.DVI"> +env.Gs"> env.Install"> env.InstallAs"> env.InstallVersionedLib"> @@ -137,6 +139,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. DocbookXInclude"> DocbookXslt"> DVI"> +Gs"> Install"> InstallAs"> InstallVersionedLib"> @@ -190,6 +193,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. env.DocbookXInclude"> env.DocbookXslt"> env.DVI"> +env.Gs"> env.Install"> env.InstallAs"> env.InstallVersionedLib"> diff --git a/doc/generated/tools.gen b/doc/generated/tools.gen index 57bb0a2..7d75638 100644 --- a/doc/generated/tools.gen +++ b/doc/generated/tools.gen @@ -444,7 +444,12 @@ Set construction variables for GNU linker/loader. gs -Set construction variables for Ghostscript. +This Tool sets the required construction variables for working with +the Ghostscript command. It also registers an appropriate Action +with the PDF Builder (PDF), such that the conversion from +PS/EPS to PDF happens automatically for the TeX/LaTeX toolchain. +Finally, it adds an explicit Ghostscript Builder (Gs) to the +environment. Sets: &cv-link-GS;, &cv-link-GSCOM;, &cv-link-GSFLAGS;.Uses: &cv-link-GSCOMSTR;. diff --git a/doc/generated/variables.gen b/doc/generated/variables.gen index 784cd28..ee5a0dd 100644 --- a/doc/generated/variables.gen +++ b/doc/generated/variables.gen @@ -2324,7 +2324,7 @@ described above.) GS -The Ghostscript program used to convert PostScript to PDF files. +The Ghostscript program used, e.g. to convert PostScript to PDF files. @@ -2332,7 +2332,8 @@ The Ghostscript program used to convert PostScript to PDF files. GSCOM -The Ghostscript command line used to convert PostScript to PDF files. +The full Ghostscript command line used for the conversion process. Its default +value is $GS $GSFLAGS -sOutputFile=$TARGET $SOURCES. @@ -2341,9 +2342,8 @@ The Ghostscript command line used to convert PostScript to PDF files. The string displayed when -Ghostscript is used to convert -a PostScript file to a PDF file. -If this is not set, then $GSCOM (the command line) is displayed. +Ghostscript is called for the conversion process. +If this is not set (the default), then $GSCOM (the command line) is displayed. @@ -2351,8 +2351,9 @@ If this is not set, then -General options passed to the Ghostscript program -when converting PostScript to PDF files. +General options passed to the Ghostscript program, +when converting PostScript to PDF files for example. Its default value +is -dNOPAUSE -dBATCH -sDEVICE=pdfwrite @@ -3548,6 +3549,9 @@ See m Internal ``macro''. Computes locale (language) name based on target filename (default: '${TARGET.filebase}' ). + +See msginit tool and POInit builder. + diff --git a/src/engine/SCons/Tool/gs.py b/src/engine/SCons/Tool/gs.py index ada169a..a8fddde 100644 --- a/src/engine/SCons/Tool/gs.py +++ b/src/engine/SCons/Tool/gs.py @@ -34,6 +34,7 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.Action +import SCons.Builder import SCons.Platform import SCons.Util @@ -52,17 +53,27 @@ GhostscriptAction = None def generate(env): """Add Builders and construction variables for Ghostscript to an Environment.""" - global GhostscriptAction - if GhostscriptAction is None: - GhostscriptAction = SCons.Action.Action('$GSCOM', '$GSCOMSTR') - - import pdf - pdf.generate(env) - - bld = env['BUILDERS']['PDF'] - bld.add_action('.ps', GhostscriptAction) - + # The following try-except block enables us to use the Tool + # in standalone mode (without the accompanying pdf.py), + # whenever we need an explicit call of gs via the Gs() + # Builder ... + try: + if GhostscriptAction is None: + GhostscriptAction = SCons.Action.Action('$GSCOM', '$GSCOMSTR') + + import pdf + pdf.generate(env) + + bld = env['BUILDERS']['PDF'] + bld.add_action('.ps', GhostscriptAction) + except ImportError, e: + pass + + gsbuilder = SCons.Builder.Builder(action = SCons.Action.Action('$GSCOM', '$GSCOMSTR'), + env = env) + env['BUILDERS']['Gs'] = gsbuilder + env['GS'] = gs env['GSFLAGS'] = SCons.Util.CLVar('-dNOPAUSE -dBATCH -sDEVICE=pdfwrite') env['GSCOM'] = '$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES' diff --git a/src/engine/SCons/Tool/gs.xml b/src/engine/SCons/Tool/gs.xml index c34f004..3fe5165 100644 --- a/src/engine/SCons/Tool/gs.xml +++ b/src/engine/SCons/Tool/gs.xml @@ -26,7 +26,12 @@ See its __doc__ string for a discussion of the format. -Set construction variables for Ghostscript. +This Tool sets the required construction variables for working with +the Ghostscript command. It also registers an appropriate Action +with the PDF Builder (&b-link-PDF;), such that the conversion from +PS/EPS to PDF happens automatically for the TeX/LaTeX toolchain. +Finally, it adds an explicit Ghostscript Builder (&b-link-Gs;) to the +environment. @@ -42,7 +47,7 @@ Set construction variables for Ghostscript. -The Ghostscript program used to convert PostScript to PDF files. +The Ghostscript program used, e.g. to convert PostScript to PDF files. @@ -50,7 +55,8 @@ The Ghostscript program used to convert PostScript to PDF files. -The Ghostscript command line used to convert PostScript to PDF files. +The full Ghostscript command line used for the conversion process. Its default +value is $GS $GSFLAGS -sOutputFile=$TARGET $SOURCES. @@ -59,9 +65,8 @@ The Ghostscript command line used to convert PostScript to PDF files. The string displayed when -Ghostscript is used to convert -a PostScript file to a PDF file. -If this is not set, then &cv-link-GSCOM; (the command line) is displayed. +Ghostscript is called for the conversion process. +If this is not set (the default), then &cv-link-GSCOM; (the command line) is displayed. @@ -69,10 +74,27 @@ If this is not set, then &cv-link-GSCOM; (the command line) is displayed. -General options passed to the Ghostscript program -when converting PostScript to PDF files. +General options passed to the Ghostscript program, +when converting PostScript to PDF files for example. Its default value +is -dNOPAUSE -dBATCH -sDEVICE=pdfwrite + + + +A Builder for explicitly calling the gs executable. +Depending on the underlying OS, the different names gs, +gsos2 and gswin32c +are tried. + +env = Environment(tools=['gs']) +env.Gs('cover.jpg','scons-scons.pdf', + GSFLAGS='-dNOPAUSE -dBATCH -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -q') + ) + + + + \ No newline at end of file diff --git a/test/Ghostscript/GS.py b/test/Ghostscript/GS.py index 2cae8b8..daeea09 100644 --- a/test/Ghostscript/GS.py +++ b/test/Ghostscript/GS.py @@ -51,6 +51,7 @@ env = Environment(GS = r'%(_python_)s mygs.py', GSCOM = r'$GS $TARGET $SOURCE', tools=['gs']) env.PDF(target = 'test1.pdf', source = 'test1.ps') +env.Gs(target = 'test2.pdf', source = 'test1.ps') """ % locals()) test.write('test1.ps', r"""This is a .ps test. @@ -60,6 +61,7 @@ test.write('test1.ps', r"""This is a .ps test. test.run(arguments = '.', stderr = None) test.fail_test(test.read('test1.pdf') != "This is a .ps test.\n") +test.fail_test(test.read('test2.pdf') != "This is a .ps test.\n") -- cgit v0.12