Try to handle OSError when we use the --export argument in CLI mode.
Fixes #08835
This commit is contained in:
parent
c9eee3b471
commit
41b97edb03
@ -35,6 +35,7 @@ Module responsible for handling the command line arguments for Gramps.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import getopt
|
import getopt
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -290,6 +291,21 @@ class ArgParser:
|
|||||||
if (opt_ix < len(options) - 1
|
if (opt_ix < len(options) - 1
|
||||||
and options[opt_ix + 1][0] in ('-f', '--format')):
|
and options[opt_ix + 1][0] in ('-f', '--format')):
|
||||||
family_tree_format = options[opt_ix + 1][1]
|
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))
|
self.exports.append((value, family_tree_format))
|
||||||
elif option in ['-a', '--action']:
|
elif option in ['-a', '--action']:
|
||||||
action = value
|
action = value
|
||||||
|
Loading…
Reference in New Issue
Block a user