--- ECHO_content/VLPExtension.py 2008/11/16 12:15:42 1.83 +++ ECHO_content/VLPExtension.py 2009/06/09 14:05:20 1.91 @@ -488,7 +488,10 @@ from zope.interface import implements from zope.publisher.interfaces import NotFound from zope.app import zapi from zope.component import queryMultiAdapter -from ZPublisher.BaseRequest import DefaultPublishTraverse +try: + from ZPublisher.BaseRequest import DefaultPublishTraverse +except: + pass class VLP_collection(ECHO_collection,Acquisition.Explicit): """VLP spezifische Erweiterung der Collection""" @@ -520,18 +523,18 @@ class VLP_collection(ECHO_collection,Acq actual_url=request['ACTUAL_URL'] lastActual=actual_url.split("/")[-1] - + logging.debug("pub_trav:"+actual_url) if name.startswith("lit"): #umleitung wenn lit aufgerufen wirk # umleitung auf den eigentlichen folder nur wenn direkt der Folder litXXX oder dessen index_html methode aufgerufen wird - if lastActual.startswith("lit") or (lastActual=="index_html") or (lastActual=="index_meta"): + if lastActual.startswith("lit") or (lastActual=="index_html") or (lastActual=="index_meta") or (lastActual=="getTitle") or (lastActual=="getMetaDataLink") or (lastActual=="hasTranscription") or (lastActual=="transcription"): #obj=self. ZopeFind(self,obj_ids=[name],search_sub=1) ob=self.findObjFromLitName(name) if not ob: return "LIt not found" else: - logging.error("request:"+repr(ob)) + logging.debug("request:"+repr(ob)) request.response.setStatus(200) #if (lastActual=="index_meta"): # logging.debug("index_meta requested") @@ -582,7 +585,8 @@ class VLP_collection(ECHO_collection,Acq if foundCol: col = foundCol logging.debug("generateSubCollections: subcollection %s exists (%s)"%(repr(col),found.reference)) - if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay): + logging.debug(repr([col.title,found.titlerefdisplay,col.label,found.titlerefdisplay])) + if (unicodify(col.title) != unicodify(found.titlerefdisplay)) or (unicodify(col.label) != unicodify(found.titlerefdisplay)): # subcollection seems to have changed logging.debug("generateSubCollections: subcollection has changed, recreating!") col.aq_parent.manage_delObjects([col.getId()]) @@ -611,11 +615,12 @@ class VLP_collection(ECHO_collection,Acq error=sys.exc_info()[0:2] logging.error("generateSubCollections: ERROR in %s"%litid) if RESPONSE is not None: + RESPONSE.write("

(ERROR updateII(%s): %s %s TXT: %s)\n

"%(litid,error[0],error[1],sys.exc_info()[2])) RESPONSE.write("

(ERROR (%s): %s %s)

\n"%(litid,error[0],error[1])) - #logging.error("generateSubCollections: %s %s"%error) - #self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1]))) + logging.error("generateSubCollections: %s %s"%error) + self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1]))) errorsTXT+="

ERROR: No subcollection of %s (ERROR: %s %s)

\n"%(litid,error[0],error[1]) - #errorsTXT+="

No subcollection of %s "%litid+"(ERROR: %s %s)

"%error + errorsTXT+="

No subcollection of %s "%litid+"(ERROR: %s %s)

"%error return errorsTXT @@ -637,8 +642,11 @@ class VLP_collection(ECHO_collection,Acq logging.error("getOrCreateFolder wrong filename: %s"%fileName) return None - - restName="%08d"%int(fileName[3:]) + try: + restName="%08d"%int(fileName[3:]) + except: + logging.error("getOrCreateFolder wrong filename: %s"%fileName) + return None fs=(restName[0:2],restName[0:4],restName[0:6]) @@ -653,8 +661,9 @@ class VLP_collection(ECHO_collection,Acq return current - def updateCollection(self,forceUpdate=False,RESPONSE=None): - """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" + def changeOrAddResources(self,forceUpdate=False,RESPONSE=None): + """changes ord updates all resources found in the file system""" + errorsTXT="

Errors

" if RESPONSE is not None: RESPONSE.setHeader('Content-Type','text/html') @@ -711,7 +720,7 @@ class VLP_collection(ECHO_collection,Acq except: error=sys.exc_info()[0:2] if RESPONSE is not None: - RESPONSE.write("(ERROR (%s): %s %s) "%(fileName,error[0],error[1])) + RESPONSE.write("(ERROR Update(%s): %s %s %s) "%(fileName,error[0],error[1],sys.exc_info()[2])) errorsTXT+="

ERROR creating index for %s "%fileName+"(ERROR: %s %s)

\n"%error # update pageSizeSum for subcollections @@ -730,10 +739,16 @@ class VLP_collection(ECHO_collection,Acq error=sys.exc_info()[0:2] logging.error("updateCollection: ERROR in %s (%s %s)"%(fileName,error[0],error[1])) if RESPONSE is not None: - RESPONSE.write("

(ERROR (%s): %s %s)

\n"%(fileName,error[0],error[1])) + RESPONSE.write("(ERROR updateII(%s): %s %s %s) "%(fileName,error[0],error[1],sys.exc_info()[2])) errorsTXT+="

File not created:%s (ERROR: %s %s)

\n"%(fileName,error[0],error[1]) - - # update subcollections + return errorsTXT + + def updateCollection(self,forceUpdate=True,RESPONSE=None): + """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" + + # update subcollections + errorsTXT="" + errorsTXT+=self.changeOrAddResources(forceUpdate, RESPONSE); errorsTXT+=self.generateSubCollections(forceUpdate=forceUpdate,RESPONSE=RESPONSE) errorsTXT+="\n" if RESPONSE is not None: @@ -795,9 +810,14 @@ class VLP_resource(ECHO_resource,Cacheab meta_type="VLP_resource" + def _p_resolveConflict(self,oldstate,savedstate,newstate): + logging.debug("updateCollection: Have to resolve conflict!") + return newstate + #vlp_basis="/mpiwg/online/permanent/vlp" + referencetypes=[] manage_options=ECHO_resource.manage_options+Cacheable.manage_options+( @@ -807,17 +827,68 @@ class VLP_resource(ECHO_resource,Cacheab {'label':'Generate Library Template','action':'generateLibraryTemplateHTML'}, ) + def getMetaDataLink(self): + """link auf die metatdaten""" + return self.absolute_url()+"/index_meta" + + def getTitle(self): + """Title der Ressource""" + title= self.ZSQLSimpleSearch("""select title from vl_literature where reference= \'%s\' """ %self.getId())[0].title + logging.debug(title) + return title + def getImagePath(self): """Pfad zu den Images""" + path=None if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')): - return os.path.join(self.vlp_basis,self.resourceID,'pageimg') + path= os.path.join(self.vlp_basis,self.resourceID,'pageimg') elif os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pages')): - return os.path.join(self.vlp_basis,self.resourceID,'pages') - else: - return "no images " - + path = os.path.join(self.vlp_basis,self.resourceID,'pages') + # workaround in some cases there seem to be no pictures in pages + + if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi')): + + + pagesHi = os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi')) + if path is None: + return os.path.join(self.vlp_basis,self.resourceID,'pagesHi') + + pages = os.listdir(path) + + if len (pagesHi) > len(pages): + + countHi=0 + for p in pagesHi: + dat,ext = os.path.splitext(p) + if ext.lower() in [".tiff",".tif",".jpg"]: + countHi+=1 + count=0 + for p in pages: + dat,ext = os.path.splitext(p) + if ext.lower() in [".tiff",".tif",".jpg"]: + count+=1 + + if countHi > count: + path=os.path.join(self.vlp_basis,self.resourceID,'pagesHi') + + logging.error("pages < pagesHi: %s"%self.resourceID) + if path is None: + + + if len (os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))) > len(os.listdir(path)): + + + + path=os.path.join(self.vlp_basis,self.resourceID,'pagesHi') + logging.error("pages < pagesHi: %s"%self.resourceID) + else: + + logging.error("no images: %s"%self.resourceID) + return None + + return path def transcription(self): @@ -878,7 +949,7 @@ class VLP_resource(ECHO_resource,Cacheab ret+="" re2=ret[0:] - re3=re2.decode('latin-1').encode('utf-8') + re3=self.unicodify(re2) #re3=re2 ft=self.ZopeFind(self,obj_metatypes=['ECHO_fullText']) @@ -899,6 +970,16 @@ class VLP_resource(ECHO_resource,Cacheab else: return "no: %s"%self.getId() + def hasTranscription(self): + """transcription""" + + if not hasattr(self,'fulltext'): + self.copyTranscriptionFromDB() + if not hasattr(self,'fulltext'): #still not + return False + + return True + def resetMetaLink(self,all="no",RESPONSE=None): """resets metalink to standard resp. in case of server change it sets to the new server url""" if all=="yes": @@ -1044,13 +1125,14 @@ class VLP_resource(ECHO_resource,Cacheab ret="%s: %s"%(str[0],name) return ret - try: - ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')) - self.imagePath='pageimg' - except: - ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pages')) - self.imagePath='pages' + self.imagePathFull=self.getImagePath(); + self.imagePath=self.imagePathFull.split("/")[-1] + if (self.imagePath is None): + return None + temp=[] + ret = os.listdir(self.imagePathFull) + ret.sort() for x in ret: if (not (x[0] in ('.',':'))) and (not x[0:4] in excludeNames): @@ -1169,7 +1251,10 @@ class VLP_resource(ECHO_resource,Cacheab zt=getattr(self,'index.xml') if not forceUpdate: # check if directory is newer (self.imagePath sould be set by now) - imgdir = os.path.join(self.vlp_basis, self.resourceID, self.imagePath) + path = self.getImagePath() + if (path is None): + return "CREATE INDEX FILE NOT POSSIBLE" + imgdir = os.path.join(path) dirtime = os.path.getmtime(imgdir) zttime = zt.bobobase_modification_time() logging.debug("createindexfile: dir %s of %s index of %s"%(imgdir,dirtime,zttime))