]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/book_texinfo.py
Spelling fixes in comments and documentation
[lilypond.git] / python / book_texinfo.py
index 779cf566740aa8498d8d2f88a80b79747052c657..226ec8eb6f787b0bf8569d0dc51e6f2b99f51e92 100644 (file)
@@ -3,6 +3,7 @@
 import re
 import tempfile
 import subprocess
+import sys
 import book_base as BookBase
 from book_snippets import *
 import lilylib as ly
@@ -113,7 +114,7 @@ TexInfo_output = {
 
     OUTPUTIMAGE: r'''@noindent
 @ifinfo
-@image{%(info_image_path)s,,,%(alt)s,%(ext)s}
+@image{%(info_image_path)s,,,%(alt)s,}
 @end ifinfo
 @html
 <p>
@@ -200,22 +201,44 @@ def get_texinfo_width_indent (source, global_options):
     tmp_handle.close ()
 
     # Work around a texi2pdf bug: if LANG=C is not given, a broken regexp is
-    # used to detect relative/absolute pathes, so the absolute path is not
+    # used to detect relative/absolute paths, so the absolute path is not
     # detected as such and this command fails:
     progress (_ ("Running texi2pdf on file %s to detect default page settings.\n") % tmpfile);
 
     # execute the command and pipe stdout to the parameter_string:
-    cmd = 'LC_ALL=C %s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile);
-    if (global_options.verbose):
-        progress ("Executing: %s\n" % cmd);
-
-    proc = subprocess.Popen (cmd,
-        universal_newlines=True, shell=True,
-        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    (parameter_string, error_string) = proc.communicate ()
-    if proc.returncode != 0:
-        warning (_ ("Unable to auto-detect default settings:\n%s")
-                 % error_string)
+    cmd = '%s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile);
+    ly.debug_output ("Executing: %s\n" % cmd);
+    run_env = os.environ.copy()
+    run_env['LC_ALL'] = 'C'
+
+    ### unknown why this is necessary
+    universal_newlines = True
+    if sys.platform == 'mingw32':
+        universal_newlines = False
+        ### use os.system to avoid weird sleep() problems on
+        ### GUB's python 2.4.2 on mingw
+        # make file to write to
+        output_dir = tempfile.mkdtemp()
+        output_filename = os.path.join(output_dir, 'output.txt')
+        # call command
+        cmd += " > %s" % output_filename
+        returncode = os.system(cmd)
+        parameter_string = open(output_filename).read()
+        if returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n"))
+        # clean up
+        os.remove(output_filename)
+        os.rmdir(output_dir)
+    else:
+        proc = subprocess.Popen (cmd,
+            env=run_env,
+            universal_newlines=universal_newlines,
+            shell=True,
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        (parameter_string, error_string) = proc.communicate ()
+        if proc.returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n%s")
+                    % error_string)
     os.unlink (tmpfile)
     if os.path.exists(outfile):
         os.unlink (outfile)
@@ -245,8 +268,7 @@ def get_texinfo_width_indent (source, global_options):
         exampleindent = "0.4\\in"
 
     retval = {LINE_WIDTH: textwidth, EXAMPLEINDENT: exampleindent}
-    if (global_options.verbose):
-        progress ("Auto-detected values are: %s\n" % retval);
+    ly.debug_output ("Auto-detected values are: %s\n" % retval);
     return retval;
 
 
@@ -291,32 +313,30 @@ class BookTexinfoOutputFormat (BookBase.BookOutputFormat):
     def output_info (self, basename, snippet):
         str = ''
         rep = snippet.get_replacements ();
+        rep['base'] = basename
+        rep['filename'] = os.path.basename (snippet.filename)
+        rep['ext'] = snippet.ext
         for image in snippet.get_images ():
             rep1 = copy.copy (rep)
-            (rep1['base'], rep1['ext']) = os.path.splitext (image)
+            rep1['base'] = os.path.splitext (image)[0]
             rep1['image'] = image
-
-            # URG, makeinfo implicitly prepends dot to extension.
-            # Specifying no extension is most robust.
-            rep1['ext'] = ''
             rep1['alt'] = snippet.option_dict[ALT]
             rep1['info_image_path'] = os.path.join (self.global_options.info_images_dir, rep1['base'])
             str += self.output[OUTPUTIMAGE] % rep1
 
-        rep['base'] = basename
         str += self.output[OUTPUT] % rep
         return str
 
     def snippet_output (self, basename, snippet):
-        str = self.output_print_filename (basename, snippet)
+        str = ''
         base = basename
         if DOCTITLE in snippet.option_dict:
             doctitle = base + '.doctitle'
             translated_doctitle = doctitle + self.document_language
             if os.path.exists (translated_doctitle):
-                str += '@lydoctitle %s\n\n' % open (translated_doctitle).read ()
+                str += '\n@lydoctitle %s\n\n' % open (translated_doctitle).read ()
             elif os.path.exists (doctitle):
-                str += '@lydoctitle %s\n\n' % open (doctitle).read ()
+                str += '\n@lydoctitle %s\n\n' % open (doctitle).read ()
         if TEXIDOC in snippet.option_dict:
             texidoc = base + '.texidoc'
             translated_texidoc = texidoc + self.document_language
@@ -324,6 +344,7 @@ class BookTexinfoOutputFormat (BookBase.BookOutputFormat):
                 str += '@include %(translated_texidoc)s\n\n' % vars ()
             elif os.path.exists (texidoc):
                 str += '@include %(texidoc)s\n\n' % vars ()
+        str += self.output_print_filename (basename, snippet)
 
         substr = ''
         rep = snippet.get_replacements ();