--- cdli/cdli_files.py 2006/06/14 18:43:38 1.22 +++ cdli/cdli_files.py 2006/06/15 22:02:40 1.25 @@ -214,7 +214,9 @@ class uploadATFThread(Thread): app = root['Application'] ctx = self.getContext(app,serverport=self.serverport) self.uploadATFThread(ctx,self.upload,self.basketId) - ctx.cdliRoot.cdli_main.tmpStore=self.returnValue + + ctx.cdliRoot.cdli_main.tmpStore2[self.getName()[0:]]=self.returnValue + get_transaction().commit() while self.continueVar: @@ -231,7 +233,8 @@ class uploadATFThread(Thread): """upload an atf file""" #TODO: add comments #TODO: finish uploadATF - self.result="

I am loading your file...

" + self.result="

I got your file, start now to split it into single atf-files!

" + #make sure that id is a string and not an integer basketId=str(basketId) @@ -248,7 +251,7 @@ class uploadATFThread(Thread): psNotInCatalog=[] # files not in the catalog #split the uploadedd atf file - basketNameFromFile, numberOfFiles=splitatf(upload,dir) + basketNameFromFile, numberOfFiles=splitatf(upload,dir,ext=self) #find basketId if not set @@ -267,12 +270,13 @@ class uploadATFThread(Thread): basketLen=getattr(ctx2.basketContainer,basketId).getLastVersion().numberOfItems() - self.result+="

I got the files

I am checking now the files

" + self.result+="""

I got the files

< + p>I am computing the differences to the exisiting files

