[Formed-commits] r408 - in trunk: . formed/formed/model formed/formed/plugins/export formed/formed/plugins/modify
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 5 18:30:38 CEST 2010
Author: torsten
Date: 2010-10-05 18:30:38 +0200 (Tue, 05 Oct 2010)
New Revision: 408
Modified:
trunk/ChangeLog
trunk/formed/formed/model/data.py
trunk/formed/formed/plugins/export/rules_sh.py
trunk/formed/formed/plugins/modify/rules.py
Log:
Added generating XML for tagging config.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-04 17:16:07 UTC (rev 407)
+++ trunk/ChangeLog 2010-10-05 16:30:38 UTC (rev 408)
@@ -1,3 +1,11 @@
+2010-10-05 Torsten Irländer <torsten.irlaender at intevation.de>
+
+ * formed/formed/model/data.py: Fixed error when setting tag attribute.
+ * formed/formed/plugins/export/rules_sh.py: Added generating exporting
+ tagging-xml
+ * formed/formed/plugins/modify/rules.py: Do not generate automatic
+ tagids for rules.
+
2010-10-04 Torsten Irländer <torsten.irlaender at intevation.de>
* formed/formed/model/data.py (RuleLeaf.__init__): Added new attribute
Modified: trunk/formed/formed/model/data.py
===================================================================
--- trunk/formed/formed/model/data.py 2010-10-04 17:16:07 UTC (rev 407)
+++ trunk/formed/formed/model/data.py 2010-10-05 16:30:38 UTC (rev 408)
@@ -325,7 +325,7 @@
self.setAttribute("mark", mark)
def setTag(self, expr):
- self.setAttribute('tag', expr)
+ self.setAttribute('tag', str(expr))
def getTag(self):
return self.getAttribute("tag")
Modified: trunk/formed/formed/plugins/export/rules_sh.py
===================================================================
--- trunk/formed/formed/plugins/export/rules_sh.py 2010-10-04 17:16:07 UTC (rev 407)
+++ trunk/formed/formed/plugins/export/rules_sh.py 2010-10-05 16:30:38 UTC (rev 408)
@@ -25,6 +25,11 @@
out.append("now()")
return " ".join(out)
+def sql_date(node, document):
+ out = []
+ out.append('%s::date' % node.eval())
+ return " ".join(out)
+
def sql_var(node, document):
out = []
out.append(node.var_name)
@@ -55,6 +60,9 @@
if node.operator.__name__ == "GT":
operator = ">"
out.append("%s %s %s" % (recursive_parse(node.a, document), operator, recursive_parse(node.b, document)))
+ elif node.operator.__name__ == "LT":
+ operator = "<"
+ out.append("%s %s %s" % (recursive_parse(node.a, document), operator, recursive_parse(node.b, document)))
elif node.operator.__name__ == "EQ":
operator = "="
out.append("%s %s %s" % (recursive_parse(node.a, document), operator, recursive_parse(node.b, document)))
@@ -111,6 +119,8 @@
out.append(sql_const(node, document))
elif isinstance(node, Today):
out.append(sql_today(node, document))
+ elif isinstance(node, DateNode):
+ out.append(sql_today(node, document))
else:
raise Exception('Can not parse %s' % node)
return " ".join(out)
@@ -140,6 +150,111 @@
out.append("done")
return "\n".join(out)
+def generate_check(tag, name, desc, add_sql, del_sql):
+ out = []
+ base_sql = "SELECT id from ( %%(table)s ) m WHERE ( %(where)s )"
+ out.append('<check tagid="%s">' % tag)
+ out.append('<name>')
+ out.append(name)
+ out.append('</name>')
+ out.append('<desc>')
+ out.append(desc)
+ out.append('</desc>')
+ out.append('<addtag>')
+ out.append('<sql>')
+ out.append(escape(add_sql))
+ out.append('</sql>')
+ out.append('</addtag>')
+ out.append('<deltag>')
+ out.append('<sql>')
+ out.append(escape(del_sql))
+ out.append('</sql>')
+ out.append('</deltag>')
+ out.append('</check>')
+ return "".join(out)
+
+def generate_tagging(rules, document):
+ out = []
+ date_rules = []
+ inserts = []
+ base_sql = "SELECT id from ( %%(table)s ) m WHERE ( %(where)s )"
+ # 1. Checks
+ out.append('<checks>')
+ for num, rule in enumerate(rules):
+ try:
+ tag = int(rule.getTag())
+ except ValueError:
+ tag = 1000+num
+ name = rule.getDescription().replace("'", '"')
+ desc = rule.getValue().replace("'", '"')
+ add_sql = base_sql % {
+ 'where': recursive_parse(rule.getExpr().prog, document)}
+ del_sql = base_sql % {
+ 'where': "TRUE"}
+ if tag >= 1000:
+ date_rules.append(tag)
+ out.append(generate_check(tag, name, desc, add_sql, del_sql))
+ #inserts.append("""INSERT INTO tags (id, label, description) VALUES (%s, '%s','%s');""" % (tag, name.replace("'", '"'), desc.replace("'", '"')))
+ # Added check for test if all date-sequence rules are ok
+ tag = "10"
+ name = "Datumsangaben konsistent"
+ desc = "Alle Datumsangaben in der Fallakte befinden sich in chronologisch korrekter Reihenfolge und liegen nicht in der Zukunft"
+ add_sql = "select id from master_tbl_view m where not ARRAY(SELECT tag_id FROM nm_tags_cases_view WHERE case_id = m.id) && ARRAY[%s]" % ",".join([str(id) for id in date_rules])
+ del_sql = base_sql % {'where': "TRUE"}
+ out.append(generate_check(tag, name, desc, add_sql, del_sql))
+ #inserts.append("""INSERT INTO tags (id, label, description) VALUES (%s, '%s','%s');""" % (tag, name.replace("'", '"'), desc.replace("'", '"')))
+ out.append('</checks>')
+ out.append('<!--\n')
+ #out.append("\n".join(inserts))
+ out.append('\n-->')
+ return "".join(out)
+
+class ExportRulesForTagging(FileDialogFilter):
+
+ def __init__(self):
+ FileDialogFilter.__init__(self)
+
+ def getMenuName(self):
+ return _("Export R&ules for Tagging XML...")
+
+ def getDescription(self):
+ return _("Exports rules as a XML")
+
+ def wildcards(self):
+ return _("XML files (*.xml)|*.xml")
+
+ def dialogMessage(self):
+ return _("Export rules as Tagging config")
+
+ def errorTitle(self):
+ return _("Error occured while exporting rules to XML")
+
+ def doExport(self, path, main, dummy):
+ document = main.getDocument()
+ root = document.root
+ mode = main.getSelectedMode()
+ allModes = main.getAllModes()
+ out = None
+ sql = None
+ try:
+ out = codecs.open(path, "wb", "UTF-8")
+ all_rules = list(document.findAllByClass(data.RuleLeaf, mode, allModes))
+ error_rules = []
+ known_rules = []
+ for idx, rule in enumerate(all_rules):
+ if rule.getMark().find('error') < 0: continue
+ # filter out already generated rules.
+ rule_str = recursive_parse(rule.getExpr().prog, document)
+ if rule_str in known_rules: continue
+ error_rules.append(rule)
+ known_rules.append(rule_str)
+ sql = generate_tagging(error_rules, document)
+ print >> out, sql
+ finally:
+ if out:
+ try: out.close()
+ except: pass
+
class ExportRulesAsSH(FileDialogFilter):
def __init__(self):
Modified: trunk/formed/formed/plugins/modify/rules.py
===================================================================
--- trunk/formed/formed/plugins/modify/rules.py 2010-10-04 17:16:07 UTC (rev 407)
+++ trunk/formed/formed/plugins/modify/rules.py 2010-10-05 16:30:38 UTC (rev 408)
@@ -284,8 +284,6 @@
d1, d2 = dates[pair[0]], dates[pair[1]]
rule1.setMark("error:%s" % d1.getName())
rule2.setMark("error:%s" % d2.getName())
- rule1.setTag(idx+1000)
- rule2.setTag(idx+1000)
desc1, desc2 = [u" / ".join(x) for x in remove_common_head(
descriptions(d1), descriptions(d2))]
More information about the Formed-commits
mailing list