Mercurial > hg > documentViewer
comparison documentViewer.py @ 461:8732f15df5f3 elementtree
more renovation
author | casties |
---|---|
date | Tue, 26 Jul 2011 20:09:26 +0200 |
parents | 76bc2317146f |
children | 0d378e8ebcc3 |
comparison
equal
deleted
inserted
replaced
460:76bc2317146f | 461:8732f15df5f3 |
---|---|
100 | 100 |
101 def getParentDir(path): | 101 def getParentDir(path): |
102 """returns pathname shortened by one""" | 102 """returns pathname shortened by one""" |
103 return '/'.join(path.split('/')[0:-1]) | 103 return '/'.join(path.split('/')[0:-1]) |
104 | 104 |
105 def normalizeBibtype(bt): | 105 def normalizeBibField(bt, underscore=True): |
106 """returns normalised bib type for looking up mappings""" | 106 """returns normalised bib type for looking up mappings""" |
107 bt = bt.strip().replace(' ', '-').lower() | 107 bt = bt.strip().replace(' ', '-').lower() |
108 if underscore: | |
109 bt = bt.replace('_', '-') | |
110 | |
108 return bt | 111 return bt |
109 | 112 |
110 def getBibdataFromDom(dom): | 113 def getBibdataFromDom(dom): |
111 """returns dict with all elements from bib-tag""" | 114 """returns dict with all elements from bib-tag""" |
112 bibinfo = {} | 115 bibinfo = {} |
113 bib = dom.find(".//meta/bib") | 116 bib = dom.find(".//meta/bib") |
114 if bib is not None: | 117 if bib is not None: |
115 # put type in @type | 118 # put type in @type |
116 type = bib.get('type') | 119 type = bib.get('type') |
117 bibinfo['@type'] = normalizeBibtype(type) | 120 bibinfo['@type'] = normalizeBibField(type) |
118 # put all subelements in dict | 121 # put all subelements in dict |
119 for e in bib: | 122 for e in bib: |
120 bibinfo[e.tag] = getText(e) | 123 bibinfo[normalizeBibField(e.tag)] = getText(e) |
121 | 124 |
122 return bibinfo | 125 return bibinfo |
126 | |
123 | 127 |
124 ## | 128 ## |
125 ## documentViewer class | 129 ## documentViewer class |
126 ## | 130 ## |
127 class documentViewer(Folder): | 131 class documentViewer(Folder): |