Refactor error construction into a common method.
This commit is contained in:
parent
8a5c8ffbc9
commit
8ca2ff5dad
@ -242,24 +242,14 @@ class ArgParser:
|
|||||||
try:
|
try:
|
||||||
options, leftargs = getopt.getopt(self.args[1:],
|
options, leftargs = getopt.getopt(self.args[1:],
|
||||||
SHORTOPTS, LONGOPTS)
|
SHORTOPTS, LONGOPTS)
|
||||||
except getopt.GetoptError as error:
|
except getopt.GetoptError as getopt_error:
|
||||||
# Extract the arguments in the list.
|
self.errors.append(
|
||||||
cli_args = "[ %s ]" % " ".join(self.args[1:])
|
self.construct_error(
|
||||||
|
|
||||||
# The % operator replaces the list elements
|
|
||||||
# with repr() of the list elements
|
|
||||||
# which is OK for latin characters,
|
|
||||||
# but not for non latin characters in list elements
|
|
||||||
translated_error_message = _(
|
|
||||||
"Error parsing the arguments: %s \n"
|
|
||||||
"Type gramps --help for an overview of "
|
"Type gramps --help for an overview of "
|
||||||
"commands, or read the manual pages."
|
"commands, or read the manual pages.",
|
||||||
) % cli_args
|
error=getopt_error
|
||||||
|
)
|
||||||
self.errors += [(
|
)
|
||||||
_('Error parsing the arguments'),
|
|
||||||
str(error) + '\n' + translated_error_message
|
|
||||||
)]
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -460,22 +450,33 @@ class ArgParser:
|
|||||||
or self.list_more
|
or self.list_more
|
||||||
or self.list_table
|
or self.list_table
|
||||||
or self.help)):
|
or self.help)):
|
||||||
# Extract and convert to unicode the arguments in the list.
|
self.errors.append(
|
||||||
# The % operator replaces the list elements with repr() of
|
self.construct_error(
|
||||||
# the list elements, which is OK for latin characters
|
|
||||||
# but not for non-latin characters in list elements
|
|
||||||
cliargs = "[ "
|
|
||||||
for arg in range(len(self.args) - 1):
|
|
||||||
cliargs += self.args[arg + 1] + ' '
|
|
||||||
cliargs += "]"
|
|
||||||
self.errors += [(_('Error parsing the arguments'),
|
|
||||||
_("Error parsing the arguments: %s \n"
|
|
||||||
"To use in the command-line mode, supply at "
|
"To use in the command-line mode, supply at "
|
||||||
"least one input file to process."
|
"least one input file to process."
|
||||||
) % cliargs)]
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if need_to_quit:
|
if need_to_quit:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
def construct_error(self, suggestion_message, error=None):
|
||||||
|
# Extract the arguments in the list.
|
||||||
|
cli_args = "[ %s ]" % " ".join(self.args[1:])
|
||||||
|
|
||||||
|
# The % operator replaces the list elements
|
||||||
|
# with repr() of the list elements
|
||||||
|
# which is OK for latin characters,
|
||||||
|
# but not for non latin characters in list elements
|
||||||
|
error_message = "Error parsing the arguments: %s \n"
|
||||||
|
translated_message = _(error_message + suggestion_message) % cli_args
|
||||||
|
|
||||||
|
if error:
|
||||||
|
translated_message = str(error) + '\n' + translated_message
|
||||||
|
|
||||||
|
return _('Error parsing the arguments'), translated_message
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
# Determine the need for GUI
|
# Determine the need for GUI
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user