Mercurial > hg > documentViewer
comparison documentViewer.py @ 4:e9085ba2bb51 modularisierung
- first fix for timeout issues
- cleaned logging calls
author | casties |
---|---|
date | Wed, 16 Jun 2010 18:38:17 +0200 |
parents | 8cc283757c39 |
children | 3c70a7d2f35b |
comparison
equal
deleted
inserted
replaced
3:3ba8479c7aba | 4:e9085ba2bb51 |
---|---|
264 del params[param] | 264 del params[param] |
265 else: | 265 else: |
266 params[param] = str(val) | 266 params[param] = str(val) |
267 | 267 |
268 # quote values and assemble into query string | 268 # quote values and assemble into query string |
269 logging.info("XYXXXXX: %s"%repr(params.items())) | 269 logging.debug("XYXXXXX: %s"%repr(params.items())) |
270 ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) | 270 ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) |
271 url=self.REQUEST['URL1']+"?"+ps | 271 url=self.REQUEST['URL1']+"?"+ps |
272 return url | 272 return url |
273 | 273 |
274 def getInfo_xml(self,url,mode): | 274 def getInfo_xml(self,url,mode): |
283 | 283 |
284 | 284 |
285 def isAccessible(self, docinfo): | 285 def isAccessible(self, docinfo): |
286 """returns if access to the resource is granted""" | 286 """returns if access to the resource is granted""" |
287 access = docinfo.get('accessType', None) | 287 access = docinfo.get('accessType', None) |
288 logger("documentViewer (accessOK)", logging.INFO, "access type %s"%access) | 288 logging.debug("documentViewer (accessOK) access type %s"%access) |
289 if access is not None and access == 'free': | 289 if access is not None and access == 'free': |
290 logger("documentViewer (accessOK)", logging.INFO, "access is free") | 290 logging.debug("documentViewer (accessOK) access is free") |
291 return True | 291 return True |
292 elif access is None or access in self.authgroups: | 292 elif access is None or access in self.authgroups: |
293 # only local access -- only logged in users | 293 # only local access -- only logged in users |
294 user = getSecurityManager().getUser() | 294 user = getSecurityManager().getUser() |
295 if user is not None: | 295 if user is not None: |
296 #print "user: ", user | 296 #print "user: ", user |
297 return (user.getUserName() != "Anonymous User") | 297 return (user.getUserName() != "Anonymous User") |
298 else: | 298 else: |
299 return False | 299 return False |
300 | 300 |
301 logger("documentViewer (accessOK)", logging.INFO, "unknown access type %s"%access) | 301 logging.debug("documentViewer (accessOK) unknown access type %s"%access) |
302 return False | 302 return False |
303 | 303 |
304 | 304 |
305 def getDirinfoFromDigilib(self,path,docinfo=None,cut=0): | 305 def getDirinfoFromDigilib(self,path,docinfo=None,cut=0): |
306 """gibt param von dlInfo aus""" | 306 """gibt param von dlInfo aus""" |
312 | 312 |
313 path=getParentDir(path) | 313 path=getParentDir(path) |
314 | 314 |
315 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path | 315 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path |
316 | 316 |
317 logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo from %s"%(infoUrl)) | 317 logging.debug("documentViewer (getparamfromdigilib) dirInfo from %s"%(infoUrl)) |
318 | 318 |
319 for cnt in range(num_retries): | 319 for cnt in range(num_retries): |
320 try: | 320 try: |
321 # dom = NonvalidatingReader.parseUri(imageUrl) | 321 # dom = NonvalidatingReader.parseUri(imageUrl) |
322 txt=urllib.urlopen(infoUrl).read() | 322 txt=urllib.urlopen(infoUrl).read() |
323 dom = Parse(txt) | 323 dom = Parse(txt) |
324 break | 324 break |
325 except: | 325 except: |
326 logger("documentViewer (getdirinfofromdigilib)", logging.ERROR, "error reading %s (try %d)"%(infoUrl,cnt)) | 326 logging.error("documentViewer (getdirinfofromdigilib) error reading %s (try %d)"%(infoUrl,cnt)) |
327 else: | 327 else: |
328 raise IOError("Unable to get dir-info from %s"%(infoUrl)) | 328 raise IOError("Unable to get dir-info from %s"%(infoUrl)) |
329 | 329 |
330 sizes=dom.xpath("//dir/size") | 330 sizes=dom.xpath("//dir/size") |
331 logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo:size"%sizes) | 331 logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes) |
332 | 332 |
333 if sizes: | 333 if sizes: |
334 docinfo['numPages'] = int(getTextFromNode(sizes[0])) | 334 docinfo['numPages'] = int(getTextFromNode(sizes[0])) |
335 else: | 335 else: |
336 docinfo['numPages'] = 0 | 336 docinfo['numPages'] = 0 |
361 # dom = NonvalidatingReader.parseUri(metaUrl) | 361 # dom = NonvalidatingReader.parseUri(metaUrl) |
362 txt=urllib.urlopen(metaUrl).read() | 362 txt=urllib.urlopen(metaUrl).read() |
363 dom = Parse(txt) | 363 dom = Parse(txt) |
364 break | 364 break |
365 except: | 365 except: |
366 logger("ERROR documentViewer (getIndexMeta)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2]) | 366 logging.error("ERROR documentViewer (getIndexMeta) %s (%s)"%sys.exc_info()[0:2]) |
367 | 367 |
368 if dom is None: | 368 if dom is None: |
369 raise IOError("Unable to read index meta from %s"%(url)) | 369 raise IOError("Unable to read index meta from %s"%(url)) |
370 | 370 |
371 return dom | 371 return dom |
389 # dom = NonvalidatingReader.parseUri(metaUrl) | 389 # dom = NonvalidatingReader.parseUri(metaUrl) |
390 txt=urllib.urlopen(metaUrl).read() | 390 txt=urllib.urlopen(metaUrl).read() |
391 dom = Parse(txt) | 391 dom = Parse(txt) |
392 break | 392 break |
393 except: | 393 except: |
394 logger("ERROR documentViewer (getPresentationInfoXML)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2]) | 394 logging.error("ERROR documentViewer (getPresentationInfoXML) %s (%s)"%sys.exc_info()[0:2]) |
395 | 395 |
396 if dom is None: | 396 if dom is None: |
397 raise IOError("Unable to read infoXMLfrom %s"%(url)) | 397 raise IOError("Unable to read infoXMLfrom %s"%(url)) |
398 | 398 |
399 return dom | 399 return dom |
400 | 400 |
401 | 401 |
402 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): | 402 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
403 """gets authorization info from the index.meta file at path or given by dom""" | 403 """gets authorization info from the index.meta file at path or given by dom""" |
404 logger("documentViewer (getauthinfofromindexmeta)", logging.INFO,"path: %s"%(path)) | 404 logging.debug("documentViewer (getauthinfofromindexmeta) path: %s"%(path)) |
405 | 405 |
406 access = None | 406 access = None |
407 | 407 |
408 if docinfo is None: | 408 if docinfo is None: |
409 docinfo = {} | 409 docinfo = {} |
475 return docinfo | 475 return docinfo |
476 | 476 |
477 | 477 |
478 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): | 478 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): |
479 """parse texttool tag in index meta""" | 479 """parse texttool tag in index meta""" |
480 logger("documentViewer (getdocinfofromtexttool)", logging.INFO, "url: %s" % (url)) | 480 logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) |
481 if docinfo is None: | 481 if docinfo is None: |
482 docinfo = {} | 482 docinfo = {} |
483 if docinfo.get('lang', None) is None: | 483 if docinfo.get('lang', None) is None: |
484 docinfo['lang'] = '' # default keine Sprache gesetzt | 484 docinfo['lang'] = '' # default keine Sprache gesetzt |
485 if dom is None: | 485 if dom is None: |
490 | 490 |
491 archiveNames = dom.xpath("//resource/name") | 491 archiveNames = dom.xpath("//resource/name") |
492 if archiveNames and (len(archiveNames) > 0): | 492 if archiveNames and (len(archiveNames) > 0): |
493 archiveName = getTextFromNode(archiveNames[0]) | 493 archiveName = getTextFromNode(archiveNames[0]) |
494 else: | 494 else: |
495 logger("documentViewer (getdocinfofromtexttool)", logging.WARNING, "resource/name missing in: %s" % (url)) | 495 logging.warning("documentViewer (getdocinfofromtexttool) resource/name missing in: %s" % (url)) |
496 | 496 |
497 archivePaths = dom.xpath("//resource/archive-path") | 497 archivePaths = dom.xpath("//resource/archive-path") |
498 if archivePaths and (len(archivePaths) > 0): | 498 if archivePaths and (len(archivePaths) > 0): |
499 archivePath = getTextFromNode(archivePaths[0]) | 499 archivePath = getTextFromNode(archivePaths[0]) |
500 # clean up archive path | 500 # clean up archive path |
502 archivePath = '/' + archivePath | 502 archivePath = '/' + archivePath |
503 if archiveName and (not archivePath.endswith(archiveName)): | 503 if archiveName and (not archivePath.endswith(archiveName)): |
504 archivePath += "/" + archiveName | 504 archivePath += "/" + archiveName |
505 else: | 505 else: |
506 # try to get archive-path from url | 506 # try to get archive-path from url |
507 logger("documentViewer (getdocinfofromtexttool)", logging.WARNING, "resource/archive-path missing in: %s" % (url)) | 507 logging.warning("documentViewer (getdocinfofromtexttool) resource/archive-path missing in: %s" % (url)) |
508 if (not url.startswith('http')): | 508 if (not url.startswith('http')): |
509 archivePath = url.replace('index.meta', '') | 509 archivePath = url.replace('index.meta', '') |
510 | 510 |
511 if archivePath is None: | 511 if archivePath is None: |
512 # we balk without archive-path | 512 # we balk without archive-path |
594 pass | 594 pass |
595 return docinfo | 595 return docinfo |
596 | 596 |
597 def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): | 597 def getDocinfoFromImagePath(self,path,docinfo=None,cut=0): |
598 """path ist the path to the images it assumes that the index.meta file is one level higher.""" | 598 """path ist the path to the images it assumes that the index.meta file is one level higher.""" |
599 logger("documentViewer (getdocinfofromimagepath)", logging.INFO,"path: %s"%(path)) | 599 logging.debug("documentViewer (getdocinfofromimagepath) path: %s"%(path)) |
600 if docinfo is None: | 600 if docinfo is None: |
601 docinfo = {} | 601 docinfo = {} |
602 path=path.replace("/mpiwg/online","") | 602 path=path.replace("/mpiwg/online","") |
603 docinfo['imagePath'] = path | 603 docinfo['imagePath'] = path |
604 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo,cut=cut) | 604 docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo,cut=cut) |
605 | 605 |
606 pathorig=path | 606 pathorig=path |
607 for x in range(cut): | 607 for x in range(cut): |
608 path=getParentDir(path) | 608 path=getParentDir(path) |
609 logging.error("PATH:"+path) | 609 logging.debug("documentViewer (getdocinfofromimagepath) PATH:"+path) |
610 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path | 610 imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path |
611 docinfo['imageURL'] = imageUrl | 611 docinfo['imageURL'] = imageUrl |
612 | 612 |
613 #path ist the path to the images it assumes that the index.meta file is one level higher. | 613 #path ist the path to the images it assumes that the index.meta file is one level higher. |
614 docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) | 614 docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) |
616 return docinfo | 616 return docinfo |
617 | 617 |
618 | 618 |
619 def getDocinfo(self, mode, url): | 619 def getDocinfo(self, mode, url): |
620 """returns docinfo depending on mode""" | 620 """returns docinfo depending on mode""" |
621 logger("documentViewer (getdocinfo)", logging.INFO,"mode: %s, url: %s"%(mode,url)) | 621 logging.debug("documentViewer (getdocinfo) mode: %s, url: %s"%(mode,url)) |
622 # look for cached docinfo in session | 622 # look for cached docinfo in session |
623 if self.REQUEST.SESSION.has_key('docinfo'): | 623 if self.REQUEST.SESSION.has_key('docinfo'): |
624 docinfo = self.REQUEST.SESSION['docinfo'] | 624 docinfo = self.REQUEST.SESSION['docinfo'] |
625 # check if its still current | 625 # check if its still current |
626 if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: | 626 if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: |
627 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo in session: %s"%docinfo) | 627 logging.debug("documentViewer (getdocinfo) docinfo in session: %s"%docinfo) |
628 return docinfo | 628 return docinfo |
629 # new docinfo | 629 # new docinfo |
630 docinfo = {'mode': mode, 'url': url} | 630 docinfo = {'mode': mode, 'url': url} |
631 if mode=="texttool": #index.meta with texttool information | 631 if mode=="texttool": #index.meta with texttool information |
632 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) | 632 docinfo = self.getDocinfoFromTextTool(url, docinfo=docinfo) |
633 elif mode=="imagepath": | 633 elif mode=="imagepath": |
634 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) | 634 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) |
635 elif mode=="filepath": | 635 elif mode=="filepath": |
636 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) | 636 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo,cut=1) |
637 else: | 637 else: |
638 logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!") | 638 logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) |
639 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) | 639 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) |
640 | 640 |
641 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo) | 641 logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) |
642 self.REQUEST.SESSION['docinfo'] = docinfo | 642 self.REQUEST.SESSION['docinfo'] = docinfo |
643 return docinfo | 643 return docinfo |
644 | 644 |
645 def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None): | 645 def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None): |
646 """returns pageinfo with the given parameters""" | 646 """returns pageinfo with the given parameters""" |