Pylint improvements
This commit is contained in:
parent
fdccc733a2
commit
05800c530a
@ -46,9 +46,6 @@ _ = glocale.translation.gettext
|
|||||||
|
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.db import DbTxn
|
from gramps.gen.db import DbTxn
|
||||||
from gramps.gen.lib import (Person, Family, Event, Place,
|
|
||||||
Source, Citation, Repository,
|
|
||||||
Media, Note)
|
|
||||||
from gramps.gen.updatecallback import UpdateCallback
|
from gramps.gen.updatecallback import UpdateCallback
|
||||||
|
|
||||||
from gramps.gui.display import display_help
|
from gramps.gui.display import display_help
|
||||||
@ -207,6 +204,7 @@ class ReorderEntry(object):
|
|||||||
""" gets Keep flag """
|
""" gets Keep flag """
|
||||||
return self.keep_obj
|
return self.keep_obj
|
||||||
|
|
||||||
|
|
||||||
class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
||||||
""" Class for Reodering Gramps ID Tool """
|
""" Class for Reodering Gramps ID Tool """
|
||||||
xobjects = (('person', 'people'), ('family', 'families'),
|
xobjects = (('person', 'people'), ('family', 'families'),
|
||||||
@ -246,7 +244,6 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
|
|
||||||
self.prim_methods, self.obj_methods = {}, {}
|
self.prim_methods, self.obj_methods = {}, {}
|
||||||
for prim_obj, prim_objs in self.xobjects:
|
for prim_obj, prim_objs in self.xobjects:
|
||||||
class_type = prim_obj.title()
|
|
||||||
iter_handles = "iter_%s_handles" % prim_obj
|
iter_handles = "iter_%s_handles" % prim_obj
|
||||||
get_number_obj = "get_number_of_%s" % prim_objs
|
get_number_obj = "get_number_of_%s" % prim_objs
|
||||||
prefix_fmt = "%s_prefix" % prim_obj
|
prefix_fmt = "%s_prefix" % prim_obj
|
||||||
@ -258,8 +255,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
self.prim_methods[prim_obj] = (getattr(self.db, prefix_fmt),
|
self.prim_methods[prim_obj] = (getattr(self.db, prefix_fmt),
|
||||||
getattr(self.db, get_number_obj)(),
|
getattr(self.db, get_number_obj)(),
|
||||||
getattr(self.db, next_from_id)())
|
getattr(self.db, next_from_id)())
|
||||||
self.obj_methods[prim_obj] = (class_type,
|
self.obj_methods[prim_obj] = (getattr(self.db, iter_handles),
|
||||||
getattr(self.db, iter_handles),
|
|
||||||
getattr(self.db, commit),
|
getattr(self.db, commit),
|
||||||
getattr(self.db, get_from_id),
|
getattr(self.db, get_from_id),
|
||||||
getattr(self.db, get_from_handle),
|
getattr(self.db, get_from_handle),
|
||||||
@ -279,7 +275,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
""" compute all primary objects and toggle the 'Active' attribute """
|
""" compute all primary objects and toggle the 'Active' attribute """
|
||||||
self.object_status = not self.object_status
|
self.object_status = not self.object_status
|
||||||
|
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj = self.top.get_object('%s_active' % prim_obj)
|
obj = self.top.get_object('%s_active' % prim_obj)
|
||||||
obj.set_active(self.object_status)
|
obj.set_active(self.object_status)
|
||||||
|
|
||||||
@ -303,7 +299,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
def __on_format_button_clicked(self, widget=None):
|
def __on_format_button_clicked(self, widget=None):
|
||||||
""" compute all sensitive primary objects and sets the
|
""" compute all sensitive primary objects and sets the
|
||||||
'Format' scheme of identifiers """
|
'Format' scheme of identifiers """
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj_format = self.top.get_object('%s_format' % prim_obj)
|
obj_format = self.top.get_object('%s_format' % prim_obj)
|
||||||
if not obj_format.get_sensitive():
|
if not obj_format.get_sensitive():
|
||||||
continue
|
continue
|
||||||
@ -320,7 +316,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
""" compute all primary objects and toggle the 'Change' attribute """
|
""" compute all primary objects and toggle the 'Change' attribute """
|
||||||
self.change_status = not self.change_status
|
self.change_status = not self.change_status
|
||||||
|
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj_change = self.top.get_object('%s_change' % prim_obj)
|
obj_change = self.top.get_object('%s_change' % prim_obj)
|
||||||
if not obj_change.get_sensitive():
|
if not obj_change.get_sensitive():
|
||||||
continue
|
continue
|
||||||
@ -351,7 +347,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
'Start' values of identifiers """
|
'Start' values of identifiers """
|
||||||
self.start_zero = not self.start_zero
|
self.start_zero = not self.start_zero
|
||||||
|
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj = self.top.get_object('%s_start' % prim_obj)
|
obj = self.top.get_object('%s_start' % prim_obj)
|
||||||
if not obj.get_sensitive():
|
if not obj.get_sensitive():
|
||||||
continue
|
continue
|
||||||
@ -367,7 +363,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
'Step' width of identifiers """
|
'Step' width of identifiers """
|
||||||
self.step_cnt = self.step_cnt + 1 if self.step_cnt < 3 else 0
|
self.step_cnt = self.step_cnt + 1 if self.step_cnt < 3 else 0
|
||||||
|
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj = self.top.get_object('%s_step' % prim_obj)
|
obj = self.top.get_object('%s_step' % prim_obj)
|
||||||
if not obj.get_sensitive():
|
if not obj.get_sensitive():
|
||||||
continue
|
continue
|
||||||
@ -379,7 +375,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
""" compute the primary object and toggle the 'Active' attribute """
|
""" compute the primary object and toggle the 'Active' attribute """
|
||||||
self.keep_status = not self.keep_status
|
self.keep_status = not self.keep_status
|
||||||
|
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
obj = self.top.get_object('%s_change' % prim_obj)
|
obj = self.top.get_object('%s_change' % prim_obj)
|
||||||
if not obj.get_active():
|
if not obj.get_active():
|
||||||
continue
|
continue
|
||||||
@ -441,7 +437,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
window = self.top.toplevel
|
window = self.top.toplevel
|
||||||
|
|
||||||
# set gramps style title for the window
|
# set gramps style title for the window
|
||||||
self.set_window(window, self.top.get_object("title"), \
|
self.set_window(window, self.top.get_object("title"),
|
||||||
_("Reorder Gramps IDs"))
|
_("Reorder Gramps IDs"))
|
||||||
|
|
||||||
# connect signals
|
# connect signals
|
||||||
@ -463,40 +459,40 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Calculate all entries and update Glade window
|
# Calculate all entries and update Glade window
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
# populate Object, Actual & Quantity fields with values
|
# populate Object, Actual & Quantity fields with values
|
||||||
obj_active = self.top.get_object('%s_active' % prim_obj)
|
obj_active = self.top.get_object('%s_active' % prim_obj)
|
||||||
self.active_entries[prim_obj] = MonitoredCheckbox(obj_active, obj_active,
|
self.active_entries[prim_obj] = MonitoredCheckbox(
|
||||||
self.obj_values[prim_obj].set_active,
|
obj_active, obj_active, self.obj_values[prim_obj].set_active,
|
||||||
self.obj_values[prim_obj].get_active)
|
self.obj_values[prim_obj].get_active)
|
||||||
obj_actual = self.top.get_object('%s_actual' % prim_obj)
|
obj_actual = self.top.get_object('%s_actual' % prim_obj)
|
||||||
obj_actual.set_text('%s' % self.obj_values[prim_obj].last_id())
|
obj_actual.set_text('%s' % self.obj_values[prim_obj].last_id())
|
||||||
obj_quant = self.top.get_object('%s_quant' % prim_obj)
|
obj_quant = self.top.get_object('%s_quant' % prim_obj)
|
||||||
obj_quant.set_text('%s' % str(self.obj_values[prim_obj].quant_id))
|
obj_quant.set_text('%s' % str(self.obj_values[prim_obj].quant_id))
|
||||||
|
|
||||||
# connect/populate Format, Start, Step, Keep & Change fields with GTK/values
|
# connect/populate Format, Start, Step, Keep & Change fields
|
||||||
|
# with GTK/values
|
||||||
obj_format = self.top.get_object('%s_format' % prim_obj)
|
obj_format = self.top.get_object('%s_format' % prim_obj)
|
||||||
self.format_entries[prim_obj] = MonitoredEntry(obj_format,
|
self.format_entries[prim_obj] = MonitoredEntry(
|
||||||
self.obj_values[prim_obj].set_fmt,
|
obj_format, self.obj_values[prim_obj].set_fmt,
|
||||||
self.obj_values[prim_obj].get_fmt)
|
self.obj_values[prim_obj].get_fmt)
|
||||||
obj_change = self.top.get_object('%s_change' % prim_obj)
|
obj_change = self.top.get_object('%s_change' % prim_obj)
|
||||||
self.change_entries[prim_obj] = MonitoredCheckbox(obj_change, obj_change,
|
self.change_entries[prim_obj] = MonitoredCheckbox(
|
||||||
self.obj_values[prim_obj].set_change,
|
obj_change, obj_change, self.obj_values[prim_obj].set_change,
|
||||||
self.obj_values[prim_obj].get_change)
|
self.obj_values[prim_obj].get_change)
|
||||||
obj_start = self.top.get_object('%s_start' % prim_obj)
|
obj_start = self.top.get_object('%s_start' % prim_obj)
|
||||||
self.start_entries[prim_obj] = MonitoredEntry(obj_start,
|
self.start_entries[prim_obj] = MonitoredEntry(
|
||||||
self.obj_values[prim_obj].set_id,
|
obj_start, self.obj_values[prim_obj].set_id,
|
||||||
self.obj_values[prim_obj].get_id)
|
self.obj_values[prim_obj].get_id)
|
||||||
obj_step = self.top.get_object('%s_step' % prim_obj)
|
obj_step = self.top.get_object('%s_step' % prim_obj)
|
||||||
self.step_entries[prim_obj] = MonitoredEntry(obj_step,
|
self.step_entries[prim_obj] = MonitoredEntry(
|
||||||
self.obj_values[prim_obj].set_step,
|
obj_step, self.obj_values[prim_obj].set_step,
|
||||||
self.obj_values[prim_obj].get_step,
|
self.obj_values[prim_obj].get_step,
|
||||||
changed=self.obj_values[prim_obj].change_step)
|
changed=self.obj_values[prim_obj].change_step)
|
||||||
obj_keep = self.top.get_object('%s_keep' % prim_obj)
|
obj_keep = self.top.get_object('%s_keep' % prim_obj)
|
||||||
self.keep_entries[prim_obj] = MonitoredCheckbox(obj_keep, obj_keep,
|
self.keep_entries[prim_obj] = MonitoredCheckbox(
|
||||||
self.obj_values[prim_obj].set_keep,
|
obj_keep, obj_keep, self.obj_values[prim_obj].set_keep,
|
||||||
self.obj_values[prim_obj].get_keep,
|
self.obj_values[prim_obj].get_keep, readonly=True)
|
||||||
readonly=True)
|
|
||||||
|
|
||||||
# fetch the popup menu
|
# fetch the popup menu
|
||||||
self.menu = self.top.get_object("popup_menu")
|
self.menu = self.top.get_object("popup_menu")
|
||||||
@ -537,7 +533,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
self.progress = ProgressMeter(_('Reorder Gramps IDs'), '')
|
self.progress = ProgressMeter(_('Reorder Gramps IDs'), '')
|
||||||
else:
|
else:
|
||||||
total_objs = 0
|
total_objs = 0
|
||||||
for prim_obj, tmp in self.xobjects:
|
for prim_obj, dummy in self.xobjects:
|
||||||
if self.obj_values[prim_obj].active_obj:
|
if self.obj_values[prim_obj].active_obj:
|
||||||
total_objs += self.obj_values[prim_obj].quant_id
|
total_objs += self.obj_values[prim_obj].quant_id
|
||||||
self.set_total(total_objs)
|
self.set_total(total_objs)
|
||||||
@ -545,12 +541,12 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
# Update database
|
# Update database
|
||||||
self.db.disable_signals()
|
self.db.disable_signals()
|
||||||
for prim_obj, prim_objs in self.xobjects:
|
for prim_obj, prim_objs in self.xobjects:
|
||||||
with DbTxn(_('Reorder %s IDs ...') % prim_obj, self.db, batch=True) \
|
with DbTxn(_('Reorder %s IDs ...') % prim_obj,
|
||||||
as self.trans:
|
self.db, batch=True) as self.trans:
|
||||||
if self.obj_values[prim_obj].active_obj:
|
if self.obj_values[prim_obj].active_obj:
|
||||||
if self.uistate:
|
if self.uistate:
|
||||||
self.progress.set_pass(_('Reorder %s IDs ...') % \
|
self.progress.set_pass(
|
||||||
_(prim_objs.title()), \
|
_('Reorder %s IDs ...') % _(prim_objs.title()),
|
||||||
self.obj_values[prim_obj].quant_id)
|
self.obj_values[prim_obj].quant_id)
|
||||||
# Process reordering
|
# Process reordering
|
||||||
self._reorder(prim_obj)
|
self._reorder(prim_obj)
|
||||||
@ -576,7 +572,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
dup_ids = [] # list of duplicate identifiers
|
dup_ids = [] # list of duplicate identifiers
|
||||||
new_ids = {} # list of new identifiers
|
new_ids = {} # list of new identifiers
|
||||||
|
|
||||||
class_type, iter_handles, commit, get_from_id, get_from_handle, next_from_id = \
|
iter_handles, commit, get_from_id, get_from_handle, next_from_id = \
|
||||||
self.obj_methods[prim_obj]
|
self.obj_methods[prim_obj]
|
||||||
|
|
||||||
prefix_fmt = self.obj_values[prim_obj].get_fmt()
|
prefix_fmt = self.obj_values[prim_obj].get_fmt()
|
||||||
@ -641,8 +637,8 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if change:
|
if change:
|
||||||
# update the defined ID numbers into objects under consideration
|
# update the defined ID numbers into objects under
|
||||||
# of keeping ID if format not matches prefix
|
# consideration of keeping ID if format not matches prefix
|
||||||
# (implication logical boolean operator below)
|
# (implication logical boolean operator below)
|
||||||
if act_id.startswith(prefix) and act_id.endswith(suffix) or \
|
if act_id.startswith(prefix) and act_id.endswith(suffix) or \
|
||||||
not keep_fmt:
|
not keep_fmt:
|
||||||
@ -650,7 +646,8 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
commit(obj, self.trans)
|
commit(obj, self.trans)
|
||||||
new_id = self.obj_values[prim_obj].succ_id()
|
new_id = self.obj_values[prim_obj].succ_id()
|
||||||
else:
|
else:
|
||||||
# attempt to extract integer - if we can't, treat it as a duplicate
|
# attempt to extract integer - if we can't, treat it as a
|
||||||
|
# duplicate
|
||||||
try:
|
try:
|
||||||
match = self._findint.match(act_id)
|
match = self._findint.match(act_id)
|
||||||
if match:
|
if match:
|
||||||
@ -684,12 +681,14 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback):
|
|||||||
# handle that matches the new scheme.
|
# handle that matches the new scheme.
|
||||||
if dup_ids:
|
if dup_ids:
|
||||||
if self.uistate:
|
if self.uistate:
|
||||||
self.progress.set_pass(_('Finding and assigning unused IDs.'), len(dup_ids))
|
self.progress.set_pass(_('Finding and assigning unused IDs.'),
|
||||||
|
len(dup_ids))
|
||||||
for handle in dup_ids:
|
for handle in dup_ids:
|
||||||
obj = get_from_handle(handle)
|
obj = get_from_handle(handle)
|
||||||
obj.set_gramps_id(next_from_id())
|
obj.set_gramps_id(next_from_id())
|
||||||
commit(obj, self.trans)
|
commit(obj, self.trans)
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user