X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=stepmake%2Fbin%2Fls-latex.py;h=4279b73148dc9234319ca61f07ac8a76cdaf5f8a;hb=32cdc3e2bc738e82c0965bdc5d8d99830e929092;hp=e1995fc4cfe5d4c2c145ce9298b1602a68cae63f;hpb=1cf3d59c1559fb9774c4c1c8cae155cfe54a927c;p=lilypond.git diff --git a/stepmake/bin/ls-latex.py b/stepmake/bin/ls-latex.py index e1995fc4cf..4279b73148 100644 --- a/stepmake/bin/ls-latex.py +++ b/stepmake/bin/ls-latex.py @@ -7,198 +7,206 @@ version = '0.1' import sys import os -from string import * - +import string import __main__ import glob -import regex - -latex_author_re = regex.compile('\\author{\([^}]+\)}') -latex_title_re = regex.compile('\\title{\([^}]+\)}') +import re + +format_names = {'ps.gz': 'Compressed PostScript', + 'html' : 'HTML' + } + +def gulp_file(f): + try: + i = open(f) + i.seek (0, 2) + n = i.tell () + i.seek (0,0) + except: + sys.stderr.write ("can't open file: %s\n" % f) + return '' + s = i.read (n) + if len (s) <= 0: + sys.stderr.write ("gulped empty file: %s\n" % f) + i.close () + return s class Latex_head: - def __init__ (self): - self.author = '' - self.title = '' - self.date = '' - self.format = '' + def __init__ (self): + self.author = '' + self.title = '' + self.date = '' + self.format = '' + +def read_latex_header (s): + header = Latex_head() + m = re.search(r'\\author{([^}]+)}', s) + if m: + header.author = m.group (1) - -def read_latex_header (fn): - s = gulp_file (fn) - i = regex.search( '\\\\begin{document}', s) + m = re.search (r'\\title{([^}]+)}',s ) + if m: + header.title = m.group (1) + + header.formats = ['ps.gz'] + return header + + +def read_bib_header (s): + m = re.search ('% *AUTHOR *= *(.*)\n',s) + + header = Latex_head() + + if m: + header.author = m.group (1) + + m = re.search ('% *TITLE *= *(.*)\n',s ) + if m: + header.title = m.group (1) + + header.formats = ['html'] + return header + + +def read_pod_header (s): + header = Latex_head () + + i = re.search( '[^\n \t]', s) + s = s[i:] + i = re.search( '\n\n', s) + s = s[i+2:] + i = re.search( '\n\n', s) + header.title = s[:i] + + header.formats = ['html'] + return header - if i < 0: - sys.stderr.write( 'Huh? empty file?') - s = '\\author{(unknown)}\\title{(unknown)}' +def read_texinfo_header (s): + header = Latex_head () + + m = re.search( '@settitle (.*)\n', s) + if m: + header.title = m.group (1) + m = re.search( '@author (.*)\n', s) + if m: + header.author = m.group (1) - s = s[:i] - s = regsub.gsub('%.*$', '', s) - s = regsub.gsub('\n', ' ', s) - - header = Latex_head() - header.filename= fn; - - if latex_author_re.search (s) == -1 : - sys.stderr.write( 'huh? No author?') - header.author = 'unknown' - else: - header.author = latex_author_re.group (1) - if latex_title_re.search (s) == -1: - sys.stderr.write( 'huh? No title?') - header.title = 'unknown' - else: - header.title = latex_title_re.group (1) - header.outfile = fn - header.outfile = regsub.gsub ('\.latex$', '.ps.gz', header.outfile) - header.outfile = regsub.gsub ('\.tex$', '.ps.gz', header.outfile) - header.outfile = regsub.gsub ('\.doc$', '.ps.gz', header.outfile) - header.format = 'gzipped postscript' - return header - - -bib_author_re = regex.compile('% *AUTHOR *= *\(.*\)$') -bib_title_re = regex.compile('% *TITLE *= *\(.*\)$') - -def bib_header (fn): - s = gulp_file (fn) - if bib_author_re.search (s) == -1 : - sys.stderr.write ('gulped file: ' + fn + '\n') - raise 'huh?' - - header = Latex_head() - header.filename= fn; - header.author = bib_author_re.group (1) - if bib_title_re.search (s) == -1: - sys.stderr.write ('gulped file: ' + fn + '\n') - raise 'huh?' - header.title = bib_title_re.group (1) - header.outfile = regsub.gsub ( '\.bib$', '.html' , fn) - header.format = 'HTML' - return header - - -def read_pod_header (fn): - header = Latex_head () - s = gulp_file (fn) - i = regex.search( '[^\n \t]', s) - s = s[i:] - i = regex.search( '\n\n', s) - s = s[i+2:] - if i < 0: - sys.stderr.write ('gulped file: ' + fn + '\n') - raise 'huh?' - i = regex.search( '\n\n', s) - header.title = s[:i] - header.filename = fn - header.outfile = regsub.gsub ('\.pod$', '.html', fn) - return header - -def read_texinfo_header (fn): - header = Latex_head () - s = gulp_file (fn) - i = regex.search( '@node ', s) - s = s[i+5:] - i = regex.search( ',', s) - if i < 0: - sys.stderr.write ('gulped file: ' + fn + '\n') - raise 'huh?' - header.title = s[:i] - header.filename = fn - header.outfile = regsub.gsub ('\.texinfo$', '.html', fn) - header.format = 'HTML' - return header + header.formats = ['html', 'ps.gz'] + return header # urg -# should make a 'next_parens' -yo_article_re = regex.compile('article(\\([^)]*\\))[ \t\n]*(\\([^)]*\\))') -yo_report_re = regex.compile('report(\\([^)]*\\))[\t\n ]*(\\([^)]*\\))') -yo_sect_re = regex.compile('sect(\\([^)]*\\))') -yo_chap_re = regex.compile('sect(\\([^)]*\\))') - -def read_yo_header (fn): - header = Latex_head () - s = gulp_file (fn) - if 0: - pass - elif yo_report_re.search (s) <> -1: - header.author = yo_report_re.group(2) - header.title = yo_report_re.group(1) - elif yo_article_re.search (s) <> -1: - header.author = yo_article_re.group(2) - header.title = yo_article_re.group(1) - elif yo_chap_re.search (s) <> -1: - header.title = yo_chap_re.group (1) - elif yo_sect_re.search (s) <> -1: - header.title = yo_sect_re.group (1) - header.filename = fn - header.outfile = regsub.gsub ('\.yo$', '.html', fn) - header.format = 'HTML' - return header +# should make a 'next_parens ' +yo_article_re = re.compile ('article(\\([^)]*\\))[ \t\n]*(\\([^)]*\\))') +yo_report_re = re.compile ('report(\\([^)]*\\))[\t\n ]*(\\([^)]*\\))') +yo_sect_re = re.compile ('sect(\\([^)]*\\))') +yo_chapter_re = re.compile ('chapter(\\([^)]*\\))') + +def read_yodl_header (s): + header = Latex_head () + report = yo_report_re.search (s) + article = 0 + sect = 0 + chapter = 0 + if report: + header.author = report.group (2) + header.title = yo_report_re.group (1) + else: + article = yo_article_re.search (s) + if article: + header.author = article.group (2) + header.title = article.group (1) + else: + chapter = yo_chapter_re.search (s) + if chapter: + header.title = chapter.group (1) + else: + sect = yo_sect_re.search (s) + if sect: + header.title = sect.group (1) + + header.formats = ['html'] + return header def print_html_head (l,o,h): - pre =o + pre =o + + fn = pre + h.basename + + t = h.filename + if h.title : + t = t + ': '+ h.title + + l.write ('
  • %s ' % t) - l.write ('
  • %s (%s)' % (pre + h.outfile, h.title, h.format )) - if h.author: - l.write ('

    by %s

    ' % h.author) - l.write ('
  • \n') + if h.author: + l.write ('

    by %s

    ' % h.author) + + for f in h.formats: + l.write ('(%s)' % (fn, f, format_names [f])) + l.write ('\n') def help (): - sys.stdout.write ("Usage: ls-latex [OPTION]... FILE...\n" - "Generate html index file for FILE...\n\n" - + "Options:\n" - + " -h, --help print this help\n" - + " -p, --package=DIR specify package\n" - ) - sys.exit (0) + sys.stdout.write (r"""Usage: ls-latex [OPTIONS]... FILE... +Generate html index file for FILE... + +Options: +-h, --help print this help +""") + sys.exit (0) import getopt (options, files) = getopt.getopt(sys.argv[1:], - 'e:hp:', ['help', 'prefix=', 'package=', 'title=']) + 'e:h', ['help', 'prefix=', 'title=']) tex = '' output ='' pre = '' title = '' for opt in options: - o = opt[0] - a = opt[1] - if o == '--prefix': - pre = a - elif o == '--title': - title = a - elif o == '-h' or o == '--help': - help () - elif o == '-p' or o == '--package': - topdir = a - -sys.path.append (topdir + '/stepmake/bin') -from packagepython import * -package = Package (topdir) -packager = Packager () + o = opt[0] + a = opt[1] + if o == '--prefix': + pre = a + elif o == '--title': + title = a + elif o == '-h' or o == '--help': + help () + l = sys.stdout -l.write ('%s

    %s

    ')