Coding Guidelines: relative and absolute imports, some fixes and shortenings

svn: r20496
This commit is contained in:
Benny Malengier 2012-10-03 07:39:26 +00:00
parent 809c60fd77
commit e6cd5b5d2d
10 changed files with 64 additions and 59 deletions

View File

@ -36,7 +36,7 @@ import sys
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import gramps.gen.user from gramps.gen.user import User
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -50,7 +50,7 @@ _SPINNER = ['|', '/', '-', '\\']
# User class # User class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class User(gramps.gen.user.User): class User(User):
""" """
This class provides a means to interact with the user via CLI. This class provides a means to interact with the user via CLI.
It implements the interface in gramps.gen.user.User() It implements the interface in gramps.gen.user.User()

View File

@ -88,7 +88,7 @@ QUAL_TEXT = (
(Date.QUAL_ESTIMATED, _('Estimated')), (Date.QUAL_ESTIMATED, _('Estimated')),
(Date.QUAL_CALCULATED, _('Calculated')) ) (Date.QUAL_CALCULATED, _('Calculated')) )
CAL_TO_MONTHS_NAMES = { CAL_TO_MONTHS_NAMES = {
Date.CAL_GREGORIAN : displayer.short_months, Date.CAL_GREGORIAN : displayer.short_months,
Date.CAL_JULIAN : displayer.short_months, Date.CAL_JULIAN : displayer.short_months,
Date.CAL_HEBREW : displayer.hebrew, Date.CAL_HEBREW : displayer.hebrew,

View File

@ -45,7 +45,7 @@ from gramps.gui.dialog import (WarningDialog, ErrorDialog, DBErrorDialog,
# User class # User class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class User(gramps.gen.user.User): class User(User):
""" """
This class provides a means to interact with the user via GTK. This class provides a means to interact with the user via GTK.
It implements the interface in gramps.gen.user.User() It implements the interface in gramps.gen.user.User()

View File

@ -56,15 +56,16 @@ from cgi import escape
from gramps.gen.db import DbTxn from gramps.gen.db import DbTxn
from gramps.gen.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.errors import WindowActiveError from gramps.gen.errors import WindowActiveError
from gramps.gui.editors import EditPerson, EditFamily
from gramps.gui.widgets.reorderfam import Reorder
from gramps.gen.lib import ChildRef, Family, Name, Person, Surname from gramps.gen.lib import ChildRef, Family, Name, Person, Surname
from gramps.gui.utils import color_graph_box, hex_to_rgb, is_right_click from gramps.gen.lib.date import Today
from gramps.gui.ddtargets import DdTargets from ..editors import EditPerson, EditFamily
from .reorderfam import Reorder
from ..utils import color_graph_box, hex_to_rgb, is_right_click
from ..ddtargets import DdTargets
from gramps.gen.utils.alive import probably_alive from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.libformatting import FormattingHelper from gramps.gen.utils.libformatting import FormattingHelper
from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people, from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people,
get_age, get_timeperiod, preset_name) get_age, get_timeperiod, preset_name)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -364,7 +365,7 @@ class FanChartBaseWidget(Gtk.DrawingArea):
self.set_userdata_timeperiod(child, userdata) self.set_userdata_timeperiod(child, userdata)
#now create gradient data, 5 values from min to max rounded to nearest 50 #now create gradient data, 5 values from min to max rounded to nearest 50
if self.maxperiod < self.minperiod: if self.maxperiod < self.minperiod:
self.maxperiod = self.minperiod = gen.lib.date.Today().get_year() self.maxperiod = self.minperiod = Today().get_year()
rper = self.maxperiod // 50 rper = self.maxperiod // 50
if rper * 50 != self.maxperiod: if rper * 50 != self.maxperiod:
self.maxperiod = rper * 50 + 50 self.maxperiod = rper * 50 + 50

View File

@ -55,15 +55,15 @@ from cgi import escape
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.errors import WindowActiveError from gramps.gen.errors import WindowActiveError
from gramps.gui.editors import EditPerson, EditFamily from ..editors import EditPerson, EditFamily
from gramps.gui.utils import hex_to_rgb from ..utils import hex_to_rgb
from gramps.gui.ddtargets import DdTargets from ..ddtargets import DdTargets
from gramps.gen.utils.alive import probably_alive from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.libformatting import FormattingHelper from gramps.gen.utils.libformatting import FormattingHelper
from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people, from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people,
get_age, get_timeperiod) get_age, get_timeperiod)
from gramps.gen.plug.report.utils import find_spouse from gramps.gen.plug.report.utils import find_spouse
from gramps.gui.widgets.fanchart import * from fanchart import *
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -52,7 +52,7 @@ from gi.repository import Gdk
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import constants from gramps.plugins.lib.maps import constants
from dummylayer import DummyLayer from dummylayer import DummyLayer
from dummynogps import DummyMapNoGpsPoint from dummynogps import DummyMapNoGpsPoint
from selectionlayer import SelectionLayer from selectionlayer import SelectionLayer

