annotate abcfield.py @ 385:30a9bef6c3e1

Added tag build-default-171 for changeset 8d574b900e36
author Jenkins Build Manager <jenkins@cryhavoc.org.uk>
date Sat, 31 Aug 2013 00:20:51 +0100
parents 27f29e8aafea
children 760d0ae5acea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
1 #!/usr/bin/env python
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
2 #
122
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
3 # Extact a text field (title, by default) from a .abc file, and print it out
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
4 # formatted for use in LaTeX or HTML.
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
5 #
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
6
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
7 import optparse
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
8 import sys
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
9
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
10 accentedletters = {
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
11 # Acute accents
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
12 "'A" : ("&Aacute;", "\\'{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
13 "'E" : ("&Eacute;", "\\'{E}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
14 "'I" : ("&Iacute;", "\\'{I}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
15 "'O" : ("&Oacute;", "\\'{O}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
16 "'U" : ("&Uacute;", "\\'{U}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
17 "'Y" : ("&Yacute;", "\\'{Y}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
18 "'a" : ("&aacute;", "\\'{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
19 "'e" : ("&eacute;", "\\'{e}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
20 "'i" : ("&iacute;", "\\'{i}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
21 "'o" : ("&oacute;", "\\'{o}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
22 "'u" : ("&uacute;", "\\'{u}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
23 "'y" : ("&yacute;", "\\'{y}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
24
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
25 # Grave accents
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
26 "`A" : ("&Agrave;", "\\`{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
27 "`E" : ("&Egrave;", "\\`{E}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
28 "`I" : ("&Igrave;", "\\`{I}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
29 "`O" : ("&Ograve;", "\\`{O}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
30 "`U" : ("&Ugrave;", "\\`{U}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
31 "`a" : ("&agrave;", "\\`{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
32 "`e" : ("&egrave;", "\\`{e}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
33 "`i" : ("&igrave;", "\\`{i}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
34 "`o" : ("&ograve;", "\\`{o}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
35 "`u" : ("&ugrave;", "\\`{u}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
36
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
37 # Umlauts
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
38 "\"A" : ("&Auml;", "\\\"{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
39 "\"E" : ("&Euml;", "\\\"{E}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
40 "\"I" : ("&Iuml;", "\\\"{I}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
41 "\"O" : ("&Ouml;", "\\\"{O}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
42 "\"U" : ("&Uuml;", "\\\"{U}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
43 "\"Y" : ("&Yuml;", "\\\"{Y}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
44 "\"a" : ("&auml;", "\\\"{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
45 "\"e" : ("&euml;", "\\\"{e}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
46 "\"i" : ("&iuml;", "\\\"{\i}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
47 "\"o" : ("&ouml;", "\\\"{o}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
48 "\"u" : ("&uuml;", "\\\"{u}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
49 "\"y" : ("&yuml;", "\\\"{y}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
50
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
51 # Circumflexes
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
52 "^A" : ("&Acirc;", "\\^{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
53 "^E" : ("&Ecirc;", "\\^{E}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
54 "^I" : ("&Icirc;", "\\^{I}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
55 "^O" : ("&Ocirc;", "\\^{O}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
56 "^U" : ("&Ucirc;", "\\^{U}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
57 "^a" : ("&acirc;", "\\^{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
58 "^e" : ("&ecirc;", "\\^{e}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
59 "^i" : ("&icirc;", "\\^{\i}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
60 "^o" : ("&ocirc;", "\\^{o}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
61 "^u" : ("&ucirc;", "\\^{u}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
62
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
63 # Tilde
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
64 "~A" : ("&Atilde;", "\\~{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
65 "~N" : ("&Ntilde;", "\\~{N}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
66 "~O" : ("&Otilde;", "\\~{O}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
67 "~a" : ("&atilde;", "\\~{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
68 "~n" : ("&ntilde;", "\\~{n}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
69 "~o" : ("&otilde;", "\\~{o}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
70
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
71 # Cedilla
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
72 ",C" : ("&Ccedil;", "\\c{C}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
73 ",c" : ("&ccedil;", "\\c{c}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
74
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
75 # Slash
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
76 "/O" : ("&Oslash;", "\\O"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
77 "/o" : ("&oslash;", "\\o"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
78
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
79 # Ring
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
80 "AA" : ("&Aring;", "\\r{A}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
81 "aa" : ("&aring;", "\\r{a}"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
82
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
83 # Ligatures
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
84 "AE" : ("&AElig;", "\\AE"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
85 "ae" : ("&aelig;", "\\ae"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
86 "ss" : ("&szlig;", "\\ss"),
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
87 }
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
88
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
89 def convertTitle(t, options):
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
90 res = ""
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
91 while True:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
92 p = t.partition('\\')
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
93 res += p[0]
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
94 if p[1] == "":
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
95 break
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
96 abc = p[2][0:2]
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
97 t = p[2][2:]
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
98 if (options.html or options.latex) and abc in accentedletters:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
99 if options.html:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
100 res += accentedletters[abc][0]
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
101 else:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
102 res += accentedletters[abc][1]
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
103 else:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
104 res += "\\" + abc
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
105 return res
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
106
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
107 def process(inf, options):
316
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
108 n = options.index
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
109 for line in inf:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
110 line = line.strip()
122
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
111 if len(line) > 2 and line[0] == options.field and line[1] == ':':
326
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
112 if len(options.contains) > 0:
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
113 if line.find(options.contains) < 0:
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
114 continue
316
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
115 if n > 1:
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
116 n = n - 1
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
117 else:
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
118 print(convertTitle(line[2:].strip(), options))
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
119 break
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
120
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
121 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n"
122
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
122 " Extract field data from ABC file.")
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
123 parser.add_option("-f", "--field", dest="field", default="T",
295ba8275ab4 Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents: 110
diff changeset
124 help="extract the field FIELD", metavar="FIELD")
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
125 parser.add_option("-m", "--html", dest="html",
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
126 action="store_true", default=False,
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
127 help="format output for HTML")
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
128 parser.add_option("-l", "--latex", dest="latex",
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
129 action="store_true", default=False,
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
130 help="format ouput for LaTeX")
316
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
131 parser.add_option("-n", "--index", dest="index",
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
132 action="store", type="int", default=1,
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
133 help="report INDEXth value [default: %default]",
eedf65564226 Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents: 122
diff changeset
134 metavar="INDEX")
326
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
135 parser.add_option("-c", "--contains", dest="contains",
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
136 action="store", type="string", default="",
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
137 help="report only if line contains CONTENT",
27f29e8aafea Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents: 316
diff changeset
138 metavar="CONTENT")
110
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
139 (options, args) = parser.parse_args()
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
140
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
141 if options.html and options.latex:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
142 sys.exit("You must choose one of HTML or LaTeX output")
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
143
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
144 if len(args) > 0:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
145 for arg in args:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
146 try:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
147 inf = open(arg, "r")
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
148 process(inf, options)
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
149 finally:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
150 inf.close()
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
151 else:
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
152 process(sys.stdin, options)
a63e39fc3410 Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff changeset
153 sys.exit(0)