--- cdli/cdli_files.py 2006/06/13 18:34:10 1.19 +++ cdli/cdli_files.py 2006/06/13 20:42:47 1.20 @@ -17,19 +17,21 @@ from threading import Thread from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.BaseRequest import RequestContainer - +import threading global tmpVar class uploadATFfinallyThread(Thread): - + """class for adding uploaded filed (temporarily stored in the staging area at /tmp""" + def __init__(self): + """init for uploadATFfinallyThread""" self.continueVar=True self.returnValue=None self.end=False Thread.__init__(self) def set(self,procedure,comment="",basketname='',unlock=None,SESSION=None,username=None,serverport="8080"): - """set values""" + """set start values for the thread""" self.procedure=procedure self.comment=comment self.basketname=basketname @@ -39,11 +41,13 @@ class uploadATFfinallyThread(Thread): self.serverport=serverport def __call__(self): - """wait""" + """call of the thread (equals run)""" self.run() return True def getContext(self, app,serverport="8080"): + """get the context within the ZODB""" + resp = HTTPResponse(stdout=None) env = { 'SERVER_NAME':'localhost', @@ -55,42 +59,56 @@ class uploadATFfinallyThread(Thread): def run(self): - + """run""" + self.result="" + #find context within ZODB from Zope import DB conn = DB.open() root = conn.root() app = root['Application'] ctx = self.getContext(app,serverport=self.serverport) + #add the files self.uploadATFfinallyThread(ctx,self.procedure,comment=self.comment,basketname=self.basketname,unlock=self.unlock,SESSION=self.SESSION,username=self.username) + #commit the transactions get_transaction().commit() conn.close() + #set flag for end of this method self.end=True return True def getResult(self): + """method for accessing result""" + return self.result def uploadATFfinallyThread(self,ctx,procedure,comment="",basketname='',unlock=None,RESPONSE=None,SESSION=None,username=None): """upload the files""" + #TODO: make this configurable, at the moment, rootFolder for cdli has to be cdliRoot ctx2=ctx.cdliRoot self.result+="
Adding files
" + #TODO: make this configurable, at the moment base folder for the files has to be cdli_main ctx2.cdli_main.importFiles(comment=comment,author=str(username) ,folderName=tmpDir, files=newPs,ext=self) - #unlock + #unlock locked files? if unlock: self.result+="Unlock files
" unlockFns=[] @@ -123,6 +142,7 @@ class uploadATFfinallyThread(Thread): founds[0].getObject().lockedBy="" + #if a basketname is give, add files to the basket if not (basketname ==''): self.result+="Add basket
" basketId=ctx2.basketContainer.getBasketIdfromName(basketname) @@ -142,8 +162,11 @@ class uploadATFfinallyThread(Thread): return True class uploadATFThread(Thread): + """class for checking the files befor uploading""" def __init__(self): + """initialise""" + self.continueVar=True self.returnValue=None @@ -151,6 +174,7 @@ class uploadATFThread(Thread): def set(self,upload,basketId,username,serverport="8080"): + """set start values for the thread""" self.result="" self.upload=upload self.basketId=basketId @@ -158,11 +182,12 @@ class uploadATFThread(Thread): self.serverport=serverport def __call__(self): - """wait""" + """call method """ self.run() return True def getContext(self, app,serverport="8080"): + """get the context within the ZODB""" resp = HTTPResponse(stdout=None) env = { 'SERVER_NAME':'localhost', @@ -175,6 +200,7 @@ class uploadATFThread(Thread): def run(self): self.result="" + #find context within ZODB from Zope import DB conn = DB.open() root = conn.root() @@ -186,9 +212,10 @@ class uploadATFThread(Thread): pass get_transaction().abort() conn.close() - + print "done" def getResult(self): + """method for accessing result""" return self.result def uploadATFThread(self,ctx,upload,basketId=0): @@ -196,22 +223,33 @@ class uploadATFThread(Thread): #TODO: add comments #TODO: finish uploadATF self.result="I am checking now the files
" - + + #start to check the files for fn in os.listdir(dir): self.result+="check:%s
"%fn + # check if file is in the catalog + #TODO: checkCatalog is not implemented yet if ctx2.cdli_main.checkCatalog(fn): psNotInCatalog.append(fn) - + #check if p-file already at the server founds=ctx2.CDLICatalog.search({'title':fn}) + #if not than add filename to the list of newfiles if len(founds)==0: newPs.append(fn) - + + #if p file alread at the server for found in founds: + #analyse the differences to the actual file obj=found.getObject() if (not obj.lockedBy=='') and (not obj.lockedBy==self.username): @@ -247,7 +291,7 @@ class uploadATFThread(Thread): changed.append((obj,diffs)) #hochladen - + #ready, set the returnValues self.result+="