View File

@ -56,7 +56,9 @@ from gi.repository import GObject
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR
from gramps.gen.lib import ChildRefType, EventRoleType, EventType, FamilyRelType, NameType, Person from gramps.gen.lib import (ChildRefType, EventRoleType, EventType,
FamilyRelType, NameType, Person)
from gramps.gen.lib.date import Today
from gramps.gui.editors import EditPerson, EditFamily from gramps.gui.editors import EditPerson, EditFamily
from gramps.gen.utils.db import family_name from gramps.gen.utils.db import family_name
from gramps.gui.display import display_help from gramps.gui.display import display_help
@ -82,7 +84,7 @@ WIKI_HELP_SEC = _('manual|Verify_the_Data...')
_person_cache = {} _person_cache = {}
_family_cache = {} _family_cache = {}
_event_cache = {} _event_cache = {}
_today = gen.lib.date.Today().get_sort_value() _today = Today().get_sort_value()
def find_event(db, handle): def find_event(db, handle):
if handle in _event_cache: if handle in _event_cache:

View File

@ -77,8 +77,10 @@ log = logging.getLogger(".NarrativeWeb")
# GRAMPS module # GRAMPS module
#------------------------------------------------ #------------------------------------------------
from gramps.gen.ggettext import sgettext as _ from gramps.gen.ggettext import sgettext as _
from gramps.gen.lib import ChildRefType, Date, EventType, FamilyRelType, Name, NameType, Person from gramps.gen.lib import (ChildRefType, Date, EventType, FamilyRelType, Name,
from gramps.gen.lib import UrlType, date, NoteType, EventRoleType NameType, Person, UrlType, NoteType,
EventRoleType)
from gramps.gen.lib.date import Today, get_start_day
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION
from gramps.gen.sort import Sort from gramps.gen.sort import Sort
from gramps.gen.plug.menu import PersonOption, NumberOption, StringOption, \ from gramps.gen.plug.menu import PersonOption, NumberOption, StringOption, \
@ -1385,7 +1387,7 @@ class BasePage(object):
text = '' text = ''
if copyright == 0: if copyright == 0:
if self.author: if self.author:
year = date.Today().get_year() year = Today().get_year()
text = '&copy; %(year)d %(person)s' % { text = '&copy; %(year)d %(person)s' % {
'person' : self.author, 'person' : self.author,
'year' : year} 'year' : year}
@ -1499,7 +1501,7 @@ class BasePage(object):
msg = _('Generated by <a href = "%(homepage)s">' msg = _('Generated by <a href = "%(homepage)s">'
'Gramps</a> %(version)s on %(date)s') % { 'Gramps</a> %(version)s on %(date)s') % {
'date': _dd.display(date.Today()), 'date': _dd.display(Today()),
'homepage' : URL_HOMEPAGE, 'homepage' : URL_HOMEPAGE,
'version': VERSION} 'version': VERSION}
@ -1523,7 +1525,7 @@ class BasePage(object):
text = '' text = ''
if copy_nr == 0: if copy_nr == 0:
if self.author: if self.author:
year = date.Today().get_year() year = Today().get_year()
text = '&copy; %(year)d %(person)s' % { text = '&copy; %(year)d %(person)s' % {
'person' : self.author, 'person' : self.author,
'year' : year} 'year' : year}
@ -6123,7 +6125,7 @@ class IndividualPage(BasePage):
birth_date = birth.get_date_object() birth_date = birth.get_date_object()
if birth_date and birth_date is not Date.EMPTY: if birth_date and birth_date is not Date.EMPTY:
alive = probably_alive(self.person, self.dbase_, date.Today() ) alive = probably_alive(self.person, self.dbase_, Today() )
death_date = _find_death_date(self.dbase_, self.person) death_date = _find_death_date(self.dbase_, self.person)
if not alive and death_date is not None: if not alive and death_date is not None:

View File

