diff --git a/po/POTFILES.in b/po/POTFILES.in index d65fe3722..aa7aa9d42 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,7 +4,6 @@ # src/const.py src/gramps.py -src/Utils.py # cli src/cli/arghandler.py diff --git a/po/POTFILES.skip b/po/POTFILES.skip index ea43fb619..29245c3b8 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -212,7 +212,9 @@ src/gen/utils/__init__.py src/gen/utils/callback.py src/gen/utils/callman.py src/gen/utils/cast.py +src/gen/utils/config.py src/gen/utils/db.py +src/gen/utils/debug.py src/gen/utils/file.py src/gen/utils/id.py src/gen/utils/image.py diff --git a/src/Makefile.am b/src/Makefile.am index f9899048d..24e8cd9e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,8 +13,7 @@ gdirdir=$(prefix)/share/gramps gdir_PYTHON = \ const.py\ - gramps.py\ - Utils.py + gramps.py # Clean up all the byte-compiled files MOSTLYCLEANFILES = *pyc *pyo diff --git a/src/Utils.py b/src/Utils.py deleted file mode 100644 index bf8a2fabc..000000000 --- a/src/Utils.py +++ /dev/null @@ -1,202 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2009 Gary Burton -# Copyright (C) 2011 Tim G L Lyons -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# $Id$ - -""" -Non GUI/GTK related utility functions -""" - -#------------------------------------------------------------------------- -# -# Standard python modules -# -#------------------------------------------------------------------------- -import locale -import logging -LOG = logging.getLogger(".") - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import gen.lib -from gen.datehandler import codeset -from gen.config import config -from gen.constfunc import mac, win - -#------------------------------------------------------------------------- -# -# modified flag -# -#------------------------------------------------------------------------- -_history_brokenFlag = 0 - -def history_broken(): - global _history_brokenFlag - _history_brokenFlag = 1 - -def xml_lang(): - loc = locale.getlocale() - if loc[0] is None: - return "" - else: - return loc[0].replace('_', '-') - -#------------------------------------------------------------------------- -# -# force_unicode -# -#------------------------------------------------------------------------- - -def force_unicode(n): - if not isinstance(n, unicode): - return (unicode(n).lower(), unicode(n)) - else: - return (n.lower(), n) - -#------------------------------------------------------------------------- -# -# Clears the modified flag. Should be called after data is saved. -# -#------------------------------------------------------------------------- -def clearHistory_broken(): - global _history_brokenFlag - _history_brokenFlag = 0 - -def wasHistory_broken(): - return _history_brokenFlag - -#------------------------------------------------------------------------- -# -# String Encoding functions -# -#------------------------------------------------------------------------- - -def encodingdefs(): - """ - 4 functions are defined to obtain a byte string that can be used as - sort key and is locale aware. Do not print the sortkey, it is a sortable - string, but is not a human readable correct string! - When gtk is defined, one can avoid some function calls as then the default - python encoding is not ascii but utf-8, so use the gtk functions in those - cases. - - conv_utf8_tosrtkey: convert a utf8 encoded string to sortkey usable string - - conv_unicode_tosrtkey: convert a unicode object to sortkey usable string - - conv_utf8_tosrtkey_ongtk: convert a utf8 encoded string to sortkey usable - string when gtk is loaded or utf-8 is default python encoding - - conv_unicode_tosrtkey_ongtk: convert a unicode object to sortkey usable - string when gtk is loaded or utf-8 is default python encoding - """ - pass - -if win(): - # python encoding is ascii, but C functions need to receive the - # windows codeset, so convert over to it - conv_utf8_tosrtkey = lambda x: locale.strxfrm(x.decode("utf-8").encode( - codeset)) - conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode(codeset)) - #when gtk is imported the python defaultencoding is utf-8, - #so no need to specify it - conv_utf8_tosrtkey_ongtk = lambda x: locale.strxfrm(unicode(x).encode( - codeset)) - conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x.encode(codeset,'replace')) -else: - # on unix C functions need to receive utf-8. Default conversion would - # use ascii, so it is needed to be explicit about the resulting encoding - conv_utf8_tosrtkey = lambda x: locale.strxfrm(x) - conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode("utf-8")) - # when gtk loaded, default encoding (sys.getdefaultencoding ) is utf-8, - # so default conversion happens with utf-8 - conv_utf8_tosrtkey_ongtk = lambda x: locale.strxfrm(x) - conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x) - - -def title(n): - return '%s' % n - -def set_title_label(xmlobj, t): - title_label = xmlobj.get_widget('title') - title_label.set_text('%s' % t) - title_label.set_use_markup(True) - -from warnings import warn -def set_titles(window, title, t, msg=None): - warn('The Utils.set_titles is deprecated. Use ManagedWindow methods') - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def profile(func, *args): - import hotshot.stats - - prf = hotshot.Profile('mystats.profile') - print "Start" - prf.runcall(func, *args) - print "Finished" - prf.close() - print "Loading profile" - stats = hotshot.stats.load('mystats.profile') - print "done" - stats.strip_dirs() - stats.sort_stats('time', 'calls') - stats.print_stats(100) - stats.print_callers(100) - -#------------------------------------------------------------------------- -# -# Config-based functions -# -#------------------------------------------------------------------------- -def get_researcher(): - """ - Return a new database owner with the default values from the config file. - """ - name = config.get('researcher.researcher-name') - address = config.get('researcher.researcher-addr') - locality = config.get('researcher.researcher-locality') - city = config.get('researcher.researcher-city') - state = config.get('researcher.researcher-state') - country = config.get('researcher.researcher-country') - post_code = config.get('researcher.researcher-postal') - phone = config.get('researcher.researcher-phone') - email = config.get('researcher.researcher-email') - - owner = gen.lib.Researcher() - owner.set_name(name) - owner.set_address(address) - owner.set_locality(locality) - owner.set_city(city) - owner.set_state(state) - owner.set_country(country) - owner.set_postal_code(post_code) - owner.set_phone(phone) - owner.set_email(email) - - return owner diff --git a/src/cli/grampscli.py b/src/cli/grampscli.py index 0a7a9fc73..ac00c5be4 100644 --- a/src/cli/grampscli.py +++ b/src/cli/grampscli.py @@ -53,7 +53,7 @@ from gen.dbstate import DbState from gen.db import DbBsddb import gen.db.exceptions from gen.plug import BasePluginManager -from Utils import get_researcher +from gen.utils.config import get_researcher from gen.recentfiles import recent_files #------------------------------------------------------------------------- diff --git a/src/gen/utils/Makefile.am b/src/gen/utils/Makefile.am index e5eab21df..12c698aab 100644 --- a/src/gen/utils/Makefile.am +++ b/src/gen/utils/Makefile.am @@ -14,7 +14,9 @@ pkgpython_PYTHON = \ callback.py \ callman.py \ cast.py \ + config.py \ configmanager.py \ + debug.py \ db.py \ file.py \ id.py \ diff --git a/src/gen/utils/config.py b/src/gen/utils/config.py new file mode 100644 index 000000000..ffbd838a9 --- /dev/null +++ b/src/gen/utils/config.py @@ -0,0 +1,67 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2009 Gary Burton +# Copyright (C) 2011 Tim G L Lyons +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" +Configuration based utilities +""" + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +import gen.lib +from gen.config import config + +#------------------------------------------------------------------------- +# +# Configuration based utilities +# +#------------------------------------------------------------------------- +def get_researcher(): + """ + Return a new database owner with the default values from the config file. + """ + name = config.get('researcher.researcher-name') + address = config.get('researcher.researcher-addr') + locality = config.get('researcher.researcher-locality') + city = config.get('researcher.researcher-city') + state = config.get('researcher.researcher-state') + country = config.get('researcher.researcher-country') + post_code = config.get('researcher.researcher-postal') + phone = config.get('researcher.researcher-phone') + email = config.get('researcher.researcher-email') + + owner = gen.lib.Researcher() + owner.set_name(name) + owner.set_address(address) + owner.set_locality(locality) + owner.set_city(city) + owner.set_state(state) + owner.set_country(country) + owner.set_postal_code(post_code) + owner.set_phone(phone) + owner.set_email(email) + + return owner diff --git a/src/gen/utils/debug.py b/src/gen/utils/debug.py new file mode 100644 index 000000000..4ae2d255a --- /dev/null +++ b/src/gen/utils/debug.py @@ -0,0 +1,48 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2009 Gary Burton +# Copyright (C) 2011 Tim G L Lyons +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" +Debugging utilities +""" + +#------------------------------------------------------------------------- +# +# Debugging utilities +# +#------------------------------------------------------------------------- +def profile(func, *args): + import hotshot.stats + + prf = hotshot.Profile('mystats.profile') + print "Start" + prf.runcall(func, *args) + print "Finished" + prf.close() + print "Loading profile" + stats = hotshot.stats.load('mystats.profile') + print "done" + stats.strip_dirs() + stats.sort_stats('time', 'calls') + stats.print_stats(100) + stats.print_callers(100) diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index 30ad8d007..5b50d15b8 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -58,7 +58,7 @@ from gen.errors import WindowActiveError from gui.filters import SearchBar from gui.utils import add_menuitem import const -import Utils +from gen.utils.debug import profile from gen.utils.string import data_recover_msg from gen.utils.file import get_unicode_path_from_file_chooser from gui.dialog import QuestionDialog, QuestionDialog2 @@ -264,7 +264,7 @@ class ListView(NavigationView): self.model.total()) def __build_tree(self): - Utils.profile(self._build_tree) + profile(self._build_tree) def build_tree(self, force_sidebar=False): if self.active: diff --git a/src/gui/views/treemodels/Makefile.am b/src/gui/views/treemodels/Makefile.am index ea145333f..c7ea9db30 100644 --- a/src/gui/views/treemodels/Makefile.am +++ b/src/gui/views/treemodels/Makefile.am @@ -8,6 +8,7 @@ pkgpythondir = $(datadir)/@PACKAGE@/gui/views/treemodels pkgpython_PYTHON = \ __init__.py \ + bugfix.py \ eventmodel.py \ familymodel.py \ flatbasemodel.py \ diff --git a/src/gui/views/treemodels/bugfix.py b/src/gui/views/treemodels/bugfix.py new file mode 100644 index 000000000..780bc3db1 --- /dev/null +++ b/src/gui/views/treemodels/bugfix.py @@ -0,0 +1,51 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2009 Gary Burton +# Copyright (C) 2011 Tim G L Lyons +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" +Bug fix for strxfrm. + +strxfrm is apparently broken in Win ?? --> they should fix base lib, +we need strxfrm, fix it in this module. +""" + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import locale + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +from gen.datehandler import codeset +from gen.constfunc import win + +if win(): + conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x.encode( + codeset,'replace')) +else: + conv_unicode_tosrtkey_ongtk = lambda x: locale.strxfrm(x) diff --git a/src/gui/views/treemodels/flatbasemodel.py b/src/gui/views/treemodels/flatbasemodel.py index 8c9370200..6fa326469 100644 --- a/src/gui/views/treemodels/flatbasemodel.py +++ b/src/gui/views/treemodels/flatbasemodel.py @@ -73,7 +73,7 @@ import gtk # #------------------------------------------------------------------------- from gen.filters import SearchFilter, ExactSearchFilter -from Utils import conv_unicode_tosrtkey_ongtk +from bugfix import conv_unicode_tosrtkey_ongtk #------------------------------------------------------------------------- # @@ -506,7 +506,7 @@ class FlatBaseModel(gtk.GenericTreeModel): This list is sorted ascending, via localized string sort. conv_unicode_tosrtkey_ongtk which uses strxfrm, which is apparently broken in Win ?? --> they should fix base lib, we need strxfrm, fix it - in the Utils module. + in the bugfix module. """ # use cursor as a context manager with self.gen_cursor() as cursor: diff --git a/src/gui/views/treemodels/treebasemodel.py b/src/gui/views/treemodels/treebasemodel.py index 77bbce639..fcacc4ab3 100644 --- a/src/gui/views/treemodels/treebasemodel.py +++ b/src/gui/views/treemodels/treebasemodel.py @@ -54,7 +54,7 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- -from Utils import conv_unicode_tosrtkey_ongtk +from bugfix import conv_unicode_tosrtkey_ongtk import gui.widgets.progressdialog as progressdlg from lru import LRU from bisect import bisect_right diff --git a/src/guiQML/views/personview.py b/src/guiQML/views/personview.py index 5d57b7b50..0ace3993d 100644 --- a/src/guiQML/views/personview.py +++ b/src/guiQML/views/personview.py @@ -55,7 +55,7 @@ from PySide import QtOpenGL # #------------------------------------------------------------------------- import const -from Utils import conv_unicode_tosrtkey_ongtk +from gui.views.treemodels import conv_unicode_tosrtkey_ongtk from gen.ggettext import gettext as _ from gen.display.name import displayer as name_displayer from gen.lib import Name diff --git a/src/plugins/lib/libhtml.py b/src/plugins/lib/libhtml.py index 948c1180d..5462b9888 100644 --- a/src/plugins/lib/libhtml.py +++ b/src/plugins/lib/libhtml.py @@ -34,6 +34,7 @@ from __future__ import print_function # Python modules #------------------------------------------------------------------------ import re +import locale """ HTML operations. @@ -571,6 +572,18 @@ class Html(list): def __exit__(self, exc_type, exc_val, exc_tb): return exc_type is None +#------------------------------------------------------------------------ +# +# Functions +# +#------------------------------------------------------------------------ +def xml_lang(): + loc = locale.getlocale() + if loc[0] is None: + return "" + else: + return loc[0].replace('_', '-') + #------------------------------------------- # # Unit tests diff --git a/src/plugins/lib/libhtmlbackend.py b/src/plugins/lib/libhtmlbackend.py index c81ef119f..090ec0121 100644 --- a/src/plugins/lib/libhtmlbackend.py +++ b/src/plugins/lib/libhtmlbackend.py @@ -43,8 +43,7 @@ import os.path # #------------------------------------------------------------------------ from gen.plug.docbackend import DocBackend -from libhtml import Html -from Utils import xml_lang +from libhtml import Html, xml_lang from gen.errors import ReportError diff --git a/src/plugins/tool/ownereditor.py b/src/plugins/tool/ownereditor.py index 8e4bebc1e..cfbb0300f 100644 --- a/src/plugins/tool/ownereditor.py +++ b/src/plugins/tool/ownereditor.py @@ -39,7 +39,7 @@ import gtk #------------------------------------------------------------------------- import const from gen.config import config -from Utils import get_researcher +from gen.utils.config import get_researcher from gui.display import display_help from gui.widgets import MonitoredEntry from gui.managedwindow import ManagedWindow diff --git a/src/plugins/webreport/narrativeweb.py b/src/plugins/webreport/narrativeweb.py index dc9a23377..d505fffea 100644 --- a/src/plugins/webreport/narrativeweb.py +++ b/src/plugins/webreport/narrativeweb.py @@ -88,7 +88,7 @@ from gen.plug.report import ( Report, Bibliography) from gen.plug.report import utils as ReportUtils from gen.plug.report import MenuReportOptions -import Utils +from gen.utils.config import get_researcher from gen.utils.string import confidence from gen.utils.file import media_path_full from gen.utils.referent import get_source_and_citation_referents @@ -102,7 +102,7 @@ from gen.proxy import PrivateProxyDb, LivingProxyDb from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS # import HTML Class from src/plugins/lib/libhtml.py -from libhtml import Html +from libhtml import Html, xml_lang # import styled notes from src/plugins/lib/libhtmlbackend.py from libhtmlbackend import HtmlBackend, process_spaces @@ -530,7 +530,7 @@ class BasePage(object): self.page_title = "" - self.author = Utils.get_researcher().get_name() + self.author = get_researcher().get_name() if self.author: self.author = self.author.replace(',,,', '') @@ -1544,7 +1544,7 @@ class BasePage(object): """ # begin each html page... - xmllang = Utils.xml_lang() + xmllang = xml_lang() page, head, body = Html.page('%s - %s' % (html_escape(self.title_str.strip()), html_escape(title)), @@ -3552,7 +3552,7 @@ class PlacePage(BasePage): with Html("script", type = "text/javascript") as jsc: canvas += jsc - jsc += openstreetmap_jsc % (Utils.xml_lang()[3:5].lower(), longitude, latitude) + jsc += openstreetmap_jsc % (xml_lang()[3:5].lower(), longitude, latitude) # add javascript function call to body element body.attr +=' onload = "initialize();" ' @@ -5260,7 +5260,7 @@ class ContactPage(BasePage): summaryarea += contactimg # get researcher information - r = Utils.get_researcher() + r = get_researcher() with Html("div", id = 'researcher') as researcher: summaryarea += researcher @@ -5638,7 +5638,7 @@ class IndividualPage(BasePage): # we are using OpenStreetMap? else: - jsc += openstreetmap_jsc % (Utils.xml_lang()[3:5].lower(), longitude, latitude) + jsc += openstreetmap_jsc % (xml_lang()[3:5].lower(), longitude, latitude) # there is more than one marker... else: @@ -5660,7 +5660,7 @@ class IndividualPage(BasePage): # we are using OpenStreetMap... else: - jsc += osm_markers % (Utils.xml_lang()[3:5].lower(), tracelife, midY_, midX_, zoomlevel) + jsc += osm_markers % (xml_lang()[3:5].lower(), tracelife, midY_, midX_, zoomlevel) # if Google and Drop Markers are selected, then add "Drop Markers" button? if (self.mapservice == "Google" and self.googleopts == "Drop"): diff --git a/src/plugins/webreport/webcal.py b/src/plugins/webreport/webcal.py index bc507e237..41021fbdd 100644 --- a/src/plugins/webreport/webcal.py +++ b/src/plugins/webreport/webcal.py @@ -58,14 +58,14 @@ from gen.plug.report import MenuReportOptions from gen.plug.menu import BooleanOption, NumberOption, StringOption, \ EnumeratedListOption, FilterOption, PersonOption, \ DestinationOption, NoteOption -from Utils import xml_lang, get_researcher +from gen.utils.config import get_researcher from gen.utils.alive import probably_alive from gen.datehandler import displayer as _dd, long_days from gen.display.name import displayer as _nd import libholiday -from libhtml import Html +from libhtml import Html, xml_lang from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS from gui.pluginmanager import GuiPluginManager