From 410985b0e1569cda8e625b5aaaae81ef2c8b00e1 Mon Sep 17 00:00:00 2001 From: Peter Landgren Date: Tue, 25 Sep 2012 16:51:45 +0000 Subject: [PATCH] Fix of issue 6058 and printing of non ascii strings in Windows. svn: r20445 --- src/cli/arghandler.py | 41 ++++++++++++++++++++-------------------- src/cli/clidbman.py | 14 +++++++------- src/cli/plug/__init__.py | 40 +++++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/cli/arghandler.py b/src/cli/arghandler.py index 669ea9712..ab420e6f7 100644 --- a/src/cli/arghandler.py +++ b/src/cli/arghandler.py @@ -403,9 +403,8 @@ class ArgHandler(object): encode(sys.getfilesystemencoding()) for name, dirname in sorted(self.dbman.family_tree_list(), key=lambda pair: pair[0].lower()): - print (_("%(full_DB_path)s with name \"%(f_t_name)s\"") % \ - {'full_DB_path' : dirname, + {'full_DB_path' : dirname.decode(sys.getfilesystemencoding()), 'f_t_name' : name}).encode(sys.getfilesystemencoding()) sys.exit(0) @@ -413,11 +412,13 @@ class ArgHandler(object): print _('Gramps Family Trees:').encode(sys.getfilesystemencoding()) summary_list = self.dbman.family_tree_summary() for summary in sorted(summary_list, - key=lambda sum: sum["Family tree"].lower()): + key=lambda sum: sum[_("Family tree")].lower()): print _("Family Tree \"%s\":").\ - encode(sys.getfilesystemencoding()) % summary["Family tree"] + encode(sys.getfilesystemencoding()) % summary[_("Family tree")] for item in sorted(summary): - if item != "Family tree": + if item == _("Path"): + summary[item] = (summary[item]).decode(sys.getfilesystemencoding()) + if item != _("Family tree"): print (" %s: %s" % (item, summary[item])).\ encode(sys.getfilesystemencoding()) sys.exit(0) @@ -426,9 +427,9 @@ class ArgHandler(object): self.__import_action() for (action, op_string) in self.actions: - print >> sys.stderr, _("Performing action: %s.") % action + print >> sys.stderr, (_("Performing action: %s.") % action).encode(sys.getfilesystemencoding()) if op_string: - print >> sys.stderr, _("Using options string: %s") % op_string + print >> sys.stderr, (_("Using options string: %s") % op_string).encode(sys.getfilesystemencoding()) self.cl_action(action, op_string) for expt in self.exports: @@ -444,11 +445,11 @@ class ArgHandler(object): if cleanup: self.cleanup() - print >> sys.stderr, _("Exiting.") + print >> sys.stderr, _("Exiting.").encode(sys.getfilesystemencoding()) sys.exit(0) def cleanup(self): - print >> sys.stderr, _("Cleaning up.") + print >> sys.stderr, _("Cleaning up.").encode(sys.getfilesystemencoding()) # remove files in import db subdir after use self.dbstate.db.close() if self.imp_db_path: @@ -478,11 +479,11 @@ class ArgHandler(object): try: self.sm.open_activate(self.imp_db_path) - msg = _("Created empty family tree successfully") + msg = _("Created empty family tree successfully").encode(sys.getfilesystemencoding()) print >> sys.stderr, msg except: - print >> sys.stderr, _("Error opening the file.") - print >> sys.stderr, _("Exiting...") + print >> sys.stderr, _("Error opening the file.").encode(sys.getfilesystemencoding()) + print >> sys.stderr, _("Exiting...").encode(sys.getfilesystemencoding()) sys.exit(0) for imp in self.imports: @@ -490,7 +491,7 @@ class ArgHandler(object): fmt = str(imp[1]) msg = _("Importing: file %(filename)s, format %(format)s.") % \ {'filename' : fn, 'format' : fmt} - print >> sys.stderr, msg + print >> sys.stderr, msg.encode(sys.getfilesystemencoding()) self.cl_import(imp[0], imp[1]) def __open_action(self): @@ -506,10 +507,10 @@ class ArgHandler(object): # we load this file for use try: self.sm.open_activate(self.open) - print >> sys.stderr, _("Opened successfully!") + print >> sys.stderr, _("Opened successfully!").encode(sys.getfilesystemencoding()) except: - print >> sys.stderr, _("Error opening the file.") - print >> sys.stderr, _("Exiting...") + print >> sys.stderr, _("Error opening the file.").encode(sys.getfilesystemencoding()) + print >> sys.stderr, _("Exiting...").encode(sys.getfilesystemencoding()) sys.exit(0) def check_db(self, dbpath, force_unlock = False): @@ -581,7 +582,7 @@ class ArgHandler(object): options_str_dict = _split_options(options_str) except: options_str_dict = {} - print >> sys.stderr, _("Ignoring invalid options string.") + print >> sys.stderr, _("Ignoring invalid options string.").encode(sys.getfilesystemencoding()) name = options_str_dict.pop('name', None) _cl_list = pmgr.get_reg_reports(gui=False) @@ -609,8 +610,8 @@ class ArgHandler(object): msg = _("Report name not given. " "Please use one of %(donottranslate)s=reportname") % \ {'donottranslate' : '[-p|--options] name'} - - print >> sys.stderr, _("%s\n Available names are:") % msg + + print >> sys.stderr, (_("%s\n Available names are:") % msg).encode(sys.getfilesystemencoding()) for pdata in sorted(_cl_list, key= lambda pdata: pdata.id.lower()): # Print cli report name ([item[0]), GUI report name (item[4]) if len(pdata.id) <= 25: @@ -628,7 +629,7 @@ class ArgHandler(object): chunk in options_str.split(',') ] ) except: options_str_dict = {} - print >> sys.stderr, _("Ignoring invalid options string.") + print >> sys.stderr, _("Ignoring invalid options string.").encode(sys.getfilesystemencoding()) name = options_str_dict.pop('name', None) _cli_tool_list = pmgr.get_reg_tools(gui=False) diff --git a/src/cli/clidbman.py b/src/cli/clidbman.py index d917b5cca..82dd2127c 100644 --- a/src/cli/clidbman.py +++ b/src/cli/clidbman.py @@ -176,15 +176,15 @@ class CLIDbManager(object): tval, enable, stock_id) = item count, version = self.get_dbdir_summary(dirpath) retval = {} - retval["Number of people"] = count + retval[_("Number of people")] = count if enable: - retval["Locked?"] = "yes" + retval[_("Locked?")] = _("yes") else: - retval["Locked?"] = "no" - retval["DB version"] = version - retval["Family tree"] = name.encode(sys.getfilesystemencoding()) - retval["Path"] = dirpath - retval["Last accessed"] = time.strftime('%x %X', + retval[_("Locked?")] = _("no") + retval[_("DB version")] = version + retval[_("Family tree")] = name.encode(sys.getfilesystemencoding()) + retval[_("Path")] = dirpath + retval[_("Last accessed")] = time.strftime('%x %X', time.localtime(tval)) list.append( retval ) return list diff --git a/src/cli/plug/__init__.py b/src/cli/plug/__init__.py index 715446d04..c6b41248e 100644 --- a/src/cli/plug/__init__.py +++ b/src/cli/plug/__init__.py @@ -165,7 +165,7 @@ def _validate_options(options, dbase): phandle = None person = dbase.get_person_from_handle(phandle) if not person: - print _("ERROR: Please specify a person") + print _("ERROR: Please specify a person").encode(sys.getfilesystemencoding()) if person: option.set_value(person.get_gramps_id()) @@ -189,7 +189,7 @@ def _validate_options(options, dbase): family = dbase.get_family_from_handle(family_handle) option.set_value(family.get_gramps_id()) else: - print _("ERROR: Please specify a family") + print _("ERROR: Please specify a family").encode(sys.getfilesystemencoding()) #------------------------------------------------------------------------ # @@ -293,7 +293,7 @@ class CommandLineReport(object): elif self.category == CATEGORY_GRAPHVIZ: for graph_format in graphdoc.FORMATS: self.options_help['off'][2].append( - graph_format["ext"] + "\t" + graph_format["descr"] ) + graph_format["type"] + "\t" + graph_format["descr"] ) else: self.options_help['off'][2] = "NA" @@ -400,12 +400,12 @@ class CommandLineReport(object): elif isinstance(option, Option): self.options_help[name].append(option.get_help()) else: - print _("Unknown option: %s") % option - print _(" Valid options are:"), ", ".join( - self.options_dict.keys()) + print (_("Unknown option: %s") % option).encode(sys.getfilesystemencoding()) + print (_(" Valid options are:"), ", ".join( + self.options_dict.keys())).encode(sys.getfilesystemencoding()) print (_(" Use '%(donottranslate)s' to see description " "and acceptable values") % - {'donottranslate' : "show=option"}) + {'donottranslate' : "show=option"}).encode(sys.getfilesystemencoding()) def parse_options(self): """ @@ -430,12 +430,12 @@ class CommandLineReport(object): option.set_value(self.options_dict[opt]) else: - print _("Ignoring unknown option: %s") % opt - print _(" Valid options are:"), ", ".join( - self.options_dict.keys()) + print (_("Ignoring unknown option: %s") % opt).encode(sys.getfilesystemencoding()) + print (_(" Valid options are:"), ", ".join( + self.options_dict.keys())).encode(sys.getfilesystemencoding()) print (_(" Use '%(donottranslate)s' to see description " "and acceptable values") % - {'donottranslate' : "show=option"}) + {'donottranslate' : "show=option"}).encode(sys.getfilesystemencoding()) self.option_class.handler.output = self.options_dict['of'] @@ -468,13 +468,13 @@ class CommandLineReport(object): _chosen_format = self.__bookdoc_plugins[0].get_extension() elif self.category == CATEGORY_GRAPHVIZ: for graph_format in graphdoc.FORMATS: - if graph_format['ext'] == self.options_dict['off']: + if graph_format['type'] == self.options_dict['off']: if not self.format: # choose the first one, not the last self.format = graph_format["class"] if self.format is None: # Pick the first one as the default. self.format = graphdoc.FORMATS[0]["class"] - _chosen_format = graphdoc.FORMATS[0]["ext"] + _chosen_format = graphdoc.FORMATS[0]["type"] else: self.format = None if _chosen_format and self.options_str_dict.has_key('off'): @@ -482,9 +482,9 @@ class CommandLineReport(object): "and using '%(notranslate1)s=%(notranslate3)s'.") % {'notranslate1' : "off", 'notranslate2' : self.options_dict['off'], - 'notranslate3' : _chosen_format}) + 'notranslate3' : _chosen_format}).encode(sys.getfilesystemencoding()) print (_("Use '%(notranslate)s' to see valid values.") % - {'notranslate' : "show=off"}) + {'notranslate' : "show=off"}).encode(sys.getfilesystemencoding()) for paper in paper_sizes: if paper.get_name() == self.options_dict['papers']: @@ -517,7 +517,7 @@ class CommandLineReport(object): if not self.show: return elif self.show == 'all': - print _(" Available options:") + print _(" Available options:").encode(sys.getfilesystemencoding()) for key in sorted(self.options_dict.keys()): if key in self.options_help: opt = self.options_help[key] @@ -530,12 +530,12 @@ class CommandLineReport(object): print optmsg.encode(sys.getfilesystemencoding()) print (_(" Use '%(donottranslate)s' to see description " "and acceptable values") % - {'donottranslate' : "show=option"}) + {'donottranslate' : "show=option"}).encode(sys.getfilesystemencoding()) elif self.show in self.options_help: opt = self.options_help[self.show] tabs = '\t\t' if len(self.show) < 10 else '\t' print ' %s%s%s (%s)' % (self.show, tabs, opt[1], opt[0]) - print _(" Available values are:") + print _(" Available values are:").encode(sys.getfilesystemencoding()) vals = opt[2] if isinstance(vals, (list, tuple)): for val in vals: @@ -549,7 +549,7 @@ class CommandLineReport(object): #there was a show option given, but the option is invalid print (_("option '%(optionname)s' not valid. " "Use '%(donottranslate)s' to see all valid options.") % - {'optionname' : self.show, 'donottranslate' : "show=all"}) + {'optionname' : self.show, 'donottranslate' : "show=all"}).encode(sys.getfilesystemencoding()) #------------------------------------------------------------------------ # @@ -559,7 +559,7 @@ class CommandLineReport(object): def cl_report(database, name, category, report_class, options_class, options_str_dict): - err_msg = _("Failed to write report. ") + err_msg = _("Failed to write report. ").encode(sys.getfilesystemencoding()) clr = CommandLineReport(database, name, category, options_class, options_str_dict)