|
|
| version 1.46, 2005/06/08 07:07:27 | version 1.64, 2007/10/04 14:15:33 |
|---|---|
| Line 16 import xml.dom.minidom | Line 16 import xml.dom.minidom |
| import urllib | import urllib |
| import xmlrpclib | import xmlrpclib |
| import vlp_xmlhelpers | import vlp_xmlhelpers |
| import sys | |
| import os | |
| from stat import * | |
| from types import * | from types import * |
| from Globals import package_home | from Globals import package_home |
| import transaction | |
| def lemmatize(str): | def lemmatize(str): |
| Line 142 def manage_addSendMailForm(self, id, toA | Line 145 def manage_addSendMailForm(self, id, toA |
| class VLP_essay(Folder): | class VLP_essay(Folder): |
| """classe für VLP essays""" | """classe fr VLP essays""" |
| meta_type="VLP_essay" | meta_type="VLP_essay" |
| Line 227 class VLP_essay(Folder): | Line 230 class VLP_essay(Folder): |
| pages.sort(sortFind) | pages.sort(sortFind) |
| #print str(pages[int(pagenum)][1]()) | #print str(pages[int(pagenum)][1]()) |
| if pages[int(pagenum)-1][1].meta_type=='File': | if pages[int(pagenum)-1][1].meta_type=='File': |
| #return makeXML(str(pages[int(pagenum)-1][1])) | #return makeXML(str(pages[int(pagenum)-1][1])) |
| Line 259 class VLP_essay(Folder): | Line 263 class VLP_essay(Folder): |
| retstr=url+"?p="+str(int(pagenum)+1) | retstr=url+"?p="+str(int(pagenum)+1) |
| return retstr | return retstr |
| def lastURL(self,pagenum,url): | |
| # teste ob performance ok, sonst in variable | |
| pages=len(self.ZopeFind(self,obj_metatypes=['DTML Document','File'])) | |
| return url+"?p="+str(pages) | |
| def previousURL(self,pagenum,url): | def previousURL(self,pagenum,url): |
| if int(pagenum)-1 > 0: | if int(pagenum)-1 > 0: |
| Line 343 class VLP_subcollection(ECHO_collection) | Line 353 class VLP_subcollection(ECHO_collection) |
| meta_type="VLP_subcollection" | meta_type="VLP_subcollection" |
| def getVLPSubcollectionToc(self,type): | |
| #different ordering depending on the type | |
| if(type == "(Collection)"): | |
| sort= "shortreference" | |
| else: | |
| sort = "startpages" | |
| #content of journals also displayed if not online | |
| if (type == "(JournalVolume)"): | |
| online ="" | |
| else: | |
| online ="AND online = 1" | |
| sort=self.collectionSort(type) | |
| item = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature | |
| WHERE volumeid ~ '%s\\\\M' """%self.getId() | |
| + """ %s AND not referenceType='%s' """%(online,type) | |
| + """ORDER BY """ + sort)] | |
| tocItem = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature | |
| WHERE reference = '%s' """%self.getId() | |
| + """AND online = 1 AND referenceType='%s' """%type | |
| + """ORDER BY """ + sort)] | |
| return tocItem+item | |
| def checkForFrontMatter(self,item): | def checkForFrontMatter(self,item): |
| """Teste ob Frontmatter exists""" | """Teste ob Frontmatter exists""" |
| if not item==self.getId(): | if not item==self.getId(): |
| Line 390 class VLP_collection(ECHO_collection): | Line 430 class VLP_collection(ECHO_collection): |
| def generateSubCollections(self): | def generateSubCollections(self,errorsTXT=""): |
| """erzeuge subcollectionen""" | """erzeuge subcollectionen""" |
| founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Book)','(Collection)','(Journal)')") | logging.debug("generateSubCollections") |
| founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Edited Book)','(Book)','(Collection)','(JournalVolume)','(Generic Container)')") | |
| self.REQUEST.RESPONSE.write("<html><body>\n") | self.REQUEST.RESPONSE.write("<h2>Create Subcollections</h2>\n") |
| for found in founds: | for found in founds: |
| foundCol=self.ZopeFind(self,obj_ids=[found.reference]) | try: |
| litid = str(found.reference) | |
| foundCol=self.ZopeFind(self,obj_ids=[litid]) | |
| if foundCol: | if foundCol: |
| logging.debug("generateSubCollections: deleting collection %s"%found.reference) | |
| self.manage_delObjects([foundCol[0][0]]) | self.manage_delObjects([foundCol[0][0]]) |
| manage_addVLP_subCollection(self,found.reference,found.titlerefdisplay,found.titlerefdisplay) | logging.debug("generateSubCollections: creating collection %s"%found.reference) |
| manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay) | |
| #getattr(self,found.reference).generateSubCollectionFromDB() | #getattr(self,found.reference).generateSubCollectionFromDB() |
| #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter) | #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter) |
| if os.path.exists(os.path.join(self.vlp_basis,found.reference)): | if os.path.exists(os.path.join(self.vlp_basis,litid)): |
| logging.debug("generateSubCollections: found collection dir %s"%litid) | |
| obj=getattr(self,found.reference) | obj=getattr(self,litid) |
| if not self.ZopeFind(obj,obj_ids=[found.reference]): | if not self.ZopeFind(obj,obj_ids=[litid]): |
| metalink=self.REQUEST['URL1']+"/"+found.reference+"/"+found.reference+"/index_meta" | metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta" |
| newObj=VLP_resource(found.reference,'',metalink,found.reference,found.reference,found.reference,'generated','book','','','','','','') | newObj=VLP_resource(litid,'',metalink,litid,litid,litid,'generated','book','','','','','','') |
| obj._setObject(found.reference,newObj) | obj._setObject(litid,newObj) |
| genObj=getattr(obj,found.reference) | |
| genObj=getattr(obj,litid) | |
| genObj.createIndexFile() | genObj.createIndexFile() |
| self.REQUEST.RESPONSE.write("<p>%s</p>\n"%found.reference) | self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid) |
| except: | |
| error=sys.exc_info()[0:2] | |
| logging.error("generateSubCollections: ERROR in %s"%litid) | |
| #logging.error("generateSubCollections: %s %s"%error) | |
| #self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1]))) | |
| errorsTXT+="<p>No subcollection of %s "%litid | |
| #errorsTXT+="<p>No subcollection of %s "%litid+"(ERROR: %s %s)</p>"%error | |
| return errorsTXT | |
| def VLP_path_configForm(self): | def VLP_path_configForm(self): |
| """change pt""" | """change pt""" |
| Line 431 class VLP_collection(ECHO_collection): | Line 486 class VLP_collection(ECHO_collection): |
| def updateCollection(self,RESPONSE=None): | def updateCollection(self,RESPONSE=None): |
| """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" | """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" |
| errorsTXT="<h2>Errors</h2>" | |
| RESPONSE.write("<html><body>") | |
| files=os.listdir(self.vlp_basis) | files=os.listdir(self.vlp_basis) |
| errorsTXT+="<h3>New Ressources</h3>" | |
| for fileName in files: | for fileName in files: |
| if fileName[0:3]=="lit": | if fileName[0:3]=="lit": |
| metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta" | metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta" |
| try: | |
| if not hasattr(self,fileName): | if not hasattr(self,fileName): |
| logging.debug("updateCollection: new %s"%fileName) | |
| RESPONSE.write("<p>new: %s\n</p>"%fileName) | |
| newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','') | newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','') |
| self._setObject(fileName,newObj) | self._setObject(fileName,newObj) |
| RESPONSE.write("got: %s\n"%fileName) | RESPONSE.write("<p>got: %s\n</p>"%fileName) |
| genObj=getattr(self,fileName) | genObj=getattr(self,fileName) |
| logging.debug("updateCollection: inspecting %s"%fileName) | |
| if hasattr(genObj,'createIndexFile'): | if hasattr(genObj,'createIndexFile'): |
| try: | |
| logging.debug("updateCollection: creating index for %s"%fileName) | |
| genObj.createIndexFile() | genObj.createIndexFile() |
| except: | |
| error=sys.exc_info()[0:2] | |
| RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(fileName,error[0],error[1])) | |
| errorsTXT+="<p>No indexfile of %s "+"(ERROR: %s %s)</p>"%error | |
| if genObj.meta_type=="VLP_subcollection": | |
| logging.debug("updateCollection: %s is subcollection"%fileName) | |
| genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum() | |
| else: | |
| genObj.pageSizeSum=genObj.getPageSizeSum() | |
| self.generateSubCollections() | except: |
| error=sys.exc_info()[0:2] | |
| RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(fileName,error[0],error[1])) | |
| errorsTXT+="<p>File not created:%s (ERROR: %s %s)</p>"%(fileName,error[0],error[1]) | |
| errorsTXT+=self.generateSubCollections() | |
| errorsTXT+="\n" | |
| RESPONSE.write(errorsTXT) | |
| if RESPONSE is not None: | |
| RESPONSE.redirect('manage_main') | |
| def updateCollectionMD(self,RESPONSE=None): | def updateCollectionMD(self,RESPONSE=None): |
| """updateMD""" | """updateMD""" |
| Line 654 class VLP_resource(ECHO_resource,Cacheab | Line 734 class VLP_resource(ECHO_resource,Cacheab |
| return 0 | return 0 |
| def getPageSizeSum(self): | |
| """generate average page size""" | |
| #size of hi resolution | |
| files=[] | |
| try: | |
| pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesHi') | |
| files=os.listdir(pathHi) | |
| hi=0 | |
| for f in files: | |
| hi+=os.stat(os.path.join(pathHi,f))[ST_SIZE] | |
| except: | |
| hi=0 | |
| #size of hi resolution | |
| try: | |
| pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesLo') | |
| files=os.listdir(pathHi) | |
| lo=0 | |
| for f in files: | |
| lo+=os.stat(os.path.join(pathHi,f))[ST_SIZE] | |
| except: | |
| lo=0 | |
| return (hi,lo,len(files)) | |
| def getPageWeights(self): | |
| """average Page sizes in kBytes""" | |
| res=getattr(self,'pageSizeSum',(0,0,1)) | |
| return (res[0]/(1024*res[2]),res[1]/(1024*res[2])) | |
| def dir2index(self): | def dir2index(self): |
| """dir to index""" | """dir to index""" |
| excludeNames=['Icon'] | excludeNames=['Icon'] |
| def calculateName(str): | def calculateName(str): |
| name=os.path.splitext(str[1:])[0] | name=os.path.splitext(str[1:])[0] |
| ret="%s: %s"%(str[0],name) | ret="%s: %s"%(str[0],name) |
| Line 673 class VLP_resource(ECHO_resource,Cacheab | Line 792 class VLP_resource(ECHO_resource,Cacheab |
| temp=[] | temp=[] |
| ret.sort() | ret.sort() |
| for x in ret: | for x in ret: |
| if (not (x[0]==".")) and (not x[0:4] in excludeNames): | if (not (x[0] in ('.',':'))) and (not x[0:4] in excludeNames): |
| temp.append((calculateName(x),os.path.splitext(x)[0])) | temp.append((calculateName(x),os.path.splitext(x)[0])) |
| return temp | return temp |
| Line 743 class VLP_resource(ECHO_resource,Cacheab | Line 861 class VLP_resource(ECHO_resource,Cacheab |
| def readIndexFile(self,url=None): | def readIndexFile(self,url=None): |
| """reads the indexfile. presently url not None isn't implemented. In the future url can be defined.""" | """reads the indexfile. presently url not None isn't implemented. In the future url can be defined.""" |
| if not url: | if not url: |
| url=self.absolute_url()+"/index.xml" | urlTmp=self.absolute_url()+"/index.xml" |
| if self.ZCacheable_isCachingEnabled(): | if self.ZCacheable_isCachingEnabled(): |
| result = self.ZCacheable_get(view_name=url) | result = self.ZCacheable_get(view_name=urlTmp) |
| if result is not None: | if result is not None: |
| # Got a cached value. | # Got a cached value. |
| return result | return result |
| pagelist=[] | pagelist=[] |
| fh=ECHO_helpers.urlopen(url) | if not url: |
| xmlTxt=getattr(self,'index.xml')() | |
| dom=xml.dom.minidom.parseString(xmlTxt) | |
| else: | |
| fh=ECHO_helpers.urlopen(urlTmp) | |
| dom=xml.dom.minidom.parse(fh) | dom=xml.dom.minidom.parse(fh) |
| Line 764 class VLP_resource(ECHO_resource,Cacheab | Line 887 class VLP_resource(ECHO_resource,Cacheab |
| fileName=page.getAttribute('file') | fileName=page.getAttribute('file') |
| pagelist.append((pageNum,text,fileName)) | pagelist.append((pageNum,text,fileName)) |
| self.ZCacheable_set(pagelist,view_name=url) | self.ZCacheable_set(pagelist,view_name=urlTmp) |
| return pagelist | return pagelist |
| def getFileName(self): | def getFileName(self): |
| Line 779 class VLP_resource(ECHO_resource,Cacheab | Line 902 class VLP_resource(ECHO_resource,Cacheab |
| def createIndexFile(self,RESPONSE=None): | def createIndexFile(self,RESPONSE=None): |
| """create index file""" | """create index file""" |
| logging.debug("createindexfile of %s"%self.id) | |
| pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)() | pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)() |
| if not hasattr(self,'index.xml'): | if not hasattr(self,'index.xml'): |
| zt=ZopePageTemplate('index.xml') | zt=ZopePageTemplate('index.xml') |
| self._setObject('index.xml',zt) | self._setObject('index.xml',zt) |
| else: | else: |
| zt=getattr(self,'index.xml') | zt=getattr(self,'index.xml') |
| #logging.debug("createindexfile uses %s"%pt) | |
| zt.pt_edit(pt, 'text/xml') | zt.pt_edit(pt, 'text/xml') |
| transaction.get().commit() | |
| if RESPONSE is not None: | if RESPONSE is not None: |
| RESPONSE.redirect('manage_main') | RESPONSE.redirect('manage_main') |