From 0e4a3a145b736f2666b63ee0eb5c791a73deae4a Mon Sep 17 00:00:00 2001 From: j Date: Wed, 25 Jan 2017 23:39:43 +0100 Subject: [PATCH] use argparse --- txt.js/txt.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/txt.js/txt.py b/txt.js/txt.py index f4db38b..6d81561 100755 --- a/txt.js/txt.py +++ b/txt.js/txt.py @@ -5,7 +5,7 @@ from __future__ import division import os from PIL import Image -from optparse import OptionParser +from argparse import ArgumentParser from ox.image import drawText, wrapText root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) @@ -75,18 +75,15 @@ def render(infile, outfile): def main(): - parser = OptionParser() - parser.add_option( - '-i', '--infile', dest='infile', help='txt file to be read' + parser = ArgumentParser() + parser.add_argument( + '-i', '--infile', dest='infile', help='txt file to be read', required=True ) - parser.add_option( - '-o', '--outfile', dest='outfile', help='jpg file to be written' + parser.add_argument( + '-o', '--outfile', dest='outfile', help='jpg file to be written', required=True ) - (options, args) = parser.parse_args() - if None in (options.infile, options.outfile): - parser.print_help() - else: - render(options.infile, options.outfile) + options = parser.parse_args() + render(options.infile, options.outfile) if __name__ == '__main__':