@ -50,6 +50,7 @@ log = logging.getLogger(".WebPage")
# GRAMPS module # GRAMPS module
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.lib import Date, Name, NameType, Person from gramps.gen.lib import Date, Name, NameType, Person
from gramps.gen.lib.date import Today
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION
from gramps.gen.constfunc import win from gramps.gen.constfunc import win
from gramps.gen.plug.report import Report from gramps.gen.plug.report import Report
@ -148,7 +149,7 @@ class WebCalReport(Report):
self.email = researcher.email self.email = researcher.email
# set to today's date # set to today's date
self.today = gen.lib.date.Today() self.today = Today()
self.warn_dir = True # Only give warning once. self.warn_dir = True # Only give warning once.
@ -559,7 +560,7 @@ class WebCalReport(Report):
elif url_fname == 'fullyearlinked': elif url_fname == 'fullyearlinked':
myTitle = _('Full year at a Glance') myTitle = _('Full year at a Glance')
else: else:
myTitle = _(url_fname) myTitle = _(url_fname)
hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle) hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle)
if check_cs: if check_cs:
@ -1185,8 +1186,7 @@ class WebCalReport(Report):
# Display date as user set in preferences # Display date as user set in preferences
msg = _('Generated by <a href="http://gramps-project.org">' msg = _('Generated by <a href="http://gramps-project.org">'
'Gramps</a> on %(date)s') % {'date' : _dd.display( 'Gramps</a> on %(date)s') % {'date' : _dd.display(Today())}
gen.lib.date.Today())}
footer += Html("p", msg, id = 'createdate') footer += Html("p", msg, id = 'createdate')
copy_nr = self.copy copy_nr = self.copy
@ -1369,7 +1369,7 @@ class WebCalOptions(MenuReportOptions):
category_name = _("Content Options") category_name = _("Content Options")
# set to today's date for use in menu, etc. # set to today's date for use in menu, etc.
today = gen.lib.date.Today() today = Today()
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False) self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.')) self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))

View File

@ -185,48 +185,48 @@ class DbDjango(DbWriteBase, DbReadBase):
# First we add the primary objects: # First we add the primary objects:
for key in self.import_cache.keys(): for key in self.import_cache.keys():
obj = self.import_cache[key] obj = self.import_cache[key]
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
self.dji.add_person(obj.serialize()) self.dji.add_person(obj.serialize())
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
self.dji.add_family(obj.serialize()) self.dji.add_family(obj.serialize())
elif isinstance(obj, gen.lib.Event): elif isinstance(obj, Event):
self.dji.add_event(obj.serialize()) self.dji.add_event(obj.serialize())
elif isinstance(obj, gen.lib.Place): elif isinstance(obj, Place):
self.dji.add_place(obj.serialize()) self.dji.add_place(obj.serialize())
elif isinstance(obj, gen.lib.Repository): elif isinstance(obj, Repository):
self.dji.add_repository(obj.serialize()) self.dji.add_repository(obj.serialize())
elif isinstance(obj, gen.lib.Citation): elif isinstance(obj, Citation):
self.dji.add_citation(obj.serialize()) self.dji.add_citation(obj.serialize())
elif isinstance(obj, gen.lib.Source): elif isinstance(obj, Source):
self.dji.add_source(obj.serialize()) self.dji.add_source(obj.serialize())
elif isinstance(obj, gen.lib.Note): elif isinstance(obj, Note):
self.dji.add_note(obj.serialize()) self.dji.add_note(obj.serialize())
elif isinstance(obj, gen.lib.MediaObject): elif isinstance(obj, MediaObject):
self.dji.add_media(obj.serialize()) self.dji.add_media(obj.serialize())
elif isinstance(obj, gen.lib.Tag): elif isinstance(obj, Tag):
self.dji.add_tag(obj.serialize()) self.dji.add_tag(obj.serialize())
# Next we add the links: # Next we add the links:
for key in self.import_cache.keys(): for key in self.import_cache.keys():
obj = self.import_cache[key] obj = self.import_cache[key]
if isinstance(obj, gen.lib.Person): if isinstance(obj, Person):
self.dji.add_person_detail(obj.serialize()) self.dji.add_person_detail(obj.serialize())
elif isinstance(obj, gen.lib.Family): elif isinstance(obj, Family):
self.dji.add_family_detail(obj.serialize()) self.dji.add_family_detail(obj.serialize())
elif isinstance(obj, gen.lib.Event): elif isinstance(obj, Event):
self.dji.add_event_detail(obj.serialize()) self.dji.add_event_detail(obj.serialize())
elif isinstance(obj, gen.lib.Place): elif isinstance(obj, Place):
self.dji.add_place_detail(obj.serialize()) self.dji.add_place_detail(obj.serialize())
elif isinstance(obj, gen.lib.Repository): elif isinstance(obj, Repository):
self.dji.add_repository_detail(obj.serialize()) self.dji.add_repository_detail(obj.serialize())
elif isinstance(obj, gen.lib.Citation): elif isinstance(obj, Citation):
self.dji.add_citation_detail(obj.serialize()) self.dji.add_citation_detail(obj.serialize())
elif isinstance(obj, gen.lib.Source): elif isinstance(obj, Source):
self.dji.add_source_detail(obj.serialize()) self.dji.add_source_detail(obj.serialize())
elif isinstance(obj, gen.lib.Note): elif isinstance(obj, Note):
self.dji.add_note_detail(obj.serialize()) self.dji.add_note_detail(obj.serialize())
elif isinstance(obj, gen.lib.MediaObject): elif isinstance(obj, MediaObject):
self.dji.add_media_detail(obj.serialize()) self.dji.add_media_detail(obj.serialize())
elif isinstance(obj, gen.lib.Tag): elif isinstance(obj, Tag):
self.dji.add_tag_detail(obj.serialize()) self.dji.add_tag_detail(obj.serialize())
self.use_import_cache = False self.use_import_cache = False
self.import_cache = {} self.import_cache = {}
@ -495,7 +495,7 @@ class DbDjango(DbWriteBase, DbReadBase):
return None return None
def get_researcher(self): def get_researcher(self):
obj = gen.lib.Researcher() obj = Researcher()
return obj return obj
def get_tag_handles(self, sort_handles=False): def get_tag_handles(self, sort_handles=False):
@ -619,67 +619,67 @@ class DbDjango(DbWriteBase, DbReadBase):
data = cPickle.loads(base64.decodestring(repository.cache)) data = cPickle.loads(base64.decodestring(repository.cache))
else: else:
data = self.dji.get_repository(repository) data = self.dji.get_repository(repository)
return gen.lib.Repository.create(data) return Repository.create(data)
def make_citation(self, citation): def make_citation(self, citation):
if self.use_db_cache and citation.cache: if self.use_db_cache and citation.cache:
data = cPickle.loads(base64.decodestring(citation.cache)) data = cPickle.loads(base64.decodestring(citation.cache))
else: else:
data = self.dji.get_citation(citation) data = self.dji.get_citation(citation)
return gen.lib.Citation.create(data) return Citation.create(data)
def make_source(self, source): def make_source(self, source):
if self.use_db_cache and source.cache: if self.use_db_cache and source.cache:
data = cPickle.loads(base64.decodestring(source.cache)) data = cPickle.loads(base64.decodestring(source.cache))
else: else:
data = self.dji.get_source(source) data = self.dji.get_source(source)
return gen.lib.Source.create(data) return Source.create(data)
def make_family(self, family): def make_family(self, family):
if self.use_db_cache and family.cache: if self.use_db_cache and family.cache:
data = cPickle.loads(base64.decodestring(family.cache)) data = cPickle.loads(base64.decodestring(family.cache))
else: else:
data = self.dji.get_family(family) data = self.dji.get_family(family)
return gen.lib.Family.create(data) return Family.create(data)
def make_person(self, person): def make_person(self, person):
if self.use_db_cache and person.cache: if self.use_db_cache and person.cache:
data = cPickle.loads(base64.decodestring(person.cache)) data = cPickle.loads(base64.decodestring(person.cache))
else: else:
data = self.dji.get_person(person) data = self.dji.get_person(person)
return gen.lib.Person.create(data) return Person.create(data)
def make_event(self, event): def make_event(self, event):
if self.use_db_cache and event.cache: if self.use_db_cache and event.cache:
data = cPickle.loads(base64.decodestring(event.cache)) data = cPickle.loads(base64.decodestring(event.cache))
else: else:
data = self.dji.get_event(event) data = self.dji.get_event(event)
return gen.lib.Event.create(data) return Event.create(data)
def make_note(self, note): def make_note(self, note):
if self.use_db_cache and note.cache: if self.use_db_cache and note.cache:
data = cPickle.loads(base64.decodestring(note.cache)) data = cPickle.loads(base64.decodestring(note.cache))
else: else:
data = self.dji.get_note(note) data = self.dji.get_note(note)
return gen.lib.Note.create(data) return Note.create(data)
def make_tag(self, tag): def make_tag(self, tag):
data = self.dji.get_tag(tag) data = self.dji.get_tag(tag)
return gen.lib.Tag.create(data) return Tag.create(data)
def make_place(self, place): def make_place(self, place):
if self.use_db_cache and place.cache: if self.use_db_cache and place.cache:
data = cPickle.loads(base64.decodestring(place.cache)) data = cPickle.loads(base64.decodestring(place.cache))
else: else:
data = self.dji.get_place(place) data = self.dji.get_place(place)
return gen.lib.Place.create(data) return Place.create(data)
def make_media(self, media): def make_media(self, media):
if self.use_db_cache and media.cache: if self.use_db_cache and media.cache:
data = cPickle.loads(base64.decodestring(media.cache)) data = cPickle.loads(base64.decodestring(media.cache))
else: else:
data = self.dji.get_media(media) data = self.dji.get_media(media)
return gen.lib.MediaObject.create(data) return MediaObject.create(data)
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
if handle in self.import_cache: if handle in self.import_cache: