--- cdli/tools/uploadATFAsyncFinally.py 2011/07/19 12:43:26 1.1 +++ cdli/tools/uploadATFAsyncFinally.py 2011/07/20 09:33:34 1.2 @@ -11,6 +11,7 @@ from Products.cdli.cdli_files import CDL import sys import os import os.path +import transaction class uploadATFfinallyThread: """class for adding uploaded filed (temporarily stored in the staging area at /tmp""" @@ -19,7 +20,7 @@ class uploadATFfinallyThread: """init for uploadATFfinallyThread""" logging.getLogger().setLevel(logging.DEBUG) - def set(self,procedure,uploadId,comment="",basketname='',unlock=None,username=None,serverport="8080"): + def set(self,procedure,uploadId,comment="",basketname='',unlock=None,username=None,serverport="29080"): """set start values for the thread""" self.result=file("/tmp/"+str(basketname)+".out","w") @@ -36,7 +37,7 @@ class uploadATFfinallyThread: self.run() return True - def getContext(self, app,serverport="8080"): + def getContext(self, app,serverport="29080"): """get the context within the ZODB""" resp = HTTPResponse(stdout=None) @@ -98,7 +99,7 @@ class uploadATFfinallyThread: errorFn = [x[0] for x in tmp['errors']] #shall I only upload the changed files? logging.debug("uploadATFfinally procedure: %s"%procedure) - if procedure=="uploadchanged": + if procedure.lower()=="uploadchanged": changedTmp=[x[0] for x in tmp.get('changed',[])] uploadFns=[] @@ -107,9 +108,18 @@ class uploadATFfinallyThread: if (not x in tmp['lockerrors']) and ( not x in errorFn): uploadFns.append(x) #or all - elif procedure=="uploadAll": + elif procedure.lower()=="uploadall": uploadFns=[] - for x in os.listdir(tmp['tmpdir']): + #workaround fuer memory fehler in listdir + #http://stackoverflow.com/questions/4098831/workaround-oserror-with-os-listdir + dirTmp=tmp['tmpdir'] + ids = os.popen4('find %s' % dirTmp)[1].read().rstrip().split('\n') + ids.remove(dirTmp) + n = len(dirTmp) + if dirTmp[-1] != os.path.sep: + n += 1 + ids = [f[n:] for f in ids] # remove dir prefix + for x in ids: if (not x in tmp['lockerrors']) and ( not x in errorFn): uploadFns.append(x) @@ -135,8 +145,8 @@ class uploadATFfinallyThread: logging.debug("uploadatffinallythread changing:%s"%fn) founds[0].getObject().manage_addCDLIFileObject('',comment,tmp['author'],file=os.path.join(tmp['tmpdir'],fn),from_tmp=True) if i%200==0: - #transaction.get().commit() - #logging.debug("uploadatffinallythread changing: do commit") + transaction.get().commit() + logging.debug("uploadatffinallythread changing: do commit") self.result.flush() @@ -156,7 +166,17 @@ class uploadATFfinallyThread: logging.debug("uploadatffinallythread unlocking start") self.result.write("

Unlock files

\n") unlockFns=[] - for x in os.listdir(tmp['tmpdir']): + + #workaround fuer memory fehler in listdir + #http://stackoverflow.com/questions/4098831/workaround-oserror-with-os-listdir + dirTmp=tmp['tmpdir'] + ids = os.popen4('find %s' % dirTmp)[1].read().rstrip().split('\n') + ids.remove(dirTmp) + n = len(dirTmp) + if dirTmp[-1] != os.path.sep: + n += 1 + ids = [f[n:] for f in ids] # remove dir prefix + for x in ids: if not x in errorFn: unlockFns.append(x) @@ -203,7 +223,8 @@ class uploadATFfinallyThread: addIds.append(id) basket.addObjects(addIds,deleteOld=True,username=str(username)) - + + transaction.get().commit() logging.debug("uploadatffinallythread uploadfinally done")