From 41b97edb037f39a8294abb803b6d1c8febf8338f Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Tue, 26 Sep 2017 16:07:41 +0200 Subject: [PATCH] Try to handle OSError when we use the --export argument in CLI mode. Fixes #08835 --- gramps/cli/argparser.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gramps/cli/argparser.py b/gramps/cli/argparser.py index 337cf113a..6fb8b65df 100644 --- a/gramps/cli/argparser.py +++ b/gramps/cli/argparser.py @@ -35,6 +35,7 @@ Module responsible for handling the command line arguments for Gramps. # #------------------------------------------------------------------------- import sys +import os import getopt import logging @@ -290,6 +291,21 @@ class ArgParser: if (opt_ix < len(options) - 1 and options[opt_ix + 1][0] in ('-f', '--format')): family_tree_format = options[opt_ix + 1][1] + abs_name = os.path.abspath(os.path.expanduser(value)) + if not os.path.exists(abs_name): + # The file doesn't exists, try to create it. + try: + open(abs_name, 'w').close() + unlink(abs_name) + except OSError as e: + message = _("WARNING: %(strerr)s " + "(errno=%(errno)s):\n" + "WARNING: %(name)s\n") % { + 'strerr' : e.strerror, + 'errno' : e.errno, + 'name' : e.filename} + print(message) + sys.exit(1) self.exports.append((value, family_tree_format)) elif option in ['-a', '--action']: action = value