[Formed-commits] r332 - in trunk: . formed/formed/plugins/names
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue May 26 16:12:26 CEST 2009
Author: teichmann
Date: 2009-05-26 16:12:25 +0200 (Tue, 26 May 2009)
New Revision: 332
Modified:
trunk/ChangeLog
trunk/formed/formed/plugins/names/filter.py
Log:
Repaired unique filter for nodecomponent names.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-05-06 13:25:09 UTC (rev 331)
+++ trunk/ChangeLog 2009-05-26 14:12:25 UTC (rev 332)
@@ -1,3 +1,8 @@
+2009-05-26 Sascha L. Teichmann <teichmann at intevation.de>
+
+ * formed/formed/plugins/names/filter.py: Repaired unique filter for
+ nodecomponent names.
+
2009-05-06 Sascha L. Teichmann <teichmann at intevation.de>
* formed/formed/plugins/export/rg_sql.py: Only create depending
Modified: trunk/formed/formed/plugins/names/filter.py
===================================================================
--- trunk/formed/formed/plugins/names/filter.py 2009-05-06 13:25:09 UTC (rev 331)
+++ trunk/formed/formed/plugins/names/filter.py 2009-05-26 14:12:25 UTC (rev 332)
@@ -17,27 +17,45 @@
import re
+TYPE = re.compile(r"([^-]+)-(\d+)")
+
class MakeNamesUniqueFilter(Filter):
def filterDocument(self, main):
document = main.getDocument()
root = document.root
if not root: return
- ids = set()
- pattern = re.compile(r"([a-zA-Z]+)([^0-9]?)([0-9]+)")
- for nc in root.walk():
- name = nc.getName()
- if not name: continue
- if name in ids:
- m = pattern.match(name)
- if m: pre, num = m.group(1) + m.group(2), int(m.group(3))
- else: pre, num = name + "-", -1
- while True:
- num += 1
- name = "%s%d" % (pre, num)
- if name not in ids: break
- nc.setName(name)
- ids.add(name)
+
+ all = {}
+
+ for x in root.walk():
+ all.setdefault(x.getName(), []).append(x)
+
+ for x in all.values():
+ if len(x) < 2: continue
+
+ for y in x[1:]:
+ old_name = y.getName()
+ if not old_name: continue
+
+ m = TYPE.match(old_name)
+ if m:
+ t, c = m.group(1), int(m.group(2))
+ i = 0
+ while True:
+ if i == c: i += 1; continue
+ n = "%s-%d" % (t, i)
+ if not all.has_key(n): break
+ i += 1
+ else:
+ i = 0
+ while True:
+ n = "%s-%d" % (old_name, i)
+ if not all.has_key(n): break
+ i += 1
+ y.setName(n)
+ all[n] = [y]
+
# update generators for new automatic names
main.updateIds()
More information about the Formed-commits
mailing list