Mercurial > dottes
annotate abcfield.py @ 357:9aa6a0f09b19
Added tag build-default-158 for changeset 6d4b2dab5fcc
author | Jenkins Build Manager <jenkins@cryhavoc.org.uk> |
---|---|
date | Mon, 19 Aug 2013 10:31:23 +0100 |
parents | 27f29e8aafea |
children | 760d0ae5acea |
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" : ("Á", "\\'{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
13 "'E" : ("É", "\\'{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
14 "'I" : ("Í", "\\'{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
15 "'O" : ("Ó", "\\'{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
16 "'U" : ("Ú", "\\'{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
17 "'Y" : ("Ý", "\\'{Y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
18 "'a" : ("á", "\\'{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
19 "'e" : ("é", "\\'{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
20 "'i" : ("í", "\\'{i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
21 "'o" : ("ó", "\\'{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
22 "'u" : ("ú", "\\'{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
23 "'y" : ("ý", "\\'{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" : ("À", "\\`{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
27 "`E" : ("È", "\\`{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
28 "`I" : ("Ì", "\\`{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
29 "`O" : ("Ò", "\\`{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
30 "`U" : ("Ù", "\\`{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
31 "`a" : ("à", "\\`{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
32 "`e" : ("è", "\\`{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
33 "`i" : ("ì", "\\`{i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
34 "`o" : ("ò", "\\`{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
35 "`u" : ("ù", "\\`{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" : ("Ä", "\\\"{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
39 "\"E" : ("Ë", "\\\"{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
40 "\"I" : ("Ï", "\\\"{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
41 "\"O" : ("Ö", "\\\"{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
42 "\"U" : ("Ü", "\\\"{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
43 "\"Y" : ("Ÿ", "\\\"{Y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
44 "\"a" : ("ä", "\\\"{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
45 "\"e" : ("ë", "\\\"{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
46 "\"i" : ("ï", "\\\"{\i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
47 "\"o" : ("ö", "\\\"{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
48 "\"u" : ("ü", "\\\"{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
49 "\"y" : ("ÿ", "\\\"{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" : ("Â", "\\^{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
53 "^E" : ("Ê", "\\^{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
54 "^I" : ("Î", "\\^{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
55 "^O" : ("Ô", "\\^{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
56 "^U" : ("Û", "\\^{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
57 "^a" : ("â", "\\^{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
58 "^e" : ("ê", "\\^{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
59 "^i" : ("î", "\\^{\i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
60 "^o" : ("ô", "\\^{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
61 "^u" : ("û", "\\^{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" : ("Ã", "\\~{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
65 "~N" : ("Ñ", "\\~{N}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
66 "~O" : ("Õ", "\\~{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
67 "~a" : ("ã", "\\~{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
68 "~n" : ("ñ", "\\~{n}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
69 "~o" : ("õ", "\\~{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" : ("Ç", "\\c{C}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
73 ",c" : ("ç", "\\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" : ("Ø", "\\O"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
77 "/o" : ("ø", "\\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" : ("Å", "\\r{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
81 "aa" : ("å", "\\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" : ("Æ", "\\AE"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
85 "ae" : ("æ", "\\ae"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
86 "ss" : ("ß", "\\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) |