From 35944ee7c4dfd59d4d98e7f16e5bfff4e669bb4d Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 10 Jan 2007 20:35:24 -0800 Subject: [PATCH] Add option to run editor Add a command line option to run the system-default editor on the dictionary of definitions. Signed-off-by: Ira W. Snyder --- animesorter2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/animesorter2.py b/animesorter2.py index 87eaa3c..2e185eb 100755 --- a/animesorter2.py +++ b/animesorter2.py @@ -89,7 +89,7 @@ class AnimeSorter2: f.close() except IOError: logging.critical ('Opening dictionary: %s FAILED' % self.options.dict_file) - sys.exit() + sys.exit(1) ### Find all of the valid lines in the file valid_lines = [l for l in raw_lines if self.__valid_dict_line (l)] @@ -260,6 +260,8 @@ def main(): help='Confirm each move', action='store_true') parser.add_option('-p', '--pretend', dest='pretend', default=False, help='Enable pretend mode', action='store_true') + parser.add_option('-e', '--editor', dest='run_editor', default=False, + help='Run editor on dictionary', action='store_true') ## Parse the options (options, args) = parser.parse_args() @@ -269,6 +271,18 @@ def main(): options.start_dir = os.path.abspath(os.path.expanduser(options.start_dir)) options.output_dir = os.path.abspath(os.path.expanduser(options.output_dir)) + ## Run editor if necessary + if options.run_editor: + editor = os.getenv ('EDITOR') + + if editor != None: + os.system ('%s %s' % (editor, options.dict_file)) + else: + logging.critical ('Default editor could not be found!') + sys.exit (1) + + sys.exit (0) # successful, but exit anyway + # Change the loglevel if we're running in quiet mode if options.quiet: logging.getLogger().setLevel (logging.CRITICAL) -- 2.25.1