comparison documentViewer.py @ 70:0049d64aa464

filepath introduced
author dwinter
date Tue, 04 Nov 2008 20:51:35 +0100
parents b8457fc33446
children 6412c45dff58
comparison
equal deleted inserted replaced
69:3b3c7cadd013 70:0049d64aa464
330 raise IOError("Unable to read infoXMLfrom %s"%(url)) 330 raise IOError("Unable to read infoXMLfrom %s"%(url))
331 331
332 return dom 332 return dom
333 333
334 334
335 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): 335 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0):
336 """gets authorization info from the index.meta file at path or given by dom""" 336 """gets authorization info from the index.meta file at path or given by dom"""
337 logger("documentViewer (getauthinfofromindexmeta)", logging.INFO,"path: %s"%(path)) 337 logger("documentViewer (getauthinfofromindexmeta)", logging.INFO,"path: %s"%(path))
338 338
339 access = None 339 access = None
340 340
341 if docinfo is None: 341 if docinfo is None:
342 docinfo = {} 342 docinfo = {}
343 343
344 if dom is None: 344 if dom is None:
345 dom = self.getIndexMeta(getParentDir(path)) 345 for x in range(cut+1):
346 path=getParentDir(path)
347 dom = self.getIndexMeta(path)
346 348
347 acctype = dom.xpath("//access-conditions/access/@type") 349 acctype = dom.xpath("//access-conditions/access/@type")
348 if acctype and (len(acctype)>0): 350 if acctype and (len(acctype)>0):
349 access=acctype[0].value 351 access=acctype[0].value
350 if access in ['group', 'institution']: 352 if access in ['group', 'institution']:
352 354
353 docinfo['accessType'] = access 355 docinfo['accessType'] = access
354 return docinfo 356 return docinfo
355 357
356 358
357 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): 359 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0):
358 """gets bibliographical info from the index.meta file at path or given by dom""" 360 """gets bibliographical info from the index.meta file at path or given by dom"""
359 logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path)) 361 logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path))
360 362
361 if docinfo is None: 363 if docinfo is None:
362 docinfo = {} 364 docinfo = {}
363 365
364 if dom is None: 366 if dom is None:
365 dom = self.getIndexMeta(getParentDir(path)) 367 for x in range(cut+1):
368 path=getParentDir(path)
369 dom = self.getIndexMeta(path)
366 370
367 # put in all raw bib fields as dict "bib" 371 # put in all raw bib fields as dict "bib"
368 bib = dom.xpath("//bib/*") 372 bib = dom.xpath("//bib/*")
369 if bib and len(bib)>0: 373 if bib and len(bib)>0:
370 bibinfo = {} 374 bibinfo = {}
506 docinfo['year']=getTextFromNode(dom.xpath("//date")[0]) 510 docinfo['year']=getTextFromNode(dom.xpath("//date")[0])
507 except: 511 except:
508 pass 512 pass
509 return docinfo 513 return docinfo
510 514
511 def getDocinfoFromImagePath(self,path,docinfo=None): 515 def getDocinfoFromImagePath(self,path,docinfo=None,cut=0):
512 """path ist the path to the images it assumes that the index.meta file is one level higher.""" 516 """path ist the path to the images it assumes that the index.meta file is one level higher."""
513 logger("documentViewer (getdocinfofromimagepath)", logging.INFO,"path: %s"%(path)) 517 logger("documentViewer (getdocinfofromimagepath)", logging.INFO,"path: %s"%(path))
514 if docinfo is None: 518 if docinfo is None:
515 docinfo = {} 519 docinfo = {}
516 path=path.replace("/mpiwg/online","") 520 path=path.replace("/mpiwg/online","")
517 docinfo['imagePath'] = path 521 docinfo['imagePath'] = path
518 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo) 522 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo)
519 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path 523 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path
520 docinfo['imageURL'] = imageUrl 524 docinfo['imageURL'] = imageUrl
521 525
522 docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) 526 docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo,cut=cut)
523 docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo) 527 docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo,cut=cut)
524 return docinfo 528 return docinfo
525 529
526 530
527 def getDocinfo(self, mode, url): 531 def getDocinfo(self, mode, url):
528 """returns docinfo depending on mode""" 532 """returns docinfo depending on mode"""
538 docinfo = {'mode': mode, 'url': url} 542 docinfo = {'mode': mode, 'url': url}
539 if mode=="texttool": #index.meta with texttool information 543 if mode=="texttool": #index.meta with texttool information
540 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) 544 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo)
541 elif mode=="imagepath": 545 elif mode=="imagepath":
542 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) 546 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo)
547 elif mode=="filepath":
548 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1)
543 else: 549 else:
544 logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!") 550 logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!")
545 raise ValueError("Unknown mode %s"%(mode)) 551 raise ValueError("Unknown mode %s"%(mode))
546 552
547 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo) 553 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo)