[ocrfeeder] Use ArgumentParser instead of OptionParser
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Use ArgumentParser instead of OptionParser
- Date: Sun, 11 Mar 2018 13:37:59 +0000 (UTC)
commit fcb0fa3ea15e9fe6cb94e41243ab2560249631dc
Author: Joaquim Rocha <me joaquimrocha com>
Date: Sat Jul 16 21:54:31 2016 +0100
Use ArgumentParser instead of OptionParser
This is in order to use argument lists in a saner way (without repeating
the option).
src/ocrfeeder/studio/studioBuilder.py | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index 8e1ed01..062ab01 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -37,7 +37,7 @@ from ocrfeeder.feeder.documentGeneration import DocumentGeneratorManager
from ocrfeeder.util.configuration import ConfigurationManager
from ocrfeeder.util.asyncworker import AsyncItem
from ocrfeeder.util.log import debug
-from optparse import OptionParser
+from argparse import ArgumentParser
import gettext
import locale
from gi.repository import Gdk, Gtk
@@ -122,23 +122,21 @@ class Studio:
self.main_window.setHeader(menubar_callback_dict, toolbar_callback_dict)
self.main_window.setDestroyEvent(self.quit)
- parser = OptionParser(version = '%prog ' + OCRFEEDER_STUDIO_VERSION)
- parser.add_option('-i', '--images', dest = 'images',
- action = 'append', type = 'string',
- metavar = 'IMAGE1 [IMAGE2, ...]', default = [],
- help = 'images to be automatically added on start-up. '
- 'Use the option before every image path.')
- parser.add_option('-d', '--dir', dest = 'directory',
- action = 'store', type = 'string',
- help = 'directory with images to be added'
- ' automatically on start-up')
- options, args = parser.parse_args()
- imgs = options.images
+ parser = ArgumentParser(description=OCRFEEDER_STUDIO_COMMENTS)
+ parser.add_argument('-i', '--images', metavar='IMAGE1 [IMAGE2, ...]',
+ nargs='+', help='images to be automatically added '
+ 'on start-up. Use the option before every image '
+ 'path.')
+ parser.add_argument('-d', '--dir', help='directory with images to be '
+ 'added automatically on start-up')
+ parser.add_argument('-v', '--version', action='version',
+ version='%(prog)s ' + OCRFEEDER_STUDIO_VERSION)
+ args = parser.parse_args()
+ imgs = args.images
if imgs:
self.__addImagesToReviewer(imgs)
- if options.directory:
- self.__addImagesToReviewer(
- lib.getImagesFromFolder(options.directory))
+ if args.dir:
+ self.__addImagesToReviewer(lib.getImagesFromFolder(args.dir))
self.main_window.setHasSelectedBoxes(False)
self.main_window.setHasContentBoxes(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]