Mercurial > hg > documentViewer
changeset 35:2d9261aea8f3
version 0.2.4
* minor improvements
* tries more than one time to read info from digilib
author | casties |
---|---|
date | Wed, 12 Apr 2006 19:47:53 +0200 |
parents | 0ca99253b4ce |
children | 0bf5aac0ff41 |
files | documentViewer.py |
diffstat | 1 files changed, 78 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/documentViewer.py Tue Apr 11 19:27:57 2006 +0200 +++ b/documentViewer.py Wed Apr 12 19:47:53 2006 +0200 @@ -23,7 +23,6 @@ return int(number) except: return default - def getTextFromNode(nodename): if nodename is None: @@ -35,6 +34,12 @@ rc = rc + node.data return rc + +def getParentDir(path): + """returns pathname shortened by one""" + return '/'.join(path.split('/')[0:-1]) + + import socket def urlopen(url,timeout=2): @@ -111,17 +116,17 @@ def getLink(self,param=None,val=None): """link to documentviewer with parameter param set to val""" - params=cgi.parse_qs(self.REQUEST['QUERY_STRING']) + params=self.REQUEST.form.copy() if param is not None: if val is None: if params.has_key(param): del params[param] else: - params[param] = [str(val)] + params[param] = str(val) - ps = "&".join(["%s=%s"%(k,urllib.quote(v[0])) for (k, v) in params.items()]) - url=self.REQUEST['URL']+"?"+ps - #url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True) + # quote values and assemble into query string + ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) + url=self.REQUEST['URL1']+"?"+ps return url @@ -131,28 +136,31 @@ if idx == selected: return style + 'sel' else: - return style + return style - def accessOK(self, docinfo): + + def isAccessible(self, docinfo): """returns if access to the resource is granted""" access = docinfo.get('accessType', None) if access is None: - # no information - no access (not yet) + # no information - no access + #TODO: check return True elif access == 'free': return True + elif access in self.authgroups: + # only local access -- only logged in users + user = getSecurityManager().getUser() + if user is not None: + #print "user: ", user + return (user.getUserName() != "Anonymous User") + else: + return False - print "access: ", access, " authgroups: ", self.authgroups - if access in self.authgroups: - # local access OK - user = getSecurityManager().getUser().getUserName() - print "user: ", user - return (user != "Anonymous User") - - zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access group %s"%access) + zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access) return False + - def getDirinfoFromDigilib(self,path,docinfo=None): """gibt param von dlInfo aus""" if docinfo is None: @@ -162,10 +170,13 @@ zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl)) - try: - dom = NonvalidatingReader.parseUri(imageUrl) - except: - zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.ERROR, "error reading %s"%(imageUrl)) + for cnt in (1,2,3): + try: + dom = NonvalidatingReader.parseUri(imageUrl) + break + except: + zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(imageUrl,cnt)) + else: raise IOError("Unable to get dirinfo from %s"%(imageUrl)) params=dom.xpath("//dir/size") @@ -179,8 +190,33 @@ return docinfo + def getIndexMeta(self, url): + """returns dom of index.meta document at url""" + dom = None + if url.startswith("http://"): + # real URL + try: + dom = NonvalidatingReader.parseUri(url) + except: + zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) + raise IOError("Unable to get info from %s"%(url)) + else: + # online path + server=self.digilibBaseUrl+"/servlet/Texter?fn=" + metaUrl=server+url + if not metaUrl.endswith("index.meta"): + metaUrl += "/index.meta" + try: + dom = NonvalidatingReader.parseUri(metaUrl) + except: + zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) + raise IOError("Unable to get info from %s"%(url)) + + return dom + + def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): - """gets authorization info from the index.meta file at url or given by dom""" + """gets authorization info from the index.meta file at path or given by dom""" zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) access = None @@ -189,18 +225,12 @@ docinfo = {} if dom is None: - server=self.digilibBaseUrl+"/servlet/Texter?fn=" - path="/".join(path.split("/")[0:-1]) - metaUrl=server+path+"/index.meta" - try: - dom = NonvalidatingReader.parseUri(metaUrl) - except: - return docinfo + dom = self.getIndexMeta(getParentDir(path)) acctype = dom.xpath("//access-conditions/access/@type") if acctype and (len(acctype)>0): access=acctype[0].value - if access == 'group': + if access in ['group', 'institution']: access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() docinfo['accessType'] = access @@ -208,21 +238,15 @@ def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): - """gets bibliographical info from the index.meta file at url or given by dom""" + """gets bibliographical info from the index.meta file at path or given by dom""" zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) if docinfo is None: docinfo = {} if dom is None: - server=self.digilibBaseUrl+"/servlet/Texter?fn=" - path="/".join(path.split("/")[0:-1]) - metaUrl=server+path+"/index.meta" - try: - dom = NonvalidatingReader.parseUri(metaUrl) - except: - return docinfo - + dom = self.getIndexMeta(getParentDir(path)) + metaData=self.metadata.main.meta.bib bibtype=dom.xpath("//bib/@type") if bibtype and (len(bibtype)>0): @@ -231,7 +255,7 @@ bibtype="generic" bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) bibmap=metaData.generateMappingForType(bibtype) - print "bibmap: ", bibmap, " for: ", bibtype + #print "bibmap: ", bibmap, " for: ", bibtype # if there is no mapping bibmap is empty (mapping sometimes has empty fields) if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) @@ -248,11 +272,7 @@ docinfo = {} if dom is None: - try: - dom = NonvalidatingReader.parseUri(url) - except: - zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) - raise IOError("Unable to get texttool info from %s"%(url)) + dom = self.getIndexMeta(url) archiveNames=dom.xpath("//resource/name") if archiveNames and (len(archiveNames)>0): @@ -269,19 +289,19 @@ else: archivePath=None - images=dom.xpath("//texttool/image") - if images and (len(images)>0): - image=getTextFromNode(images[0]) + imageDirs=dom.xpath("//texttool/image") + if imageDirs and (len(imageDirs)>0): + imageDir=getTextFromNode(imageDirs[0]) else: - image=None + imageDir=None - if image and archivePath: - print "image: ", image, " archivepath: ", archivePath - image=os.path.join(archivePath,image) - image=image.replace("/mpiwg/online",'') - docinfo=self.getDirinfoFromDigilib(image,docinfo=docinfo) - docinfo['imagePath'] = image - docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+image + if imageDir and archivePath: + #print "image: ", imageDir, " archivepath: ", archivePath + imageDir=os.path.join(archivePath,imageDir) + imageDir=imageDir.replace("/mpiwg/online",'') + docinfo=self.getDirinfoFromDigilib(imageDir,docinfo=docinfo) + docinfo['imagePath'] = imageDir + docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+imageDir viewerUrls=dom.xpath("//texttool/digiliburlprefix") if viewerUrls and (len(viewerUrls)>0): @@ -365,7 +385,7 @@ if mode=="texttool": #index.meta with texttool information (viewerUrl,imagepath,textpath)=parseUrlTextTool(url) - print textpath + #print textpath try: dom = NonvalidatingReader.parseUri(textpath) except: