--- ECHO_content/VLPExtension.py 2007/10/04 14:15:33 1.64 +++ ECHO_content/VLPExtension.py 2007/10/04 18:45:33 1.65 @@ -430,29 +430,33 @@ class VLP_collection(ECHO_collection): - def generateSubCollections(self,errorsTXT=""): + def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None): """erzeuge subcollectionen""" logging.debug("generateSubCollections") founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Edited Book)','(Book)','(Collection)','(JournalVolume)','(Generic Container)')") - self.REQUEST.RESPONSE.write("

Create Subcollections

\n") + if RESPONSE is not None: + RESPONSE.setHeader('Content-Type','text/html') + self.REQUEST.RESPONSE.write("

Create Subcollections

\n") for found in founds: - try: litid = str(found.reference) foundCol=self.ZopeFind(self,obj_ids=[litid]) if foundCol: - logging.debug("generateSubCollections: deleting collection %s"%found.reference) - self.manage_delObjects([foundCol[0][0]]) - - logging.debug("generateSubCollections: creating collection %s"%found.reference) - manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay) - #getattr(self,found.reference).generateSubCollectionFromDB() + col = foundCol[0][1] + logging.debug("generateSubCollections: subcollection %s exists (%s)"%(col.getId(),found.reference)) + if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay): + # subcollection seems to have changed + logging.debug("generateSubCollections: subcollection has changed, recreating!") + self.manage_delObjects([foundCol[0][0]]) + manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay) + else: + logging.debug("generateSubCollections: creating new subcollection %s"%found.reference) + manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay) #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter) if os.path.exists(os.path.join(self.vlp_basis,litid)): - logging.debug("generateSubCollections: found collection dir %s"%litid) - + logging.debug("generateSubCollections: found frontmatter in %s"%litid) obj=getattr(self,litid) if not self.ZopeFind(obj,obj_ids=[litid]): metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta" @@ -460,15 +464,19 @@ class VLP_collection(ECHO_collection): obj._setObject(litid,newObj) genObj=getattr(obj,litid) - genObj.createIndexFile() + genObj.createIndexFile(forceUpdate=forceUpdate) + + if RESPONSE is not None: + self.REQUEST.RESPONSE.write("

%s

\n"%litid) - self.REQUEST.RESPONSE.write("

%s

\n"%litid) except: error=sys.exc_info()[0:2] logging.error("generateSubCollections: ERROR in %s"%litid) + if RESPONSE is not None: + 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]))) - errorsTXT+="

No subcollection of %s "%litid + 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 return errorsTXT @@ -484,53 +492,68 @@ class VLP_collection(ECHO_collection): if RESPONSE is not None: RESPONSE.redirect('manage_main') - def updateCollection(self,RESPONSE=None): + def updateCollection(self,forceUpdate=False,RESPONSE=None): """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" errorsTXT="

Errors

" - RESPONSE.write("") - files=os.listdir(self.vlp_basis) - - errorsTXT+="

New Ressources

" + if RESPONSE is not None: + RESPONSE.setHeader('Content-Type','text/html') + RESPONSE.write("") + files=os.listdir(self.vlp_basis) for fileName in files: - if fileName[0:3]=="lit": - metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta" try: if not hasattr(self,fileName): + # create new resource logging.debug("updateCollection: new %s"%fileName) - RESPONSE.write("

new: %s\n

"%fileName) + if RESPONSE is not None: + RESPONSE.write("

new: %s

\n"%fileName) newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','') self._setObject(fileName,newObj) - RESPONSE.write("

got: %s\n

"%fileName) + if RESPONSE is not None: + RESPONSE.write("

got: %s "%fileName) genObj=getattr(self,fileName) logging.debug("updateCollection: inspecting %s"%fileName) + # create index if hasattr(genObj,'createIndexFile'): try: logging.debug("updateCollection: creating index for %s"%fileName) - genObj.createIndexFile() + msg = genObj.createIndexFile(forceUpdate=forceUpdate) + if msg and RESPONSE is not None: + RESPONSE.write(msg) except: error=sys.exc_info()[0:2] - RESPONSE.write("

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

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

No indexfile of %s "+"(ERROR: %s %s)

"%error - + if RESPONSE is not None: + RESPONSE.write("(ERROR (%s): %s %s) "%(fileName,error[0],error[1])) + errorsTXT+="

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

\n"%error + + # update pageSizeSum for subcollections if genObj.meta_type=="VLP_subcollection": + if RESPONSE is not None: + RESPONSE.write(" is subcollection") logging.debug("updateCollection: %s is subcollection"%fileName) genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum() else: genObj.pageSizeSum=genObj.getPageSizeSum() - + + if RESPONSE is not None: + RESPONSE.write("

\n") + except: error=sys.exc_info()[0:2] - RESPONSE.write("

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

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

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

"%(fileName,error[0],error[1]) - - errorsTXT+=self.generateSubCollections() + 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])) + errorsTXT+="

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

\n"%(fileName,error[0],error[1]) + + # update subcollections + errorsTXT+=self.generateSubCollections(forceUpdate=forceUpdate,RESPONSE=RESPONSE) errorsTXT+="\n" - RESPONSE.write(errorsTXT) - + if RESPONSE is not None: + RESPONSE.write(errorsTXT) + RESPONSE.write("") def updateCollectionMD(self,RESPONSE=None): """updateMD""" @@ -899,18 +922,31 @@ class VLP_resource(ECHO_resource,Cacheab pageinfo=self.readIndexFile()[pn-1] return pageinfo[2] - def createIndexFile(self,RESPONSE=None): + def createIndexFile(self,forceUpdate=False,RESPONSE=None): """create index file""" - logging.debug("createindexfile of %s"%self.id) - pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)() - if not hasattr(self,'index.xml'): + if hasattr(self,'index.xml'): + # index exists + 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) + dirtime = os.path.getmtime(imgdir) + zttime = zt.bobobase_modification_time() + logging.debug("createindexfile: dir %s of %s index of %s"%(imgdir,dirtime,zttime)) + if dirtime < zttime: + # nothing to do + logging.debug("createindexfile: dir %s older than index"%(imgdir)) + return "index is up to date" + + else: + # create new index template zt=ZopePageTemplate('index.xml') self._setObject('index.xml',zt) - else: - zt=getattr(self,'index.xml') - + + # fill index template + pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)() #logging.debug("createindexfile uses %s"%pt) zt.pt_edit(pt, 'text/xml') transaction.get().commit()