Mercurial > dottes
comparison abcfield.py @ 584:696c461c8dc0
Set exit status on abcfield.py to indicate if anything found.
| author | Jim Hague <jim.hague@acm.org> |
|---|---|
| date | Sat, 29 Oct 2016 23:18:45 +0100 |
| parents | 760d0ae5acea |
| children | daa3b76bd11f |
comparison
equal
deleted
inserted
replaced
| 582:0206ab9fd6ba | 584:696c461c8dc0 |
|---|---|
| 128 continue | 128 continue |
| 129 else: | 129 else: |
| 130 continue | 130 continue |
| 131 found = True | 131 found = True |
| 132 print(convertField(line, options)) | 132 print(convertField(line, options)) |
| 133 return found | |
| 133 | 134 |
| 134 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" | 135 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" |
| 135 " Extract field data from ABC file.") | 136 " Extract field data from ABC file.") |
| 136 parser.add_option("-f", "--field", dest="field", default="T", | 137 parser.add_option("-f", "--field", dest="field", default="T", |
| 137 help="extract the field FIELD", metavar="FIELD") | 138 help="extract the field FIELD", metavar="FIELD") |
| 146 action="store", type="string", default="", | 147 action="store", type="string", default="", |
| 147 help="report only if line starts CONTENT and remove CONTENT", | 148 help="report only if line starts CONTENT and remove CONTENT", |
| 148 metavar="CONTENT") | 149 metavar="CONTENT") |
| 149 (options, args) = parser.parse_args() | 150 (options, args) = parser.parse_args() |
| 150 | 151 |
| 152 res = False | |
| 151 if len(args) > 0: | 153 if len(args) > 0: |
| 152 for arg in args: | 154 for arg in args: |
| 153 try: | 155 try: |
| 154 inf = open(arg, "r") | 156 inf = open(arg, "r") |
| 155 process(inf, options) | 157 res = res or process(inf, options) |
| 156 finally: | 158 finally: |
| 157 inf.close() | 159 inf.close() |
| 158 else: | 160 else: |
| 159 process(sys.stdin, options) | 161 res = process(sys.stdin, options) |
| 160 sys.exit(0) | 162 sys.exit(int(not res)) |
