--- versionedFile/versionedFile.py 2006/05/22 10:54:31 1.60 +++ versionedFile/versionedFile.py 2007/04/03 13:18:47 1.70 @@ -1,6 +1,7 @@ from OFS.Folder import Folder from OFS.Image import File from OFS.Image import cookId +from OFS.DTMLDocument import DTMLDocument from Globals import DTMLFile, InitializeClass,package_home from Products.PageTemplates.PageTemplateFile import PageTemplateFile from AccessControl import getSecurityManager @@ -9,7 +10,6 @@ from Products.PageTemplates.ZopePageTemp from AccessControl import ClassSecurityInfo from difflib import Differ from pprint import pprint - from Products.ZCatalog.CatalogPathAwareness import CatalogAware try: @@ -23,19 +23,20 @@ import shutil import tempfile import os.path import urllib - +import logging import time try: from Products.ECHO_content.ECHO_collection import ECHO_basis except: print "ECHO Elements not imported" class ECHO_basis: - """leer""" - manage_options=() + """leer""" + manage_options=() - + def sortv(x,y): return cmp(x[0],y[0]) + tdir = "/tmp/downloadVersionedFiles" class generateDownloadZip: @@ -51,7 +52,7 @@ class generateDownloadZip: def __call__(self): """call generate download zip""" storeTempDir=tempfile.tempdir - tempfile.tempdir=tdir + tempfile.tempdir=tdir tmpPath=tempfile.mktemp() tmpZip=tempfile.mktemp()+".gtz" @@ -61,9 +62,10 @@ class generateDownloadZip: os.mkdir(tempfile.tempdir) if not os.path.exists(tmpPath): - os.mkdir(tmpPath) - - self.response="

1. step: getting the files

" + os.mkdir(tmpPath) + + tempfile.tempdir=storeTempDir + self.response="

1. step: getting the files

" for files in self.folder.ZopeFind(self.folder,obj_metatypes=['versionedFile']): lastV=files[1].getLastVersion() @@ -75,7 +77,7 @@ class generateDownloadZip: fh.close() self.response+="

2. step: creating the downloadable file

" - self.response+="

Create gtar
" + self.response+="

Create gtar
" self.response+="

