From d5ca13254f3432c9d02b1991a6911d21d532b076 Mon Sep 17 00:00:00 2001 From: prculley Date: Thu, 24 Aug 2017 12:11:10 -0500 Subject: [PATCH] Correct ReorderID tool for several bugs and deal with GetGov ID Fixes #10177, #10175, #10176 --- gramps/plugins/tool/reorderids.glade | 2874 +++++++++++++------------- gramps/plugins/tool/reorderids.py | 117 +- 2 files changed, 1499 insertions(+), 1492 deletions(-) diff --git a/gramps/plugins/tool/reorderids.glade b/gramps/plugins/tool/reorderids.glade index 3cd6ef2c9..e6d60c293 100644 --- a/gramps/plugins/tool/reorderids.glade +++ b/gramps/plugins/tool/reorderids.glade @@ -1,1510 +1,136 @@ - + - + False - False - True - center-on-parent - True + 600 dialog - False - + True False vertical - - + + True False - 10 - 5 - - - + end + + + _No + True + True + True + False + Do not apply the operation to this item + True + + + False + False + 1 + + + + + _Yes + True + True + True + True + True + False + Apply the operation to this item + True + + + False + False + 2 + + False True + end 0 - + True False - end - center - 5 - 4 - 2 - True + 12 - - 1 - -1 - True - False - True - 8 - False - False - False - False - - - - 6 - 1 - 1 - 1 - - - - - True - False - True - 8 - False - False - False - False - - - - 6 - 2 - 1 - 1 - - - - - True - False - True - 8 - False - False - False - False - - - - 6 - 3 - 1 - 1 - - - - - True - False - True - 8 - False - False - False - False - - - - 6 - 4 - 1 - 1 - - - - - True - False - True - 8 - False - False - False - False - - - - 6 - 5 - 1 - 1 - - - - - True - False - True - 8 - False - False - False - False - - - - 6 - 6 - 1 - 1 - - - - - True - False - True - 8 - - - - 6 - 7 - 1 - 1 - - - - - True - False - True - 8 - - - - 6 - 8 - 1 - 1 - - - - - True - False - True - 8 - - - - 6 - 9 - 1 - 1 - - - - - 10 - True - False - True - 4 - False - False - False - False - - - 7 - 1 - 1 - 1 - - - - - True - False - True - 4 - False - False - False - False - digits - - - 7 - 2 - 1 - 1 - - - - - True - False - True - 4 - False - False - False - False - digits - - - 7 - 3 - 1 - 1 - - - - - True - False - True - 4 - False - False - False - False - number - - - 7 - 4 - 1 - 1 - - - - - True - False - True - 4 - False - False - False - False - number - - - 7 - 5 - 1 - 1 - - - - - True - False - True - 4 - False - False - False - False - number - - - 7 - 6 - 1 - 1 - - - - - True - False - True - 4 - number - - - 7 - 7 - 1 - 1 - - - - - True - False - True - 4 - number - - - 7 - 8 - 1 - 1 - - - - - True - False - True - 4 - number - - - 7 - 9 - 1 - 1 - - - - - True - True - start - False - 8 - False - - - 2 - 1 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 2 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 3 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 4 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 5 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 6 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 7 - 1 - 1 - - - - - True - True - False - 8 - False - - - 2 - 8 - 1 - 1 - - - - - 0 - True - True - False - 8 - False - - - 2 - 9 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 1 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 2 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 3 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 4 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 5 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 6 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 7 - 1 - 1 - - - - - True - True - False - 6 - False - - - 3 - 8 - 1 - 1 - - - - - 0 - True - True - False - 6 - False - - - 3 - 9 - 1 - 1 - - - - + True False start - Person - 1 + 6 + 6 + 24 + 24 + True + True + True + start 1 1 - 1 - 1 - + + True + False + start + 48 + dialog-warning + 6 + + + 0 + 0 + + + + True False start - Family - 0 - - - 1 - 2 - 1 - 1 - - - - - True - False - start - Event - - - 1 - 3 - 1 - 1 - - - - - True - False - start - Place - - - 1 - 4 - 1 - 1 - - - - - True - False - start - Source - - - 1 - 5 - 1 - 1 - - - - - True - False - start - Citation - - - 1 - 6 - 1 - 1 - - - - - True - False - start - Repository - 12 - - - 1 - 7 - 1 - 1 - - - - - True - False - start - Media - - - 1 - 8 - 1 - 1 - - - - - True - False - start - Note - - - 1 - 9 - 1 - 1 - - - - - True - True - False - queue - 0 - True - True - - - - 0 - 1 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 2 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 3 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 4 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 5 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 6 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 7 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 8 - 1 - 1 - - - - - True - True - False - 0 - True - True - - - - 0 - 9 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 1 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 2 - 1 - 1 - - - - - True - True - 8 - out - - - - - 4 - 3 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 4 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 5 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 6 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 7 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 8 - 1 - 1 - - - - - True - True - 8 - - - - - 4 - 9 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 1 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 2 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 3 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 4 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 5 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 6 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 7 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 8 - 1 - 1 - - - - - True - False - True - False - center - 0 - True - - - 8 - 9 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 1 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 2 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 3 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 4 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 5 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 6 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 7 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 8 - 1 - 1 - - - - - True - True - False - center - 0 - True - - - - 5 - 9 - 1 - 1 - - - - - Object - True - True - False - Enable ID reordering. - start - none - False - + 6 + 6 + True + True + True 1 0 - 1 - 1 - - True - False - List next ID available -(maynot be continuous). - start - Actual - fill - - - 2 - 0 - 1 - 1 - - - - - True - False - Amount of ID in use. - start - Quantity - - - 3 - 0 - 1 - 1 - - - - - Format + + _Use this answer for the rest of the items True True False - Actual / Upcoming ID format. - start - none - False - + If you check this button, your next answer will apply to the rest of the selected items + center + True + 0.5 + True - 4 - 0 - 1 - 1 + 1 + 2 - - Change - True - True - True - Enable ID reordering -with Start / Step sequence. - immediate - none - False - - - - 5 - 0 - 1 - 1 - - - - - Start - True - True - False - Reorder ID start number. - start - none - False - - - - 6 - 0 - 1 - 1 - - - - - Step - True - True - True - Reorder ID step width. - start - none - False - - - - 7 - 0 - 1 - 1 - - - - - Keep - True - True - True - Keep IDs with alternate -prefixes untouched. - none - False - - - - 8 - 0 - 1 - 1 - + @@ -1512,10 +138,31 @@ prefixes untouched. False - True + False 1 + + + + button184 + button185 + + + + + + + False + True + center-on-parent + True + dialog + + + True + False + vertical True @@ -1585,6 +232,1314 @@ prefixes untouched. 3 + + + True + False + 10 + 5 + + + + + + False + True + 0 + + + + + True + False + center + True + 5 + 4 + 2 + True + + + True + False + True + True + 8 + + + + 6 + 1 + + + + + True + False + True + True + 8 + + + + 6 + 2 + + + + + True + False + True + True + 8 + + + + 6 + 3 + + + + + True + False + True + True + 8 + + + + 6 + 4 + + + + + True + False + True + True + 8 + + + + 6 + 5 + + + + + True + False + True + True + 8 + + + + 6 + 6 + + + + + True + False + True + True + 8 + + + + 6 + 7 + + + + + True + False + True + True + 8 + + + + 6 + 8 + + + + + True + False + True + True + 8 + + + + 6 + 9 + + + + + True + False + True + start + 6 + digits + + + 7 + 1 + + + + + True + False + True + start + 6 + digits + + + 7 + 2 + + + + + True + False + True + start + 6 + digits + + + 7 + 3 + + + + + True + False + True + start + 6 + digits + + + 7 + 4 + + + + + True + False + True + start + 6 + digits + + + 7 + 5 + + + + + True + False + True + start + 6 + digits + + + 7 + 6 + + + + + True + False + True + start + 6 + digits + + + 7 + 7 + + + + + True + False + True + start + 6 + digits + + + 7 + 8 + + + + + True + False + True + start + 6 + digits + + + 7 + 9 + + + + + True + False + True + False + 8 + False + + + 2 + 1 + + + + + True + False + True + False + 8 + False + + + 2 + 2 + + + + + True + False + True + False + 8 + False + + + 2 + 3 + + + + + True + False + True + False + 8 + False + + + 2 + 4 + + + + + True + False + True + False + 8 + False + + + 2 + 5 + + + + + True + False + True + False + 8 + False + + + 2 + 6 + + + + + True + False + True + False + 8 + False + + + 2 + 7 + + + + + True + False + True + False + 8 + False + + + 2 + 8 + + + + + True + False + True + False + 8 + False + + + 2 + 9 + + + + + False + start + False + 6 + False + + + 3 + 1 + + + + + False + start + False + 6 + False + + + 3 + 2 + + + + + False + start + False + 6 + False + + + 3 + 3 + + + + + False + start + False + 6 + False + + + 3 + 4 + + + + + False + start + False + 6 + False + + + 3 + 5 + + + + + False + start + False + 6 + False + + + 3 + 6 + + + + + False + start + False + 6 + False + + + 3 + 7 + + + + + False + start + False + 6 + False + + + 3 + 8 + + + + + False + start + False + 6 + False + + + 3 + 9 + + + + + True + False + start + Person + 1 + + + 1 + 1 + + + + + True + False + start + Family + 0 + + + 1 + 2 + + + + + True + False + start + Event + + + 1 + 3 + + + + + True + False + start + Place + + + 1 + 4 + + + + + True + False + start + Source + + + 1 + 5 + + + + + True + False + start + Citation + + + 1 + 6 + + + + + True + False + start + Repository + 12 + + + 1 + 7 + + + + + True + False + start + Media + + + 1 + 8 + + + + + True + False + start + Note + + + 1 + 9 + + + + + True + True + False + queue + 0 + True + True + + + + 0 + 1 + + + + + True + True + False + 0 + True + True + + + + 0 + 2 + + + + + True + True + False + 0 + True + True + + + + 0 + 3 + + + + + True + True + False + 0 + True + True + + + + 0 + 4 + + + + + True + True + False + 0 + True + True + + + + 0 + 5 + + + + + True + True + False + 0 + True + True + + + + 0 + 6 + + + + + True + True + False + 0 + True + True + + + + 0 + 7 + + + + + True + True + False + 0 + True + True + + + + 0 + 8 + + + + + True + True + False + 0 + True + True + + + + 0 + 9 + + + + + True + True + True + 10 + + + + + 4 + 1 + + + + + True + True + True + 10 + + + + + 4 + 2 + + + + + True + True + True + 10 + + + + + 4 + 3 + + + + + True + True + True + 10 + + + + + 4 + 4 + + + + + True + True + True + 10 + + + + + 4 + 5 + + + + + True + True + True + 10 + + + + + 4 + 6 + + + + + True + True + True + 10 + + + + + 4 + 7 + + + + + True + True + True + 10 + + + + + 4 + 8 + + + + + True + True + True + 10 + + + + + 4 + 9 + + + + + True + False + True + False + center + 0 + True + + + 8 + 1 + + + + + True + False + True + False + center + 0 + True + + + 8 + 2 + + + + + True + False + True + False + center + 0 + True + + + 8 + 3 + + + + + True + False + True + False + center + 0 + True + + + 8 + 4 + + + + + True + False + True + False + center + 0 + True + + + 8 + 5 + + + + + True + False + True + False + center + 0 + True + + + 8 + 6 + + + + + True + False + True + False + center + 0 + True + + + 8 + 7 + + + + + True + False + True + False + center + 0 + True + + + 8 + 8 + + + + + True + False + True + False + center + 0 + True + + + 8 + 9 + + + + + True + True + False + center + 0 + True + + + + 5 + 1 + + + + + True + True + False + center + 0 + True + + + + 5 + 2 + + + + + True + True + False + center + 0 + True + + + + 5 + 3 + + + + + True + True + False + center + 0 + True + + + + 5 + 4 + + + + + True + True + False + center + 0 + True + + + + 5 + 5 + + + + + True + True + False + center + 0 + True + + + + 5 + 6 + + + + + True + True + False + center + 0 + True + + + + 5 + 7 + + + + + True + True + False + center + 0 + True + + + + 5 + 8 + + + + + True + True + False + center + 0 + True + + + + 5 + 9 + + + + + Object + True + True + False + False + Enable ID reordering. + start + none + + + + 1 + 0 + + + + + True + False + List next ID available +(maynot be continuous). + start + True + Actual + fill + + + 2 + 0 + + + + + True + False + Amount of ID in use. + start + Quantity + + + 3 + 0 + + + + + Format + True + True + False + False + Actual / Upcoming ID format. + start + True + none + + + + 4 + 0 + + + + + Change + True + True + False + True + Enable ID reordering +with Start / Step sequence. + immediate + none + + + + 5 + 0 + + + + + Start + True + True + False + False + Reorder ID start number. + start + True + none + + + + 6 + 0 + + + + + Step + True + True + False + True + Reorder ID step width. + start + none + + + + 7 + 0 + + + + + Keep + True + True + False + True + Keep IDs with alternate +prefixes untouched. + none + + + + 8 + 0 + + + + + + + + False + True + 1 + + @@ -1592,5 +1547,8 @@ prefixes untouched. reorder_ok reorder_help + + + diff --git a/gramps/plugins/tool/reorderids.py b/gramps/plugins/tool/reorderids.py index 46911e7b5..d1836ceae 100644 --- a/gramps/plugins/tool/reorderids.py +++ b/gramps/plugins/tool/reorderids.py @@ -66,27 +66,37 @@ from gramps.gui.widgets import MonitoredCheckbox, MonitoredEntry WIKI_HELP_PAGE = '%s_-_Tools' % URL_MANUAL_PAGE WIKI_HELP_SEC = _('manual|Reorder_Gramps_ID') +PREFIXES = {'person': 'i', 'family': 'f', 'event': 'e', 'place': 'p', + 'source': 's', 'citation': 'c', 'repository': 'r', + 'media': 'o', 'note': 'n'} #------------------------------------------------------------------------- # # Actual tool # #------------------------------------------------------------------------- -# gets the number specified in a format string, eg: %04d returns '04' -_parseformat = re.compile('.*%(\d+)[^\d]+') +# gets the prefix, number, suffix specified in a format string, eg: +# P%04dX returns 'P', '04', 'X' It has to have the integer format with at +# least 3 digits to pass. +_parseformat = re.compile(r'(^[^\d]*)%(0[3-9])d([^\d]*$)') + class ReorderEntry(object): """ Class for internal values for every primary object """ - def __init__(self, object_fmt, quant_id, nextgramps_id): + def __init__(self, object_fmt, quant_id, nextgramps_id, obj): + self.object = obj self.width_fmt = 4 - self.object_fmt, self.object_prefix = '', '' + self.object_fmt, self.object_prefix, self.object_suffix = '', '', '' self.quant_id, self.actual_id, self.actgramps_id = 0, 0, '0' self.calc_id(object_fmt, quant_id) - self.stored_fmt = object_fmt + self.stored_fmt = self.object_fmt self.stored_prefix = self.object_prefix + self.stored_suffix = self.object_suffix - self.number_id = int(nextgramps_id.split(self.object_prefix, 1)[1]) + self.number_id = int(nextgramps_id[len(self.object_prefix): + (len(nextgramps_id) - + len(self.object_suffix))]) self.step_id = 1 self.active_obj, self.change_obj, self.keep_obj = True, False, False @@ -101,7 +111,7 @@ class ReorderEntry(object): def set_fmt(self, object_fmt): """ sets primary object format """ if object_fmt: - self.calc_id(object_fmt, self.quant_id) + self.calc_id(object_fmt.strip(), self.quant_id) def get_fmt(self): """ gets primary object format """ @@ -121,19 +131,26 @@ class ReorderEntry(object): def __ret_gid(self, actual): """ return Gramps ID in correct format """ - return '%s%s' % \ - (self.object_prefix, str(actual).zfill(self.width_fmt)) + return '%s%s%s' % \ + (self.object_prefix, str(actual).zfill(self.width_fmt), + self.object_suffix) def calc_id(self, object_fmt, quant_id): - """ calculates identifier prefix, format & actual value """ - self.object_prefix = object_fmt.split('%', 1)[0] if '%' in object_fmt else '' + """ calculates identifier prefix, suffix, format & actual value. + Requires a valid format or returns the default instead """ self.object_fmt, self.quant_id = object_fmt, quant_id # Default values, ID counting starts with zero! - self.width_fmt, self.actual_id = 4, 0 formatmatch = _parseformat.match(object_fmt) if formatmatch: - self.width_fmt = int(formatmatch.groups()[0]) + self.object_prefix = formatmatch.groups()[0] + self.width_fmt = int(formatmatch.groups()[1]) + self.object_suffix = formatmatch.groups()[2] + else: # not a legal format string, use default + self.object_prefix = PREFIXES[self.object].upper() + self.width_fmt = 4 + self.object_suffix = '' + self.object_fmt = PREFIXES[self.object].upper() + "%04d" self.actgramps_id = self.__ret_gid(self.actual_id) def zero_id(self): @@ -246,7 +263,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): object_fmt, quant_id, next_id = self.prim_methods[prim_obj] - obj_value = ReorderEntry(object_fmt, quant_id, next_id) + obj_value = ReorderEntry(object_fmt, quant_id, next_id, prim_obj) self.obj_values[prim_obj] = obj_value if self.uistate: @@ -315,8 +332,10 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): for obj_entry in ['start', 'step', 'keep']: obj = self.top.get_object('%s_%s' % (obj_name, obj_entry)) if obj_entry == 'keep': - if self.obj_values[obj_name].stored_prefix != \ - self.obj_values[obj_name].object_prefix: + if (self.obj_values[obj_name].stored_prefix != + self.obj_values[obj_name].object_prefix and + self.obj_values[obj_name].stored_suffix != + self.obj_values[obj_name].object_suffix): self.keep_entries[obj_name].set_val(False) else: obj.set_active(obj_state) @@ -383,7 +402,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): obj_name = Gtk.Buildable.get_name(widget).split('_', 1)[0] obj_fmt = self.format_entries[obj_name].get_val() - self.format_entries[obj_name].set_val(obj_fmt) + self.format_entries[obj_name].set_text(obj_fmt) self.start_entries[obj_name].update() return False @@ -479,17 +498,17 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): self.menu = self.top.get_object("popup_menu") # ok, let's see what we've done + self.window.resize(700, 410) self.show() def _update(self): """ store changed objects formats in DB """ update = False - for prim_obj, tmp in self.xobjects: + for prim_obj, dummy in self.xobjects: obj_value = self.obj_values[prim_obj] if obj_value.object_fmt != obj_value.stored_fmt: - prefix = obj_value.object_prefix.lower() - constant = 'preferences.%sprefix' % prefix + constant = 'preferences.%sprefix' % PREFIXES[prim_obj] config.set(constant, obj_value.object_fmt) update = True @@ -542,7 +561,8 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): print('\nDone.') # finds integer portion in a GrampsID - _findint = re.compile('^[^\d]*(\d+)[^\d]*') + _findint = re.compile('^[^\d]*(\d+)[^\d]*$') + _prob_id = re.compile(' *[^\d]*(\d+){3,9}[^\d]*') def _reorder(self, prim_obj): """ reorders all selected objects with a (new) style, start & step """ @@ -553,13 +573,13 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): self.obj_methods[prim_obj] prefix_fmt = self.obj_values[prim_obj].get_fmt() - prefix = prefix_fmt.split('%', 1)[0] + prefix = self.obj_values[prim_obj].object_prefix + suffix = self.obj_values[prim_obj].object_suffix new_id = self.obj_values[prim_obj].get_id() keep_fmt = self.obj_values[prim_obj].get_keep() change = self.obj_values[prim_obj].get_change() - - formatmatch = _parseformat.match(prefix_fmt) - index_max = int("9" * int(formatmatch.groups()[0])) + index_max = int("9" * self.obj_values[prim_obj].width_fmt) + do_same = False for handle in iter_handles(): # Update progress @@ -572,31 +592,60 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): obj = get_from_handle(handle) act_id = obj.get_gramps_id() + match = self._prob_id.match(act_id) + # here we see if the ID looks like a typical Gramps ID. If not + # we ask user if he really wants to replace it. + # This should allow user to protect a GetGov ID or similar + if not match and not do_same: + xml = Glade(toplevel='dialog') + + top = xml.toplevel + # self.top.set_icon(ICON) + top.set_title("%s - Gramps" % _("Reorder Gramps IDs")) + apply_to_rest = xml.get_object('apply_to_rest') + + label1 = xml.get_object('toplabel') + label1.set_text('%s' % + _("Reorder Gramps IDs")) + label1.set_use_markup(True) + + label2 = xml.get_object('mainlabel') + label2.set_text(_("Do you want to replace %s?" % act_id)) + top.set_transient_for(self.progress._ProgressMeter__dialog) + self.progress._ProgressMeter__dialog.set_modal(False) + top.show() + response = top.run() + do_same = apply_to_rest.get_active() + top.destroy() + self.progress._ProgressMeter__dialog.set_modal(True) + if response != Gtk.ResponseType.YES: + continue + + elif not match and do_same and response != Gtk.ResponseType.YES: + continue + if change: # update the defined ID numbers into objects under consideration # of keeping ID if format not matches prefix # (implication logical boolean operator below) - if act_id.startswith(prefix) or not keep_fmt: + if act_id.startswith(prefix) and act_id.endswith(suffix) or \ + not keep_fmt: obj.set_gramps_id(new_id) commit(obj, self.trans) new_id = self.obj_values[prim_obj].succ_id() else: # attempt to extract integer - if we can't, treat it as a duplicate try: - match = _findint.match(act_id) + match = self._findint.match(act_id) if match: # get the integer, build the new handle. Make sure it # hasn't already been chosen. If it has, put this # in the duplicate handle list index = int(match.groups()[0]) - if formatmatch: - if index > index_max: - new_id = next_from_id() - else: - new_id = prefix_fmt % index + if index > index_max: + new_id = next_from_id() else: - # prefix_fmt does not contain a number after %, eg I%d new_id = prefix_fmt % index if new_id == act_id: @@ -607,7 +656,7 @@ class ReorderIds(tool.BatchTool, ManagedWindow, UpdateCallback): elif get_from_id(new_id) is not None: dup_ids.append(obj.get_handle()) else: - obj.set_id(new_id) + obj.set_gramps_id(new_id) commit(obj, self.trans) new_ids[new_id] = act_id else: