Coding Guidelines: relative import of gen in gen submodule

svn: r20479
This commit is contained in:
Benny Malengier 2012-10-02 08:28:08 +00:00
parent 47a612c36a
commit 9832e6712e
41 changed files with 107 additions and 111 deletions

View File

@ -62,7 +62,7 @@ except:
# Initialize global displayer # Initialize global displayer
try: try:
from gen.config import config from ..config import config
val = config.get('preferences.date-format') val = config.get('preferences.date-format')
except: except:
val = 0 val = 0

View File

@ -188,7 +188,7 @@ class BSDDBTxn(object):
# test code # test code
if __name__ == "__main__": if __name__ == "__main__":
print "1" print "1"
from gen.config import config from ..config import config
if config.get('preferences.use-bsddb3'): if config.get('preferences.use-bsddb3'):
from bsddb3 import db, dbshelve from bsddb3 import db, dbshelve
else: else:

View File

@ -21,10 +21,10 @@
# gen/db/test/db_test.py # gen/db/test/db_test.py
# $Id$ # $Id$
from gen.db import (DbReadBase, DbWriteBase, from ..db import (DbReadBase, DbWriteBase,
DbBsddbRead, DbBsddb) DbBsddbRead, DbBsddb)
from gen.proxy.proxybase import ProxyDbBase from ...proxy.proxybase import ProxyDbBase
from gen.proxy import LivingProxyDb from ...proxy import LivingProxyDb
class DbTest(object): class DbTest(object):
READ_METHODS = [ READ_METHODS = [
@ -263,20 +263,20 @@ db1._verify_readonly()
db2 = DbTest(DbWriteBase()) db2 = DbTest(DbWriteBase())
db2._verify_readwrite() db2._verify_readwrite()
from gen.db import DbBsddbRead from .. import DbBsddbRead
db3 = DbTest(DbBsddbRead()) db3 = DbTest(DbBsddbRead())
db3._verify_readonly() db3._verify_readonly()
from gen.db import DbBsddb from .. import DbBsddb
db4 = DbTest(DbBsddb()) db4 = DbTest(DbBsddb())
db4._verify_readwrite() db4._verify_readwrite()
from gen.proxy.proxybase import ProxyDbBase from ...proxy.proxybase import ProxyDbBase
gdb = DbBsddb() gdb = DbBsddb()
db5 = DbTest(ProxyDbBase(gdb)) db5 = DbTest(ProxyDbBase(gdb))
db5._verify_readonly() db5._verify_readonly()
from gen.proxy import LivingProxyDb from ...proxy import LivingProxyDb
gdb = DbBsddb() gdb = DbBsddb()
db6 = DbTest(LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL)) db6 = DbTest(LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL))
db6._verify_readonly() db6._verify_readonly()

View File

@ -29,7 +29,7 @@ import time
import logging import logging
LOG = logging.getLogger(".citation") LOG = logging.getLogger(".citation")
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
""" """
methods to upgrade a database from version 13 to current version methods to upgrade a database from version 13 to current version

View File

@ -25,10 +25,10 @@
Provide the database state class Provide the database state class
""" """
from gen.db import DbBsddbRead from db import DbBsddbRead
from gen.proxy.proxybase import ProxyDbBase from proxy.proxybase import ProxyDbBase
from gen.utils.callback import Callback from utils.callback import Callback
from gen.config import config from config import config
class DbState(Callback): class DbState(Callback):
""" """

View File

@ -26,7 +26,7 @@
import unittest as U import unittest as U
from test.test_util import msg from test.test_util import msg
from gen.lib.grampstype import GrampsType, _init_map from ..grampstype import GrampsType, _init_map
# some simple map items to test with # some simple map items to test with
vals = "zz ab cd ef".split() vals = "zz ab cd ef".split()

View File

@ -25,11 +25,11 @@ This package implements an object difference engine.
""" """
import os import os
import cli.user import gramps.cli.user
from gen.dbstate import DbState from ..dbstate import DbState
from cli.grampscli import CLIManager from gramps.cli.grampscli import CLIManager
from gen.plug import BasePluginManager from ..plug import BasePluginManager
from gen.db.dictionary import DictionaryDb from ..db.dictionary import DictionaryDb
def import_as_dict(filename): def import_as_dict(filename):
""" """

View File

@ -30,10 +30,10 @@ Provide merge capabilities for citations.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import (Person, Family, Event, Place, MediaObject, Repository) from ..lib import (Person, Family, Event, Place, MediaObject, Repository)
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,10 +29,10 @@ Provide merge capabilities for events.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import Person, Family from ..lib import Person, Family
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,10 +29,10 @@ Provide merge capabilities for families.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
from gen.merge import MergePersonQuery from . import MergePersonQuery
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,10 +29,10 @@ Provide merge capabilities for media objects.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import Person, Family, Event, Source, Citation, Place from ..lib import Person, Family, Event, Source, Citation, Place
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,11 +29,11 @@ Provide merge capabilities for notes.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import (Person, Family, Event, Place, Source, Citation, Repository, from ..lib import (Person, Family, Event, Place, Source, Citation, Repository,
MediaObject) MediaObject)
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -31,9 +31,9 @@ Provide merge capabilities for persons.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -30,10 +30,10 @@ Provide merge capabilities for places.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import Person, Family, Event from ..lib import Person, Family, Event
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,10 +29,10 @@ Provide merge capabilities for repositories.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import Source from ..lib import Source
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -31,11 +31,11 @@ Provide merge capabilities for sources.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import (Person, Family, Event, Place, Source, Repository, from ..lib import (Person, Family, Event, Place, Source, Repository,
MediaObject, Citation) MediaObject, Citation)
from gen.db import DbTxn from ..db import DbTxn
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from gen.errors import MergeError from ..errors import MergeError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -36,7 +36,7 @@ import libxml2
import libxslt import libxslt
from libgrampsxml import GRAMPS_XML_VERSION from libgrampsxml import GRAMPS_XML_VERSION
from gen.const import ROOT_DIR, VERSION, USER_PLUGINS from ...const import ROOT_DIR, VERSION, USER_PLUGINS
from ...lib import Name, Surname from ...lib import Name, Surname
from ...ggettext import sgettext as _ from ...ggettext import sgettext as _

View File

@ -29,7 +29,7 @@ except:
from gnome.vfs import mime_get_short_list_applications, \ from gnome.vfs import mime_get_short_list_applications, \
mime_get_description, get_mime_type, mime_get_default_application mime_get_description, get_mime_type, mime_get_default_application
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
def get_description(type): def get_description(type):
"""Return the description of the specified mime type.""" """Return the description of the specified mime type."""

View File

@ -22,7 +22,7 @@
# #
import mimetypes import mimetypes
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
_type_map = { _type_map = {
'application/x-gramps' : 'Gramps database', 'application/x-gramps' : 'Gramps database',

View File

@ -38,7 +38,7 @@ from _winreg import *
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import _pythonmime import _pythonmime
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
def get_description(mime_type): def get_description(mime_type):
"""Return the description of the specfied mime type""" """Return the description of the specfied mime type"""

View File

@ -28,7 +28,7 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.ggettext import gettext as _ from ...ggettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -29,7 +29,7 @@
# standard python modules # standard python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import gettext as _ from ...ggettext import gettext as _
import os import os
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -39,8 +39,8 @@ import os
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# Report categories # Report categories
from gen.plug import CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE, CATEGORY_WEB,\ from .. import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE, CATEGORY_WEB,
CATEGORY_BOOK, CATEGORY_GRAPHVIZ CATEGORY_BOOK, CATEGORY_GRAPHVIZ)
standalone_categories = { standalone_categories = {
CATEGORY_TEXT : _("Text Reports"), CATEGORY_TEXT : _("Text Reports"),
@ -55,4 +55,3 @@ book_categories = {
CATEGORY_TEXT : _("Text"), CATEGORY_TEXT : _("Text"),
CATEGORY_DRAW : _("Graphics"), CATEGORY_DRAW : _("Graphics"),
} }

View File

@ -57,11 +57,11 @@ except:
# (do not import anything from 'gui' as this is in 'gen') # (do not import anything from 'gui' as this is in 'gen')
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.const import HOME_DIR, REPORT_OPTIONS from ...const import HOME_DIR, REPORT_OPTIONS
from gen.config import config from ...config import config
from gen.plug.docgen import PAPER_PORTRAIT from ..docgen import PAPER_PORTRAIT
from gen.plug import _options from .. import _options
from gen.plug import MenuOptions from .. import MenuOptions
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -26,16 +26,16 @@
# Python modules # Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import sgettext as _ from ...ggettext import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.plug.utils import gfloat from ..utils import gfloat
from gen.plug.docgen import PaperSize from ..docgen import PaperSize
from gen.const import PAPERSIZE from ...const import PAPERSIZE
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -26,11 +26,11 @@
""" """
Provide utilities for printing endnotes in text reports. Provide utilities for printing endnotes in text reports.
""" """
from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF from ..docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF
from gen.lib import NoteType, Citation from ...lib import NoteType, Citation
from gen.ggettext import gettext as _ from ...ggettext import gettext as _
from gen.utils.string import confidence from ...utils.string import confidence
from gen.datehandler import displayer from ....datehandler import displayer
def add_endnote_styles(style_sheet): def add_endnote_styles(style_sheet):
""" """

View File

@ -34,7 +34,7 @@ A collection of utilities to aid in the generation of reports.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
from gen.ggettext import gettext as _ from ...ggettext import gettext as _
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -39,7 +39,6 @@ from itertools import imap
# GRAMPS libraries # GRAMPS libraries
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
#from gen.lib import *
from proxybase import ProxyDbBase from proxybase import ProxyDbBase
class FilterProxyDb(ProxyDbBase): class FilterProxyDb(ProxyDbBase):

View File

@ -37,9 +37,9 @@ from itertools import ifilter
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from proxybase import ProxyDbBase from proxybase import ProxyDbBase
from gen.lib import Date, Person, Name, Surname, NameOriginType from ..lib import Date, Person, Name, Surname, NameOriginType
from gen.utils.alive import probably_alive from ..utils.alive import probably_alive
from gen.config import config from ..config import config
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -31,7 +31,7 @@ Proxy class for the GRAMPS databases. Filter out all data marked private.
# Python libraries # Python libraries
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
import logging import logging
LOG = logging.getLogger(".citation") LOG = logging.getLogger(".citation")
@ -40,9 +40,9 @@ LOG = logging.getLogger(".citation")
# GRAMPS libraries # GRAMPS libraries
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import (MediaRef, Attribute, Address, EventRef, from ..lib import (MediaRef, Attribute, Address, EventRef,
Person, Name, Source, RepoRef, MediaObject, Place, Event, Person, Name, Source, RepoRef, MediaObject, Place, Event,
Family, ChildRef, Repository, LdsOrd, Surname, Citation) Family, ChildRef, Repository, LdsOrd, Surname, Citation)
from proxybase import ProxyDbBase from proxybase import ProxyDbBase
class PrivateProxyDb(ProxyDbBase): class PrivateProxyDb(ProxyDbBase):

View File

@ -38,7 +38,7 @@ import types
# GRAMPS libraries # GRAMPS libraries
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.db.base import DbReadBase, DbWriteBase from ..db.base import DbReadBase, DbWriteBase
class ProxyCursor(object): class ProxyCursor(object):
""" """

View File

@ -37,7 +37,7 @@ try:
except: except:
use_lock = False use_lock = False
from gen.const import HOME_DIR from const import HOME_DIR
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -401,7 +401,7 @@ class RelationshipCalculator(object):
self.__db_connected = False self.__db_connected = False
self.depth = 15 self.depth = 15
try: try:
from gen.config import config from config import config
self.set_depth(config.get('behavior.generation-depth')) self.set_depth(config.get('behavior.generation-depth'))
except ImportError: except ImportError:
pass pass

View File

@ -23,7 +23,7 @@
""" """
Provide a simplified database access interface to the GRAMPS database. Provide a simplified database access interface to the GRAMPS database.
""" """
from gen.plug.docgen import StyleSheet, ParagraphStyle, TableStyle,\ from ..plug.docgen import StyleSheet, ParagraphStyle, TableStyle,\
TableCellStyle, FONT_SANS_SERIF, PARA_ALIGN_LEFT TableCellStyle, FONT_SANS_SERIF, PARA_ALIGN_LEFT
class SimpleDoc(object): class SimpleDoc(object):

View File

@ -27,7 +27,7 @@ Provide a simplified table creation interface
""" """
import cgi import cgi
from gen.ggettext import sgettext as _ from ..ggettext import sgettext as _
from ..lib import (Person, Family, Event, Source, Place, Citation, from ..lib import (Person, Family, Event, Source, Place, Citation,
Repository, MediaObject, Note, Date, Span) Repository, MediaObject, Note, Date, Span)
from ..config import config from ..config import config

View File

@ -39,9 +39,9 @@ import locale
# GRAMPS Modules # GRAMPS Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import Date from lib import Date
from gen.utils.db import get_birth_or_fallback from utils.db import get_birth_or_fallback
from gen.display.name import displayer as _nd from display.name import displayer as _nd
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -52,7 +52,7 @@ from ..ggettext import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# cache values; use refresh_constants() if they change # cache values; use refresh_constants() if they change
try: try:
from gen.config import config from ..config import config
_MAX_AGE_PROB_ALIVE = config.get('behavior.max-age-prob-alive') _MAX_AGE_PROB_ALIVE = config.get('behavior.max-age-prob-alive')
_MAX_SIB_AGE_DIFF = config.get('behavior.max-sib-age-diff') _MAX_SIB_AGE_DIFF = config.get('behavior.max-sib-age-diff')
_AVG_GENERATION_GAP = config.get('behavior.avg-generation-gap') _AVG_GENERATION_GAP = config.get('behavior.avg-generation-gap')
@ -499,7 +499,7 @@ def probably_alive_range(person, db,
""" """
# First, find the real database to use all people # First, find the real database to use all people
# for determining alive status: # for determining alive status:
from gen.proxy.proxybase import ProxyDbBase from ..proxy.proxybase import ProxyDbBase
basedb = db basedb = db
while isinstance(basedb, ProxyDbBase): while isinstance(basedb, ProxyDbBase):
basedb = basedb.db basedb = basedb.db
@ -512,7 +512,7 @@ def update_constants():
""" """
Used to update the constants that are cached in this module. Used to update the constants that are cached in this module.
""" """
from gen.config import config from ..config import config
global _MAX_AGE_PROB_ALIVE, _MAX_SIB_AGE_DIFF, _AVG_GENERATION_GAP global _MAX_AGE_PROB_ALIVE, _MAX_SIB_AGE_DIFF, _AVG_GENERATION_GAP
_MAX_AGE_PROB_ALIVE = config.get('behavior.max-age-prob-alive') _MAX_AGE_PROB_ALIVE = config.get('behavior.max-age-prob-alive')
_MAX_SIB_AGE_DIFF = config.get('behavior.max-sib-age-diff') _MAX_SIB_AGE_DIFF = config.get('behavior.max-sib-age-diff')

View File

@ -28,7 +28,7 @@
import os import os
import tempfile import tempfile
import zipfile import zipfile
from gen.ggettext import gettext as _ from ...ggettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -36,10 +36,8 @@ from gen.ggettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from TabbedDoc import * from TabbedDoc import *
from ...const import PROGRAM_NAME, VERSION
from gen.const import PROGRAM_NAME, VERSION from ...errors import ReportError
from gen.errors import ReportError
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -44,7 +44,7 @@ import tempfile
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.utils.file import get_unicode_path_from_env_var from file import get_unicode_path_from_env_var
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -24,12 +24,12 @@
Parses the lds.xml file to build the temple/code maps Parses the lds.xml file to build the temple/code maps
""" """
from gen.const import DATA_DIR from ..const import DATA_DIR
import os import os
import logging import logging
from xml.parsers.expat import ParserCreate from xml.parsers.expat import ParserCreate
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
LOG = logging.getLogger(".") LOG = logging.getLogger(".")

View File

@ -26,7 +26,7 @@ import unittest
from test import test_util as tu from test import test_util as tu
tu.path_append_parent() tu.path_append_parent()
from gen.utils.callback import Callback from ..callback import Callback
try: try:
log log

View File

@ -265,7 +265,7 @@ def get_addon_translator(filename=None, domain="addon", languages=None):
# Check if path is of type str. Do import and conversion if so. # Check if path is of type str. Do import and conversion if so.
# The import cannot be done at the top as that will conflict with the translation system. # The import cannot be done at the top as that will conflict with the translation system.
if type(path) == str: if type(path) == str:
from gen.utils.file import get_unicode_path_from_env_var from file import get_unicode_path_from_env_var
path = get_unicode_path_from_env_var(path) path = get_unicode_path_from_env_var(path)
if languages: if languages:
addon_translator = gettext.translation(domain, os.path.join(path,"locale"), addon_translator = gettext.translation(domain, os.path.join(path,"locale"),
@ -305,7 +305,7 @@ def trans_objclass(objclass_str):
Translates objclass_str into "... %s", where objclass_str Translates objclass_str into "... %s", where objclass_str
is 'Person', 'person', 'Family', 'family', etc. is 'Person', 'person', 'Family', 'family', etc.
""" """
from gen.ggettext import gettext as _ from ..ggettext import gettext as _
objclass = objclass_str.lower() objclass = objclass_str.lower()
if objclass == "person": if objclass == "person":
return _("the person") return _("the person")