GEPS008: Removed Utils module

svn: r19923
This commit is contained in:
Nick Hall 2012-06-25 22:04:16 +00:00
parent 6f04233439
commit 449bb71a49
19 changed files with 204 additions and 225 deletions

View File

@ -4,7 +4,6 @@
#
src/const.py
src/gramps.py
src/Utils.py
# cli
src/cli/arghandler.py

View File

@ -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

View File

@ -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

View File

@ -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 '<span weight="bold" size="larger">%s</span>' % n
def set_title_label(xmlobj, t):
title_label = xmlobj.get_widget('title')
title_label.set_text('<span weight="bold" size="larger">%s</span>' % 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

View File

@ -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
#-------------------------------------------------------------------------

View File

@ -14,7 +14,9 @@ pkgpython_PYTHON = \
callback.py \
callman.py \
cast.py \
config.py \
configmanager.py \
debug.py \
db.py \
file.py \
id.py \

67
src/gen/utils/config.py Normal file
View File

@ -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

48
src/gen/utils/debug.py Normal file
View File

@ -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)

View File

@ -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:

View File

@ -8,6 +8,7 @@ pkgpythondir = $(datadir)/@PACKAGE@/gui/views/treemodels
pkgpython_PYTHON = \
__init__.py \
bugfix.py \
eventmodel.py \
familymodel.py \
flatbasemodel.py \

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"):

View File

@ -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