[Mpuls-commits] r1295 - in wasko/branches/2.0: . mpulsweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 5 19:31:12 CET 2010
Author: bh
Date: 2010-02-05 19:31:11 +0100 (Fri, 05 Feb 2010)
New Revision: 1295
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/mpulsweb/model/annotations.py
Log:
* mpulsweb/model/annotations.py:
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-02-05 18:21:34 UTC (rev 1294)
+++ wasko/branches/2.0/ChangeLog 2010-02-05 18:31:11 UTC (rev 1295)
@@ -1,5 +1,9 @@
2010-02-05 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/model/annotations.py:
+
+2010-02-05 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/config/routing.py: Fix formatting.
2010-02-05 Bernhard Herzog <bh at intevation.de>
Modified: wasko/branches/2.0/mpulsweb/model/annotations.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/annotations.py 2010-02-05 18:21:34 UTC (rev 1294)
+++ wasko/branches/2.0/mpulsweb/model/annotations.py 2010-02-05 18:31:11 UTC (rev 1295)
@@ -1,29 +1,30 @@
# -*- coding: utf-8 -*-
#
# (c) 2008 by Intevation GmbH
-# This is Free software under the GPLv3.
+# This is Free software under the GPLv3.
# See LICENSE comming with the source of 'mpuls offline'
# for details.
#
# author: Sascha L. Teichmann <sascha.teichmann at intevation.de>
#
+import os
+import re
from xml.dom.minidom import parse
-import re
-import os
+REQUIRED = ("required",)
+HELP = ("help",)
+EVALUATION = ("evaluation",)
-REQUIRED = ("required", )
-HELP = ("help", )
-EVALUATION = ("evaluation", )
+ANNOTATION_DIV_ID = re.compile("([a-zA-Z0-9_\-]+):([a-zA-Z0-9_\-]+)"
+ ":([a-zA-Z0-9_\-,]+)")
-ANNOTATION_DIV_ID = re.compile("([a-zA-Z0-9_\-]+):([a-zA-Z0-9_\-]+):([a-zA-Z0-9_\-,]+)")
class Annotation:
def __init__(self, kind, msg):
self.kind = kind
- self.msg = msg
+ self.msg = msg
def __str__(self):
return repr(self.kind) + ": " + repr(self.msg)
@@ -31,20 +32,23 @@
def __repr__(self):
return self.__str__()
+
def build_annotation(annotations_file):
-
annotations = {}
dom = None
try:
dom = parse(annotations_file)
for div in dom.getElementsByTagName("div"):
id = div.getAttribute("id")
- if not id: continue
+ if not id:
+ continue
m = ANNOTATION_DIV_ID.match(id)
- if not m: continue
+ if not m:
+ continue
id, kind = m.group(1), m.group(2)
items = [item for item in m.group(3).split(",") if item]
- if not items: continue
+ if not items:
+ continue
div.setAttribute("id", id)
msg = unicode(div.toxml())
@@ -53,7 +57,8 @@
annons = annotations.setdefault(item, [])
annons.append(Annotation(kind, msg))
finally:
- if dom: dom.unlink()
+ if dom:
+ dom.unlink()
return annotations
@@ -71,22 +76,23 @@
def getHelp(self, id):
return self.getAnnotations(id, HELP)
-
+
def hasEvaluation(self, id):
return self.hasAnnotations(id, EVALUATION)
def getEvaluation(self, id):
return self.getAnnotations(id, EVALUATION)
-
- def hasAnnotations(self, id, kinds = REQUIRED):
+
+ def hasAnnotations(self, id, kinds=REQUIRED):
annotations = self.annotations.get(id)
- if not annotations: return False
+ if not annotations:
+ return False
for annotation in annotations:
if annotation.kind in kinds:
return True
return False
- def getAnnotations(self, id, kinds = REQUIRED):
+ def getAnnotations(self, id, kinds=REQUIRED):
try:
x = [a.msg for a in self.annotations[id] if a.kind in kinds]
except KeyError:
More information about the Mpuls-commits
mailing list