Mercurial > dottes
comparison abcfield.py @ 316:eedf65564226
Add --index parameter to allow selection of nth occurence of field.
author | Jim Hague <jim.hague@acm.org> |
---|---|
date | Tue, 16 Jul 2013 16:25:30 +0100 |
parents | 295ba8275ab4 |
children | 27f29e8aafea |
comparison
equal
deleted
inserted
replaced
315:b4d568b70c33 | 316:eedf65564226 |
---|---|
103 else: | 103 else: |
104 res += "\\" + abc | 104 res += "\\" + abc |
105 return res | 105 return res |
106 | 106 |
107 def process(inf, options): | 107 def process(inf, options): |
108 n = options.index | |
108 for line in inf: | 109 for line in inf: |
109 line = line.strip() | 110 line = line.strip() |
110 if len(line) > 2 and line[0] == options.field and line[1] == ':': | 111 if len(line) > 2 and line[0] == options.field and line[1] == ':': |
111 print(convertTitle(line[2:].strip(), options)) | 112 if n > 1: |
112 break | 113 n = n - 1 |
114 else: | |
115 print(convertTitle(line[2:].strip(), options)) | |
116 break | |
113 | 117 |
114 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" | 118 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" |
115 " Extract field data from ABC file.") | 119 " Extract field data from ABC file.") |
116 parser.add_option("-f", "--field", dest="field", default="T", | 120 parser.add_option("-f", "--field", dest="field", default="T", |
117 help="extract the field FIELD", metavar="FIELD") | 121 help="extract the field FIELD", metavar="FIELD") |
119 action="store_true", default=False, | 123 action="store_true", default=False, |
120 help="format output for HTML") | 124 help="format output for HTML") |
121 parser.add_option("-l", "--latex", dest="latex", | 125 parser.add_option("-l", "--latex", dest="latex", |
122 action="store_true", default=False, | 126 action="store_true", default=False, |
123 help="format ouput for LaTeX") | 127 help="format ouput for LaTeX") |
128 parser.add_option("-n", "--index", dest="index", | |
129 action="store", type="int", default=1, | |
130 help="report INDEXth value [default: %default]", | |
131 metavar="INDEX") | |
124 (options, args) = parser.parse_args() | 132 (options, args) = parser.parse_args() |
125 | 133 |
126 if options.html and options.latex: | 134 if options.html and options.latex: |
127 sys.exit("You must choose one of HTML or LaTeX output") | 135 sys.exit("You must choose one of HTML or LaTeX output") |
128 | 136 |