X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fly2dvi.py;h=1c5c6208ebd2888fe4055f8eeb4f24d4794ea9d1;hb=c13af663039da02ae29256f99dbd8fc5debd5b55;hp=8c418aa6c84bd17a3a263f05807b5415a0a45849;hpb=9a7a808b7c7abcacd08f4c992f75394cc4543d2e;p=lilypond.git diff --git a/scripts/ly2dvi.py b/scripts/ly2dvi.py index 8c418aa6c8..1c5c6208eb 100644 --- a/scripts/ly2dvi.py +++ b/scripts/ly2dvi.py @@ -6,7 +6,7 @@ # # source file of the GNU LilyPond music typesetter # -# (c) 1998--2002 Han-Wen Nienhuys +# (c) 1998--2003 Han-Wen Nienhuys # Jan Nieuwenhuizen # This is the third incarnation of ly2dvi. @@ -39,7 +39,6 @@ TODO: * for foo.ly, rename ly2dvi.dir to out-ly2dvi, foo.ly2dvi, foo.dir ? - * move versatile taglines, \header { @@ -74,6 +73,7 @@ import operator import stat import string import traceback +import glob ################################################################ # Users of python modules should include this snippet @@ -95,6 +95,7 @@ if os.environ.has_key ('LILYPONDPREFIX') : while datadir[-1] == os.sep: datadir= datadir[:-1] + sys.path.insert (0, os.path.join (datadir, 'python')) # Customize these @@ -106,6 +107,7 @@ global re;re = ly.re # lilylib globals program_name = 'ly2dvi' +program_version = '@TOPLEVEL_VERSION@' verbose_p = 0 pseudo_filter_p = 0 original_dir = os.getcwd () @@ -118,43 +120,50 @@ debug_p = 0 ## ly2dvi: silly name? ## do -P or -p by default? ##help_summary = _ ("Run LilyPond using LaTeX for titling") -help_summary = _ ("Run LilyPond, add titles, generate printable document") +help_summary = _ ("Run LilyPond, add titles, generate printable document.") copyright = ('Han-Wen Nienhuys > 8 + exit_status = status >> 8 if exit_status: @@ -503,21 +517,25 @@ None ly.exit (1) if preview_p: - # make a preview by rendering only the 1st line. - preview_fn = outbase + '.preview.tex' - f = open (preview_fn, 'w') - wfs = find_tex_files (files, extra) - s = global_latex_definition (wfs, extra) - - s = re.sub ('thispagestyle{firstpage}', r'''thispagestyle{empty}% -\\def\\interscoreline{\\endinput}''',s ) - s = re.sub ('thispagestyle{lastpage}', r'''thispagestyle{empty}% -\\def\\interscoreline{\\endinput}''',s ) - f.write (s) - f.close() - cmd = '%s \\\\nonstopmode \\\\input %s' % (latex_cmd, preview_fn) - ly.system (cmd) - + # make a preview by rendering only the 1st line + # of each score + for score in find_tex_files (files, extra): + preview_base = ly.strip_extension (score[0], '.tex') + preview_fn = preview_base + '.preview.tex' + s = global_latex_definition ((score,), extra) + s = re.sub ('thispagestyle{firstpage}', + r'''thispagestyle{empty}% + \\def\\interscoreline{\\endinput}''', s) + s = re.sub ('thispagestyle{lastpage}', + r'''thispagestyle{empty}% + \\def\\interscoreline{\\endinput}''', s) + f = open (preview_fn, 'w') + f.write (s) + f.close () + cmd = '%s \\\\nonstopmode \\\\input %s' \ + % (latex_cmd, preview_fn) + ly.system (cmd) + def run_dvips (outbase, extra): @@ -548,7 +566,7 @@ None. pass if pfa_file: - opts = opts + ' -Ppdf -G0 -u lilypond.map' + opts = opts + ' -Ppdf -G0 -u +lilypond.map' else: ly.warning (_ ('''Trying create PDF, but no PFA fonts found. Using bitmap fonts instead. This will look bad.''')) @@ -557,8 +575,12 @@ Using bitmap fonts instead. This will look bad.''')) ly.system (cmd) if preview_p: - cmd = 'dvips -E -o%s %s' % ( outbase + '.preview.ps', outbase + '.preview.dvi') - ly.system (cmd) + for score in find_tex_files (files, extra): + preview_base = ly.strip_extension (score[0], '.tex') + cmd = 'dvips -E -o%s %s' \ + % (preview_base + '.preview.ps', + preview_base + '.preview.dvi') + ly.system (cmd) if 'PDF' in targets: cmd = 'ps2pdf %s.ps %s.pdf' % (outbase , outbase) @@ -604,7 +626,48 @@ def find_pfa_fonts (name): m = re.match ('.*?/(feta[-a-z0-9]+) +findfont', s[here:], re.DOTALL) return pfa + +def make_html_menu_file (html_file, files_found): + exts = { + 'pdf' : "Print (PDF, %s)", + 'ps.gz' : "Print (gzipped PostScript, %s)", + 'png' : "View (PNG, %s)", + 'midi' : "Listen (MIDI, %s)", + 'ly' : "View source code (%s)", + } + html_str = '' + + pages = filter (lambda x : re.search ('page[0-9]+.png', x), + files_found) + rest = filter (lambda x : not re.search ('page[0-9]+.png', x), + files_found) + + preview = filter (lambda x: re.search ('.png$', x), rest) + if preview: + html_str = '' % preview[0] + + for p in pages: + page = re.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p) + page = page % 'unknown size' + + html_str += '
  • %s' % (p, page) + + + for e in ['pdf', 'ps.gz', 'midi', 'ly']: + fs = filter (lambda x: re.search ('.%s$' % e, x), rest) + for f in fs: + entry = exts[e] % 'unknown size' # todo + html_str += '
  • %s\n\n' % (f, entry) + + html_str += "\n\n
  • " + ly.progress (_("Writing HTML menu `%s'") % html_file) + ly.progress ('\n') + open (html_file, 'w').write (html_str) +################################################################ +## MAIN +################################################################ + (sh, long) = ly.getopt_args (option_definitions) try: (options, files) = getopt.getopt (sys.argv[1:], sh, long) @@ -647,7 +710,8 @@ for opt in options: lily_p = 0 elif o == '--preview': preview_p = 1 - targets.append ('PNG') + if 'PNG' not in targets: + targets.append ('PNG') elif o == '--preview-resolution': preview_resolution = string.atoi (a) elif o == '--no-paper' or o == '-m': @@ -676,6 +740,14 @@ for opt in options: if status: ly.warranty () sys.exit (0) + elif o == '--html': + html_p = 1 + elif o == '--png': + page_images_p = 1 + if 'PNG' not in targets: + targets.append ('PNG') + elif o == '--psgz': + targets.append ('PS.GZ') else: unimplemented_option () # signal programming error @@ -710,6 +782,8 @@ if not files: if 1: ly.identify (sys.stderr) + ly.lilypond_version_check (lilypond_binary, '@TOPLEVEL_VERSION@') + original_output = output_name # Ugh, maybe make a setup () function @@ -779,6 +853,9 @@ if 1: # have subsequent stages and use 'lelie' output. if pseudo_filter_p: files[0] = 'lelie' + + if 'PS.GZ' in targets: + targets.append ('PS') if 'PNG' in targets and 'PS' not in targets: targets.append ('PS') @@ -813,8 +890,12 @@ if 1: else: ly.warning (_("Failed to make PS file. Rerun with --verbose for a trace.")) - if 'PNG' in targets: - ly.make_preview (outbase) + if preview_p: + for score in find_tex_files (files, extra_init): + preview_base = ly.strip_extension (score[0], '.tex') + ly.make_ps_images (preview_base + '.preview.ps', + resolution=preview_resolution + ) if 'PDFTEX' in targets: try: @@ -837,8 +918,12 @@ if 1: if verbose_p: traceback.print_exc () else: - ly.warning (_("Running LaTeX falied. Rerun with --verbose for a trace.")) + ly.warning (_("Running LaTeX failed. Rerun with --verbose for a trace.")) + if page_images_p: + ly.make_ps_images (outbase + '.ps' , + resolution = preview_resolution + ) # add DEP to targets? if track_dependencies_p: @@ -846,7 +931,7 @@ if 1: generate_dependency_file (depfile, depfile) if os.path.isfile (depfile): ly.progress (_ ("dependencies output to `%s'...") % - depfile) + depfile) ly.progress ('\n') if pseudo_filter_p: @@ -865,20 +950,34 @@ if 1: targets = [] ly.progress ('\n') + if 'PS.GZ' in targets: + ly.system ("gzip *.ps") + targets.remove ('PS') + # Hmm, if this were a function, we could call it the except: clauses + files_found = [] for i in targets: ext = string.lower (i) + + pattern = '%s.%s' % (outbase, ext) + if i == 'PNG': + pattern = '*.png' + ls = glob.glob (pattern) + files_found += ls ly.cp_to_dir ('.*\.%s$' % ext, outdir) - outname = outbase + '.' + string.lower (i) - abs = os.path.join (outdir, outname) - if reldir != '.': - outname = os.path.join (reldir, outname) - if os.path.isfile (abs): - ly.progress (_ ("%s output to `%s'...") % (i, outname)) + + + if ls: + names = string.join (map (lambda x: "`%s'" % x, ls)) + ly.progress (_ ("%s output to %s...") % (i, names)) ly.progress ('\n') elif verbose_p: - ly.warning (_ ("can't find file: `%s'") % outname) - + ly.warning (_ ("can't find file: `%s.%s'") % (outbase, ext)) + + if html_p: + make_html_menu_file (os.path.join (outdir, outbase + ".html"), + files_found) + os.chdir (original_dir) ly.cleanup_temp ()