This can take a while....
\n" fh=os.popen2("tar zcvf %s %s/*"%(tmpZip,tmpPath),1)[1] @@ -84,8 +86,8 @@ class generateDownloadZip: self.response+=c if c==")": self.response+="
\n" - - + + shutil.rmtree(tmpPath) @@ -97,7 +99,7 @@ class generateDownloadZip: self.response+="""

Click here for download ( %i Byte)

\n"""%(tmpFn,len) self.response+="""

The file you receive is a tar (gnutar) compressed file, after unpacking you will find a new folder tmp where the files are stored in.

""" self.response+="""

The file will be stored for a while, you can download it later, the URL is:

-

%s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn) +

%s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn) self.done=True @@ -128,14 +130,16 @@ class versionedFileFolder(Folder,ECHO_ba optTMP= Folder.manage_options manage_options =optTMP+( - {'label':'Generate Index.html','action':'generateIndexHTML'}, + {'label':'Generate Index.html','action':'generateIndexHTML'}, {'label':'Generate Image Index.html','action':'generateIndexHTML_image'}, {'label':'Generate history_template.html','action':'generateHistoryHTML'}, + {'label':'Generate addFileForm','action':'generateAddFileForm'}, {'label':'Import Folder','action':'importFolderForm'}, {'label':'Export Folder','action':'exportFolder'}, {'label':'Position of version number','action':'changeHistoryFileNamesForm'}, ) + def changeHistoryFileNamesForm(self): """change position of version num""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) @@ -261,19 +265,19 @@ class versionedFileFolder(Folder,ECHO_ba ## return pt() def downloadSet(self,fn): - """download prepared set""" - filename=os.path.join(tdir,fn) + """download prepared set""" + filename=os.path.join(tdir,fn) - - self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"downloadFileFolder.tgz") - self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") - len=os.stat(filename)[6] - self.REQUEST.RESPONSE.setHeader("Content-Length",len) - images=file(filename).read() - self.REQUEST.RESPONSE.write(images) - self.REQUEST.RESPONSE.close() + + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"downloadFileFolder.tgz") + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + len=os.stat(filename)[6] + self.REQUEST.RESPONSE.setHeader("Content-Length",len) + images=file(filename).read() + self.REQUEST.RESPONSE.write(images) + self.REQUEST.RESPONSE.close() - + def helpDownload(self): """download help""" @@ -304,11 +308,11 @@ class versionedFileFolder(Folder,ECHO_ba """lege standard addfileform an""" #TODO: write generateaddfileform only a dummy at them moment - if not self.ZopeFind(self,obj_ids=['addFileForm.dtml']): - zt=ZopePageTemplate('index.html') - self._setObject('index.html',zt) + if not self.ZopeFind(self,obj_ids=['addFileForm.html']): + zt=ZopePageTemplate('addFileForm.html') + self._setObject('addFileForm.html',zt) default_content_fn = os.path.join(package_home(globals()), - 'zpt/versionFileFolderMain.zpt') + 'zpt/fileAdd_template.zpt') text = open(default_content_fn).read() zt.pt_edit(text, 'text/html') @@ -374,12 +378,12 @@ class versionedFileFolder(Folder,ECHO_ba - try: - xc=getattr(x[1],'comment','ZZZZZZZZZZZZZ').lower() - except: - xc='ZZZZZZZZZZZZZ'.lower() - try: - yc=getattr(y[1],'comment','ZZZZZZZZZZZZZ').lower() + try: + xc=getattr(x[1],'comment','ZZZZZZZZZZZZZ').lower() + except: + xc='ZZZZZZZZZZZZZ'.lower() + try: + yc=getattr(y[1],'comment','ZZZZZZZZZZZZZ').lower() except: yc='ZZZZZZZZZZZZZ'.lower() @@ -442,11 +446,13 @@ class versionedFileFolder(Folder,ECHO_ba def addFileForm(self): """add a file""" - ext=self.ZopeFind(self,obj_ids=["addFileForm.dtml"]) + ext=getattr(self,'addFileForm.html',None) + logging.error("Found %s"%ext) if ext: - return ext[0][1]('',globals(),version='1',AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER) + out=ext + else: - out=DTMLFile('dtml/newFileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version='1').__of__(self) + out=DTMLFile('dtml/newFileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version='1').__of__(self) return out() @@ -539,6 +545,8 @@ class versionedFileObject(File): manage_editForm._setName('manage_editForm') + + security.declarePublic('getTitle') def getTitle(self): @@ -580,7 +588,7 @@ class versionedFileObject(File): return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer']) return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history") - + security.declarePublic('getVersionComment') def getVersionComment(self): """getversioncomment""" @@ -594,7 +602,7 @@ class versionedFileObject(File): if hasattr(self,'time'): return time.strftime("%Y-%m-%d %H:%M:%S",self.time) elif hasattr(self,'timefixed'): - return self.timefixed + return self.timefixed else: setattr(self,'timefixed',self.bobobase_modification_time().ISO()) return self.bobobase_modification_time().ISO() @@ -608,18 +616,18 @@ class versionedFileObject(File): self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId()) self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") - #try: - # txt=self.index_html() - #except: - # txt=self.index_html(REQUEST,RESPONSE) - # - #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)") - + #try: + # txt=self.index_html() + #except: + # txt=self.index_html(REQUEST,RESPONSE) + # + #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)") + self.content_type="application/octet-stream" self.REQUEST.RESPONSE.redirect(self.absolute_url()) #txt=urllib.urlopen(self.absolute_url()).read() #self.REQUEST.RESPONSE.write(txt) - + #self.REQUEST.close() @@ -648,14 +656,10 @@ class versionedFileObject(File): """get version""" return self.versionNumber - security.declarePublic('getVersionComment') - def getVersionComment(self): - """get version""" - return self.versionComment - security.declarePublic('lastEditor') + security.declarePublic('lastEditor') def lastEditor(self): """last Editor""" @@ -665,7 +669,7 @@ class versionedFileObject(File): except:#old version of versionded file sometimes stored the user object and not only the name the following corrects this ret=str(self.author).replace("-","\n") ret=ret.replace("\r","\n") - return ret + return ret.lstrip().rstrip() else: jar=self._p_jar @@ -816,6 +820,25 @@ class versionedFile(CatalogAware,Folder) self.comment_date=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) + + security.declarePublic('getLastChangeDate') + + def getLastChangeDate(self): + """get last change date""" + lv=self.getLastVersion() + time=lv.getTime() + return time + + def getLastEditor(self): + """get last change date""" + lv=self.getLastVersion() + le=lv.lastEditor() + return le + + def getLockedBy(self): + """get locked by""" + return str(self.lockedBy) + security.declarePublic('getLastVersion') def getLastVersion(self): """Last Version""" @@ -839,12 +862,24 @@ class versionedFile(CatalogAware,Folder) def diff(self,data): """differenz between lastversion and data""" d=Differ() - tmp=self.getLastVersion().data + data=data.rstrip() + try: + tmp=self.getLastVersion().data.rstrip() + except: + tmp=str(self.getLastVersion().data).rstrip() #print "XX",data,tmp - l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) - + + try: + l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) + except: + try: + l=list(d.compare(repr(data).splitlines(1),tmp.splitlines(1))) + except: + return 9999,[] + plus=0 minus=0 + for a in l: if a[0]=='+': plus+=1 @@ -896,9 +931,15 @@ class versionedFile(CatalogAware,Folder) return ret security.declareProtected('AUTHENTICATED_USER','forceunlock') - def forceunlock(self,RESPONSE): + def forceunlock(self,RESPONSE=None): """unlock""" + #safe who had the lock + if self.lockedBy: + self.brokenLock=str(self.lockedBy) + else: + self.brokenLock="" self.lockedBy='' + return self.brokenLock security.declareProtected('AUTHENTICATED_USER','unlock') def unlock(self,RESPONSE): @@ -968,6 +1009,10 @@ class versionedFile(CatalogAware,Folder) objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion())) self.REQUEST.SESSION['objID_parent']=self.getId() + if getattr(self,'defaultFileCatalog',None): + + self.reindex_object() + if RESPONSE: obj=self.ZopeFind(self,obj_ids=[id])[0][1] if obj.getSize()==0: @@ -989,13 +1034,13 @@ class versionedFile(CatalogAware,Folder) self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().getId()) self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") - #try: - # txt=self.getLastVersion.index_html() - #except: - # txt=self.getLastVersion.index_html(REQUEST,RESPONSE) + #try: + # txt=self.getLastVersion.index_html() + #except: + # txt=self.getLastVersion.index_html(REQUEST,RESPONSE) - #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)") - + #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)") + self.content_type="application/octet-stream" #self.REQUEST.RESPONSE.write("bl") #self.REQUEST.RESPONSE.write(txt)