Mercurial > hg > MetaDataProvider
changeset 20:9a1e75e708e1
small bugs
in metadata context field in metadata docinfo added
osa_system2 nicht mehr noetig
author | dwinter |
---|---|
date | Sun, 23 Oct 2011 21:29:02 +0200 |
parents | bd3025a6a6c0 |
children | db5af17f4933 d036de7fd78d |
files | MetaData.py MetaDataFolder.py MetaDataMapping.py OSAS_helpers.py OSAS_metadata.py |
diffstat | 5 files changed, 220 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/MetaData.py Thu Aug 04 16:55:22 2011 +0200 +++ b/MetaData.py Sun Oct 23 21:29:02 2011 +0200 @@ -96,7 +96,7 @@ """returns the subtree (list) of the dom rooted in this element""" if dom is None: # get from server - md = self.getDomFromPathOrUrl(path) + dom = self.getDomFromPathOrUrl(path) # ElementTree doesn't like absolute paths # lets assume dom is rooted in the first element @@ -253,13 +253,15 @@ if allFields and len(mappedData) < len(data): # add fields that were not in fields for bk in data.keys(): - if bk in mappedData or not data[bk]: + if bk in mappedData or not data[bk] or bk[0]=='@': continue + mappedData[bk] = {'tag':bk, 'label':bk, 'value':data[bk]} mappedList.append(bk) mappedData['@fieldList'] = mappedList + mappedData['@type'] = data.get('@type',None) return mappedData def getDCMappedData(self, data, allFields=False):
--- a/MetaDataFolder.py Thu Aug 04 16:55:22 2011 +0200 +++ b/MetaDataFolder.py Sun Oct 23 21:29:02 2011 +0200 @@ -125,6 +125,7 @@ def getXmlPathObj(self, xmlpath): """returns object at xmlpath""" # make xmlpath relative for Zope + logging.debug("XMlPAth:"+xmlpath) if xmlpath[0] == '/': xmlpath = xmlpath[1:] @@ -198,6 +199,13 @@ # information is two tags deep - recursive=1 return self.getXmlPathFormatted('resource/meta/access-conditions/copyright', template, path=path, dom=dom, data=data, recursive=recursive, all=all) + def getContextData(self, path=None, dom=None, all=True): + """returns contents of context tag as dict""" + # information is two tags deep - recursive=1 + + return self.getXmlPathData('resource/meta/context', path=path, dom=dom, all=all) + + def getBibData(self, path=None, dom=None): """returns contents of bib tag as dict""" return self.resource.meta.bib.getData(path=path, dom=dom)
--- a/MetaDataMapping.py Thu Aug 04 16:55:22 2011 +0200 +++ b/MetaDataMapping.py Sun Oct 23 21:29:02 2011 +0200 @@ -59,7 +59,10 @@ def getFieldList(self): """returns ordered list of fields""" - return self.fieldList + if self.fieldList is None: + # create fieldList + self.fieldList = fields.keys() + return self.fieldList # convenience method def getAt(self, array, idx, default=None):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OSAS_helpers.py Sun Oct 23 21:29:02 2011 +0200 @@ -0,0 +1,203 @@ +# hilfsfunktionen +import os.path +from types import * +import xml.dom.minidom +import logging + +#ersetzt logging +def logger(txt,method,txt2): + """logging""" + logging.info(txt+ txt2) + + + +OSASObjectTypes=['OSAS_metaDataFile','OSAS_dir','Osas_file','OSAS_imageFolder','OSAS_dir_archive','OSAS_file_archive','OSAS_videoFolder','OSAS_videoFile','OSAS_videoFolder'] +OSASDirObjects=['OSAS_dir','OSAS_imageFolder',] +OSASExcludedFiles=['TheVolumeSettingsFolder','TheFindByContentFolder'] + + +def getText(nodelist): + """gibt text aus nodelist""" + rc = "" + for node in nodelist: + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return rc + +def getMetaInfoFromXML(path,xmlInfo): + """get index.meta and translate it to HTML""" + html=[] + + dom = xml.dom.minidom.parseString(xmlInfo) + try: + name=getText(dom.getElementsByTagName("name")[0].childNodes) + except: + name="NOT_DEFINED!!!" + try: + creator=getText(dom.getElementsByTagName("creator")[0].childNodes) + except: + creator="NOT_DEFINED!!!" + + try: + creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes) + except: + creation_date="NOT_DEFINED!!!" + + try: + description=getText(dom.getElementsByTagName("description")[0].childNodes) + except: + description="NOT_DEFINED!!!" + + try: + type=getText(dom.getElementsByTagName("content-type")[0].childNodes) + except: + type="" + if type=="scanned document": + html="<h3>Document: "+name+"</h3>" + elif type=="folder": + html="<h3>Folder: "+name+"</h3>" + else: + html="<h3>Document: "+name+"</h3>" + + html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>" + html=html+"<h4>Description</h4><p>"+description+"</p>" + try: + bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0] + if bib.attributes.has_key('type'): + html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>" + else: + html=html+"<h4>Info</h4>" + html=html+getBib(bib.childNodes) + + except: + """none""" + +# html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace') + + + return html + + +def getBib(nodelist): + """ translate bibliographical entries """ + rc= "<table border='0'>" + + for node in nodelist: + + if node.nodeType == node.ELEMENT_NODE: + """nothing""" + + rc = rc+"<tr><td valign='right'>"+str(node.nodeName)+":</td><td> "+getText(node.childNodes)+"</td></tr>" + + #print rc + return rc+"</table>" + +def getPropertyOfDirs(indexMeta,propertyName): + """gibt Eigenschaften der directorys gemaess Index.metas file in path aus + @param indexMeta: index.meta file + @param propertyName: Property die ausgegebenwerden soll + @return: Hash mit key name des Directories and Value von property, None if error. + """ + ret={} + + try: + dom=xml.dom.minidom.parseString(indexMeta) + + rootProp=xml.xpath.Evaluate("/resource/%s"%propertyName,dom) + if len(rootProp)==1: + property= getText(rootProp[0].childNodes) + ret["."]=property + + for node in dom.getElementsByTagName("dir"): + try: + property= getText(node.getElementsByTagName(propertyName)[0].childNodes) + dirName=getText(node.getElementsByTagName("name")[0].childNodes) + ret[dirName]=property + except: + ret[dirName]=none + return ret + except: + + return ret + + +def dirHasProperty(path,indexMeta,propertyName,propertyValue): + """gibt 1 zurueck falls path hat propertyName und properName=propertyValue + @param propertyName:Property von path in index.meta des parent folders von path + @param propertyValue:Wert der Property + @param path: Pfad der getestet werden soll + """ + if getPropertyOfDirs(indexMeta,propertyName).get(os.path.split(path)[1],None)==propertyValue: + return 1 + else: + return 0 + +def isImageFolder(path,indexMeta): + """check if folder contains images without metadata or with metadata""" + # metadaten ergeben imagefolder + if dirHasProperty(path,indexMeta,'content-type','images'): + return 1 + +def isVideoFolder(path,indexMeta): + """check if folder contains images without metadata or with metadata""" + # metadaten ergeben imagefolder + + if dirHasProperty(path,indexMeta,'media-type','video'): + return 1 + +def isVideoStream(path,indexMeta): + if dirHasProperty(path,indexMeta,'container-format','quicktime'): + return 1 + +def isImageFolderGuess(path): + """check if folder contains images without metadata or with metadata""" + #sonst rate ob folder images enthaelten durch test nach suffix + try: + dir=os.listdir(path) + + imagesuffixes=['.gif','.jpg','.jpeg','.png','.tiff','.tif'] + ret="" + for a in dir: + + suffix=os.path.splitext(a)[1].lower() + + if suffix in imagesuffixes: + return 1 + + return 0 + + except: + return 0 + +def checkOSASFileType(object): + """checke filetype + nicht erkannte type auf werden auf none gesetzt + """ + if os.path.split(object)[1][0]=="." or os.path.split(object)[1] in OSASExcludedFiles: + return None + elif isImageFolderGuess(object): + return 'OSAS_imageFolder' + elif os.path.split(object)[1]=="index.meta": + return 'OSAS_metaDataFile' + elif os.path.isdir(object): + return 'OSAS_dir' + elif os.path.isfile(object): + return 'OSAS_file' + +def toList(fields): + """Einzelfeld in Liste umwandeln + @param fields: String oder Array + @return: gibt liste zurueck + + """ + if type(fields)==StringType: + return [fields] + else: + return fields + + +def localDate(): + """gives formatted local date""" + return strftime("%d.%m.%Y",localtime()) + +