Annotation of MPIWGWeb/MPIWGHelper.py, revision 1.1.2.7
1.1.2.2 dwinter 1: from types import *
1.1.2.4 dwinter 2: import logging
1.1.2.1 dwinter 3: definedFields=['WEB_title','xdata_01','xdata_02','xdata_03','xdata_04','xdata_05','xdata_06','xdata_07','xdata_08','xdata_09','xdata_10','xdata_11','xdata_12','xdata_13','WEB_project_header','WEB_project_description','WEB_related_pub']
4:
5: checkFields = ['xdata_01']
6:
7: #ersetzt logging
8: def logger(txt,method,txt2):
9: """logging"""
10: logging.info(txt+ txt2)
11:
12: def getTextFromNode(nodename):
13:
14: nodelist=nodename.childNodes
15: rc = ""
16: for node in nodelist:
17: if node.nodeType == node.TEXT_NODE:
18: rc = rc + node.data
19: return rc
20:
1.1.2.7 ! dwinter 21: def getTemplate(self, tpName):
! 22: """get a template file either form the instance or from the product"""
! 23: ext=self.ZopeFind(self.aq_parent,obj_ids=[tpName])
! 24: if ext:
! 25: pt = getattr(self,ext[0][1].getId())
! 26: else:
! 27: pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/'+tpName)).__of__(self)
! 28: assert(pt)
! 29: return pt
1.1.2.1 dwinter 30:
31: def sortStopWordsF(self,xo,yo):
32: if not hasattr(self,'_v_stopWords'):
33: self._v_stopWords=self.stopwords_en.data.split("\n")
34:
1.1.2.5 dwinter 35: x=unicodify(xo[1])
36: y=unicodify(yo[1])
1.1.2.1 dwinter 37:
38: strx=x.split(" ")
39: stry=y.split(" ")
40:
41: for tmp in strx:
42: if tmp.lower() in self._v_stopWords:
43: del strx[strx.index(tmp)]
44:
45: for tmp in stry:
46: if tmp.lower() in self._v_stopWords:
47: del stry[stry.index(tmp)]
48:
49: return cmp(" ".join(strx)," ".join(stry))
50:
51: def sortStopWords(self):
52: return lambda x,y : sortStopWordsF(self,x,y)
53:
54: def sortF(x,y):
55: try:
56: return cmp(x[1],y[1])
57: except:
58: try:
59: return cmp(str(x[1]),str(y[1]))
60: except:
61:
62: return 0
63:
64: def sortI(x,y):
65: xsplit=x[1].split(".")
66: ysplit=y[1].split(".")
67: xret=""
68: yret=""
69: try:
70: for i in range(5):
71: try:
72: yret=yret+"%04i"%int(xsplit[i])
73: except:
74: yret=yret+"%04i"%0
75:
76: try:
77: xret=xret+"%04i"%int(ysplit[i])
78: except:
79: xret=xret+"%04i"%0
80:
81:
82: return cmp(int(yret),int(xret))
83: except:
84: return cmp(x[1],y[1])
85:
86:
87: def unicodify(str):
88: """decode str (utf-8 or latin-1 representation) into unicode object"""
1.1.2.6 casties 89: #logging.error("unicodify: %s"%str)
1.1.2.1 dwinter 90: if not str:
91: return ""
92: if type(str) is StringType:
93: try:
94: return str.decode('utf-8')
95: except:
96: return str.decode('latin-1')
97: else:
98: return str
99:
100: def utf8ify(str):
101: """encode unicode object or string into byte string in utf-8 representation"""
102: if not str:
103: return ""
104: if type(str) is StringType:
105: return str
106: else:
107: return str.encode('utf-8')
108:
1.1.2.6 casties 109:
110: def shortenString(s, l, ellipsis='...'):
111: """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis."""
112: l1 = int((l - len(ellipsis)) / 2)
113: return "%s%s%s"%(s[:l1],ellipsis,s[-l1:])
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>