def start(argv): parser = argparse.ArgumentParser( description=DESCRIPTION, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "input_image", metavar="image.rat", type=argparse.FileType("rb"), nargs="?", default=stdiotobuffer(sys.stdin), help="input RAT image file", ) parser.add_argument( "output_image", metavar="image.ppm", type=argparse.FileType("wb"), nargs="?", default=stdiotobuffer(sys.stdout), help="output PPM image file", ) parser.add_argument( "--version", action="version", version="%(prog)s {}".format(__version__), ) args = parser.parse_args(argv) convert(args.input_image, args.output_image) args.output_image.close() args.input_image.close()
def start(argv): parser = argparse.ArgumentParser( description=DESCRIPTION, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "input_image", metavar="image.hrs", type=argparse.FileType("rb"), nargs="?", default=stdiotobuffer(sys.stdin), help="input HRS image file", ) parser.add_argument( "output_image", metavar="image.ppm", type=argparse.FileType("wb"), nargs="?", default=stdiotobuffer(sys.stdout), help="output PPM image file", ) parser.add_argument( "-w", dest="width", action="store", default=320, metavar="width", type=check_positive, help="choose different width (this does not assume bigger pixels)", ) parser.add_argument( "-r", dest="rows", action="store", default=192, metavar="height", type=check_positive, help="choose height not computed from header divided by width", ) parser.add_argument( "-s", dest="skip", action="store", default=None, metavar="bytes", type=check_zero_or_positive, help="skip some number of bytes", ) parser.add_argument( "--version", action="version", version="%(prog)s {}".format(__version__), ) args = parser.parse_args(argv) convert(args.input_image, args.output_image, args.width, args.rows, args.skip) args.output_image.close() args.input_image.close()
def test_stdiotobuffer(self): self.assertEqual(sys.stdin.buffer, stdiotobuffer(sys.stdin)) self.assertEqual(sys.stdout.buffer, stdiotobuffer(sys.stdout))
def start(argv): parser = argparse.ArgumentParser( description=DESCRIPTION, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "input_image", metavar="image", type=argparse.FileType("rb"), nargs="?", default=stdiotobuffer(sys.stdin), help="input image file", ) parser.add_argument( "output_image", metavar="image.ppm", type=argparse.FileType("wb"), nargs="?", default=stdiotobuffer(sys.stdout), help="output PPM image file", ) parser.add_argument( "--version", action="version", version="%(prog)s {}".format(__version__), ) pixel_mode_group = parser.add_argument_group( "pixel mode", description=PIXEL_MODE_DESCRIPTION) pixel_mode_parser = pixel_mode_group.add_mutually_exclusive_group() pixel_mode_parser.add_argument( "-br", dest="pixel_mode", action="store_const", const=PIXEL_MODE_BR, default=PIXEL_MODE_BW, help="PMODE 4 artifacts, cyan-blue first", ) pixel_mode_parser.add_argument( "-rb", dest="pixel_mode", action="store_const", const=PIXEL_MODE_RB, default=PIXEL_MODE_BW, help="PMODE 4 artifacts, orange-red first", ) pixel_mode_parser.add_argument( "-br2", dest="pixel_mode", action="store_const", const=PIXEL_MODE_BR2, default=PIXEL_MODE_BW, help="PMODE 3 Coco 3 cyan-blue first", ) pixel_mode_parser.add_argument( "-rb2", dest="pixel_mode", action="store_const", const=PIXEL_MODE_RB2, default=PIXEL_MODE_BW, help="PMODE 3 Coco 3 orange-red first", ) pixel_mode_parser.add_argument( "-br3", dest="pixel_mode", action="store_const", const=PIXEL_MODE_BR3, default=PIXEL_MODE_BW, help="PMODE 3 Coco 3 primary, blue first", ) pixel_mode_parser.add_argument( "-rb3", dest="pixel_mode", action="store_const", const=PIXEL_MODE_RB3, default=PIXEL_MODE_BW, help="PMODE 3 Coco 3 primary, red first", ) pixel_mode_parser.add_argument( "-s10", dest="pixel_mode", action="store_const", const=PIXEL_MODE_S10, default=PIXEL_MODE_BW, help="PMODE 3 SCREEN 1,0", ) pixel_mode_parser.add_argument( "-s11", dest="pixel_mode", action="store_const", const=PIXEL_MODE_S11, default=PIXEL_MODE_BW, help="PMODE 3 SCREEN 1,1", ) parser_mode_group = parser.add_argument_group( "Format and size options:", description=PARSER_MODE_DESCRIPTION) parser_mode_group.add_argument( "-i", dest="ignore_header_errors", action="store_true", default=False, help="ignore header errors (but read header anyway)", ) parser_mode_group.add_argument( "-w", dest="width", action="store", default=256, metavar="width", type=check_positive, help="choose different width (this does not assume bigger pixels)", ) parser_mode_group.add_argument( "-r", dest="rows", action="store", default=None, metavar="height", type=check_positive, help="choose height not computed from header divided by width", ) parser_mode_group.add_argument( "-s", dest="skip", action="store", default=None, metavar="bytes", type=check_zero_or_positive, help="skip header and assume it has the specified length", ) parser_mode_group.add_argument( "-newsroom", action="store_true", default=False, help="read Coco Newsroom / The Newspaper .ART header instead", ) args = parser.parse_args(argv) ok = convert( args.input_image, args.output_image, args.pixel_mode, args.newsroom, args.width, args.rows, args.skip, args.ignore_header_errors, ) args.output_image.close() args.input_image.close() if not ok: os.remove(args.output_image.name)