Set exit status on abcfield.py to indicate if anything found.

This commit is contained in:
Jim Hague 2016-10-29 23:18:45 +01:00
parent 07e6191f9c
commit 639f6f42df
1 changed files with 5 additions and 3 deletions

View File

@ -130,6 +130,7 @@ def process(inf, options):
continue continue
found = True found = True
print(convertField(line, options)) print(convertField(line, options))
return found
parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n"
" Extract field data from ABC file.") " Extract field data from ABC file.")
@ -148,13 +149,14 @@ parser.add_option("-s", "--starts", dest="starts",
metavar="CONTENT") metavar="CONTENT")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
res = False
if len(args) > 0: if len(args) > 0:
for arg in args: for arg in args:
try: try:
inf = open(arg, "r") inf = open(arg, "r")
process(inf, options) res = res or process(inf, options)
finally: finally:
inf.close() inf.close()
else: else:
process(sys.stdin, options) res = process(sys.stdin, options)
sys.exit(0) sys.exit(int(not res))