""" #start to check the files for fn in os.listdir(dir): - self.result+="

check:%s

"%fn + self.result+="

process:%s

"%fn # check if file is in the catalog #TODO: checkCatalog is not implemented yet @@ -1050,10 +1054,11 @@ def manage_addCDLIBasketVersion(self,use else: return ob -class CDLIFileObject(versionedFileObject): +class CDLIFileObject(versionedFileObject,CatalogAware): """CDLI file object""" meta_type="CDLI File Object" + default_catalog='CDLIObjectsCatalog' security=ClassSecurityInfo() @@ -1220,22 +1225,6 @@ def manage_addCDLIFile(self,id,title,loc self._setObject(id,newObj) -# try: -# self._setObject(id,newObj) -# tryToggle=False -# except: -# while tryToggle and (tryCount < 10): -# try: -# #get_transaction().commit() -# self._setObject(id,newObj) -# tryToggle=False -# -# except: -# time.sleep(10) -# tryCount+=1 - #no successfull adding - if tryToggle: - print "ERROR",id if RESPONSE is not None: @@ -1244,11 +1233,19 @@ def manage_addCDLIFile(self,id,title,loc -def splitatf(fh,dir=None): +def splitatf(fh,dir=None,ext=None): """split it""" ret=None nf=None + i=0 for line in fh.readlines(): + if ext: + i+=1 + if (i%100)==0: + ext.result+="." + if i==10000: + i=0 + ext.result+="
" #check if basket name is in the first line if line.find("#atf basket")>=0: ret=line.replace('#atf basket ','') @@ -1279,7 +1276,9 @@ class CDLIFileFolder(versionedFileFolder filesMetaType=['CDLI file'] folderMetaType=['CDLI Folder'] default_catalog='CDLICatalog' - tmpStore=None + defaultFileCatalog=default_catalog #wenn dieses definiert ist, wird beim hinzufŸgen einer neuen version eines files dieser catalog neuiniziert + + tmpStore2={} def setTemp(self,name,value): """set tmp""" @@ -1324,7 +1323,7 @@ class CDLIFileFolder(versionedFileFolder - def findObjectsFromList(self,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None): + def findObjectsFromList(self,display=False,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None): """findObjectsFromList (, TAB oder LINE separated)""" @@ -1361,9 +1360,18 @@ class CDLIFileFolder(versionedFileFolder ret+=self.CDLICatalog({'title':fileId}) #TODO: get rid of one of these.. - self.REQUEST.SESSION['fileIds']=[x.getObject().getId() for x in ret]#store fieldIds in session for further usage + ids=[x.getObject().getId() for x in ret] + self.REQUEST.SESSION['fileIds']=ids#store fieldIds in session for further usage self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds'] - return ret + + if display: + pt=getattr(self,'filelist.html') + + return pt(search=ids) + else: + return ret + + if start: RESPONSE.redirect("filelist.html?start:int="+str(start)) @@ -1485,19 +1493,46 @@ class CDLIRoot(Folder): meta_type="CDLIRoot" - def refreshTxt(self,txt=""): + def getChangesByAuthor(self,author): + """getChangesByAuthor""" + zcat=self.CDLICatalog + return zcat({'lastEditor':author, + 'sort_on':'getTime', + 'sort_order':'descending', + 'sort_limit':n})[:n ] + + def getLastChanges(self,n=100): + """get the last n changes""" + n=int(n) + zcat=self.CDLICatalog + return zcat({'sort_on':'getLastChangeDate', + 'sort_order':'descending', + 'sort_limit':n})[:n ] + + + def getLastChanges_html(self,n=100): + """get the last n changes""" + list = [x.getId for x in self.getLastChanges(n)] + return self.cdli_main.findObjectsFromList(list=list,display=True) + + def refreshTxt(self,txt="",threadName=None): """txt fuer refresh""" - return """ 2;url=%s?repeat=%s """%(self.absolute_url()+txt,self.threadName) + return """ 2;url=%s?repeat=%s """%(self.absolute_url()+txt,threadName) - def getResult(self): + def getResult(self,threadName=None): """result of thread""" try: - return self._v_uploadATF.getResult() + return self._v_uploadATF[threadName].getResult() except: return "One moment, please" + + def checkThreads(self): + """check threads""" + return threading.enumerate() + def uploadATF(self,repeat=None,upload=None,basketId=0,RESPONSE=None): """standard ausgabe""" #self._v_uploadATF.returnValue=None @@ -1505,33 +1540,40 @@ class CDLIRoot(Folder): threadName=repeat if not threadName or threadName=="": tmpVar=False + thread=uploadATFThread() - self._v_uploadATF=thread + threadName=thread.getName()[0:] + if not hasattr(self,'_v_uploadATF'): + self._v_uploadATF={} + + self._v_uploadATF[threadName]=thread #self._xmltrans.start() #thread=Thread(target=self._v_uploadATF) - self._v_uploadATF.set(upload,basketId,self.REQUEST['AUTHENTICATED_USER'],serverport=self.REQUEST['SERVER_PORT']) + self._v_uploadATF[threadName].set(upload,basketId,self.REQUEST['AUTHENTICATED_USER'],serverport=self.REQUEST['SERVER_PORT']) #thread.start() - self._v_uploadATF.start() + self._v_uploadATF[threadName].start() - self.threadName=self._v_uploadATF.getName()[0:] + self.threadName=self._v_uploadATF[threadName].getName()[0:] wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template']) if wait_template: return wait_template[0][1]() pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','uploadATFWait.zpt')).__of__(self) - return pt(txt='/uploadATF') + return pt(txt='/uploadATF',threadName=threadName) #_v_xmltrans.run() else: #recover thread, if lost if not hasattr(self,'_v_uploadATF'): + self._v_uploadATF={} + if not self._v_uploadATF.get(threadName,None): for thread in threading.enumerate(): if threadName == thread.getName(): - self._v_uploadATF=thread - - if not self._v_uploadATF.returnValue: + self._v_uploadATF[threadName]=thread + + if not self._v_uploadATF[threadName].returnValue: wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template']) @@ -1540,19 +1582,20 @@ class CDLIRoot(Folder): pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','uploadATFWait.zpt')).__of__(self) - return pt(txt='/uploadATF') + return pt(txt='/uploadATF',threadName=threadName) else: # tmp={} -# for key in self._v_uploadATF.returnValue.keys(): -# t=self._v_uploadATF.returnValue[key] +# for key in self._v_uploadATF[threadName].returnValue.keys(): +# t=self._v_uploadATF[threadName].returnValue[key] # if type(t) is ListType: -# tmp[key]=self._v_uploadATF.returnValue[key][0:] +# tmp[key]=self._v_uploadATF[threadName].returnValue[key][0:] # else: -# tmp[key]=self._v_uploadATF.returnValue[key] - tmp=self.cdli_main.tmpStore - - self._v_uploadATF.continueVar=False +# tmp[key]=self._v_uploadATF[threadName].returnValue[key] + + tmp=self.cdli_main.tmpStore2[threadName] + del(self.cdli_main.tmpStore2[threadName]) + self._v_uploadATF[threadName].continueVar=False self.REQUEST.SESSION['changed']=[x[0].getId() for x in tmp['changed']] self.REQUEST.SESSION['errors']=[x.getId() for x in tmp['errors']] self.REQUEST.SESSION['newPs']=tmp['newPs'] @@ -1569,41 +1612,43 @@ class CDLIRoot(Folder): threadName=repeat if not threadName or threadName=="": - - - self._v_uploadATF=uploadATFfinallyThread() + thread=uploadATFfinallyThread() + threadName=thread.getName()[0:] + self._v_uploadATF[threadName]=thread - self._v_uploadATF.set(procedure,comment=comment,basketname=basketname,unlock=unlock,SESSION=self.REQUEST.SESSION,username=self.REQUEST['AUTHENTICATED_USER'],serverport=self.REQUEST['SERVER_PORT']) + self._v_uploadATF[threadName].set(procedure,comment=comment,basketname=basketname,unlock=unlock,SESSION=self.REQUEST.SESSION,username=self.REQUEST['AUTHENTICATED_USER'],serverport=self.REQUEST['SERVER_PORT']) - self._v_uploadATF.start() + self._v_uploadATF[threadName].start() - self.threadName=self._v_uploadATF.getName()[0:] + wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template']) if wait_template: return wait_template[0][1]() pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','uploadATFWait.zpt')).__of__(self) - return pt(txt='/uploadATFfinally') + return pt(txt='/uploadATFfinally',threadName=threadName) #_v_xmltrans.run() else: #recover thread, if lost if not hasattr(self,'_v_uploadATF'): + self._v_uploadATF={} + if not self._v_uploadATF.get(threadName,None): for thread in threading.enumerate(): if threadName == thread.getName(): - self._v_uploadATF=thread + self._v_uploadATF[threadName]=thread - if hasattr(self,'_v_uploadATF') and (self._v_uploadATF is not None) and (not self._v_uploadATF.end) : + if self._v_uploadATF.get(threadName,None) and (self._v_uploadATF[threadName] is not None) and (not self._v_uploadATF[threadName].end) : wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template']) if wait_template: return wait_template[0][1]() pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','uploadATFWait.zpt')).__of__(self) - return pt(txt='/uploadATFfinally') + return pt(txt='/uploadATFfinally',threadName=threadName) else: if RESPONSE is not None: