X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/ecc0929cb0e011db2825e79d7495d7ef7b113e1e..eb3c787367efefbba1ddf077d3a589468b77d2d1:/imago_pack/imago.py?ds=inline diff --git a/imago_pack/imago.py b/imago_pack/imago.py index 33e7c69..e2c2876 100755 --- a/imago_pack/imago.py +++ b/imago_pack/imago.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -"""Go image recognition""" +"""Go image recognition.""" import sys import os @@ -19,9 +19,7 @@ import manual import intrsc import gridf -def main(): - """Main function of the program.""" - +def argument_parser(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('files', metavar='file', nargs='+', help="image to analyse") @@ -37,8 +35,17 @@ def main(): help="save images instead of displaying them") parser.add_argument('-c', '--cache', dest='l_cache', action='store_true', help="use cached lines") + parser.add_argument('-S', '--sgf', dest='sgf_output', action='store_true', + help="output in SGF") parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help="report progress") + return parser + + +def main(): + """Main function of the program.""" + + parser = argument_parser() args = parser.parse_args() show_all = args.show_all @@ -96,11 +103,14 @@ def main(): board = intrsc.board(image, lines, show_all, do_something) - #simple ASCII output: - for line in board: - print ' '.join(line) + if len(args.files) == 1: + + if args.sgf_output: + print board.asSGFsetPos() + else: + print board - if len(args.files) > 1: + else: for f in args.files[1:]: try: image = Image.open(f) @@ -133,6 +143,6 @@ class Imsave(): if __name__ == '__main__': try: sys.exit(main()) - except KeyboardInterrupt: + except KeyboardInterrupt: #TODO does this work? print "Interrupted." - sys.exit() + sys.exit(1)