Unicode conversion of command line arguments no longer needed
Arguments are a list of str in python3.
This commit is contained in:
parent
2e19025f9b
commit
6fa47010cf
@ -51,7 +51,6 @@ from gramps.gen.plug.report import CATEGORY_BOOK, CATEGORY_CODE, BookList
|
|||||||
from .plug import cl_report, cl_book
|
from .plug import cl_report, cl_book
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
from gramps.gen.constfunc import conv_to_unicode
|
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -213,7 +212,6 @@ class ArgHandler(object):
|
|||||||
"""
|
"""
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
value = conv_to_unicode(value, sys.stdin.encoding)
|
|
||||||
db_path = self.__deduce_db_path(value)
|
db_path = self.__deduce_db_path(value)
|
||||||
|
|
||||||
if db_path:
|
if db_path:
|
||||||
@ -242,9 +240,7 @@ class ArgHandler(object):
|
|||||||
Handle the "-i" or "--import" option.
|
Handle the "-i" or "--import" option.
|
||||||
Only Files supported by a plugin can be imported, so not Family Trees.
|
Only Files supported by a plugin can be imported, so not Family Trees.
|
||||||
"""
|
"""
|
||||||
# Need to convert path/filename to unicode before opening
|
fname = value
|
||||||
# For non latin characters in Windows path/file/user names
|
|
||||||
fname = conv_to_unicode(value, sys.stdin.encoding)
|
|
||||||
fullpath = os.path.abspath(os.path.expanduser(fname))
|
fullpath = os.path.abspath(os.path.expanduser(fname))
|
||||||
if fname != '-' and not os.path.exists(fullpath):
|
if fname != '-' and not os.path.exists(fullpath):
|
||||||
self.__error(_('Error: Import file %s not found.') % fname)
|
self.__error(_('Error: Import file %s not found.') % fname)
|
||||||
@ -279,9 +275,7 @@ class ArgHandler(object):
|
|||||||
"""
|
"""
|
||||||
if self.gui:
|
if self.gui:
|
||||||
return
|
return
|
||||||
# Need to convert path/filename to unicode before opening
|
fname = value
|
||||||
# For non latin characters in Windows path/file/user names
|
|
||||||
fname = conv_to_unicode(value, sys.stdin.encoding)
|
|
||||||
if fname == '-':
|
if fname == '-':
|
||||||
fullpath = '-'
|
fullpath = '-'
|
||||||
else:
|
else:
|
||||||
|
@ -48,7 +48,6 @@ from gramps.gen.config import config
|
|||||||
from gramps.gen.utils.cast import get_type_converter
|
from gramps.gen.utils.cast import get_type_converter
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
from gramps.gen.constfunc import conv_to_unicode
|
|
||||||
|
|
||||||
_HELP = _("""
|
_HELP = _("""
|
||||||
Usage: gramps.py [OPTION...]
|
Usage: gramps.py [OPTION...]
|
||||||
@ -220,14 +219,6 @@ class ArgParser(object):
|
|||||||
Any errors are added to self.errors
|
Any errors are added to self.errors
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Convert arguments to unicode, otherwise getopt will not work
|
|
||||||
# if a non latin character is used as an option (by mistake).
|
|
||||||
# getopt will try to treat the first char in an utf-8 sequence. Example:
|
|
||||||
# -Ärik is '-\xc3\x84rik' and getopt will respond :
|
|
||||||
# option -\xc3 not recognized
|
|
||||||
for arg in range(len(self.args) - 1):
|
|
||||||
self.args[arg+1] = conv_to_unicode(self.args[arg + 1],
|
|
||||||
sys.stdin.encoding)
|
|
||||||
options, leftargs = getopt.getopt(self.args[1:],
|
options, leftargs = getopt.getopt(self.args[1:],
|
||||||
SHORTOPTS, LONGOPTS)
|
SHORTOPTS, LONGOPTS)
|
||||||
except getopt.GetoptError as msg:
|
except getopt.GetoptError as msg:
|
||||||
@ -377,8 +368,7 @@ class ArgParser(object):
|
|||||||
# but not for non-latin characters in list elements
|
# but not for non-latin characters in list elements
|
||||||
cliargs = "[ "
|
cliargs = "[ "
|
||||||
for arg in range(len(self.args) - 1):
|
for arg in range(len(self.args) - 1):
|
||||||
cliargs += conv_to_unicode(self.args[arg + 1],
|
cliargs += self.args[arg + 1] + ' '
|
||||||
sys.stdin.encoding) + ' '
|
|
||||||
cliargs += "]"
|
cliargs += "]"
|
||||||
self.errors += [(_('Error parsing the arguments'),
|
self.errors += [(_('Error parsing the arguments'),
|
||||||
_("Error parsing the arguments: %s \n"
|
_("Error parsing the arguments: %s \n"
|
||||||
|
@ -55,7 +55,7 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
|
|||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
from gramps.gen.plug import BasePluginManager
|
from gramps.gen.plug import BasePluginManager
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.constfunc import win, conv_to_unicode
|
from gramps.gen.constfunc import win
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# constants
|
# constants
|
||||||
@ -369,8 +369,6 @@ class CLIDbManager(object):
|
|||||||
Returns old_name, new_name if success, None, None if no success
|
Returns old_name, new_name if success, None, None if no success
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
filepath = conv_to_unicode(filepath, 'utf8')
|
|
||||||
new_text = conv_to_unicode(new_text, 'utf8')
|
|
||||||
name_file = open(filepath, "r", encoding='utf8')
|
name_file = open(filepath, "r", encoding='utf8')
|
||||||
old_text=name_file.read()
|
old_text=name_file.read()
|
||||||
name_file.close()
|
name_file.close()
|
||||||
@ -427,7 +425,7 @@ def find_next_db_name(name_list):
|
|||||||
while True:
|
while True:
|
||||||
title = "%s %d" % (DEFAULT_TITLE, i)
|
title = "%s %d" % (DEFAULT_TITLE, i)
|
||||||
if title not in name_list:
|
if title not in name_list:
|
||||||
return conv_to_unicode(title)
|
return title
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def find_next_db_dir():
|
def find_next_db_dir():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user