version 1.1, 2011/07/19 12:43:26
|
version 1.2, 2011/07/20 09:33:34
|
Line 11 from Products.cdli.cdli_files import CDL
|
Line 11 from Products.cdli.cdli_files import CDL
|
import sys |
import sys |
import os |
import os |
import os.path |
import os.path |
|
import transaction |
|
|
class uploadATFfinallyThread: |
class uploadATFfinallyThread: |
"""class for adding uploaded filed (temporarily stored in the staging area at /tmp""" |
"""class for adding uploaded filed (temporarily stored in the staging area at /tmp""" |
Line 19 class uploadATFfinallyThread:
|
Line 20 class uploadATFfinallyThread:
|
"""init for uploadATFfinallyThread""" |
"""init for uploadATFfinallyThread""" |
logging.getLogger().setLevel(logging.DEBUG) |
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""" |
"""set start values for the thread""" |
|
|
self.result=file("/tmp/"+str(basketname)+".out","w") |
self.result=file("/tmp/"+str(basketname)+".out","w") |
Line 36 class uploadATFfinallyThread:
|
Line 37 class uploadATFfinallyThread:
|
self.run() |
self.run() |
return True |
return True |
|
|
def getContext(self, app,serverport="8080"): |
def getContext(self, app,serverport="29080"): |
"""get the context within the ZODB""" |
"""get the context within the ZODB""" |
|
|
resp = HTTPResponse(stdout=None) |
resp = HTTPResponse(stdout=None) |
Line 98 class uploadATFfinallyThread:
|
Line 99 class uploadATFfinallyThread:
|
errorFn = [x[0] for x in tmp['errors']] |
errorFn = [x[0] for x in tmp['errors']] |
#shall I only upload the changed files? |
#shall I only upload the changed files? |
logging.debug("uploadATFfinally procedure: %s"%procedure) |
logging.debug("uploadATFfinally procedure: %s"%procedure) |
if procedure=="uploadchanged": |
if procedure.lower()=="uploadchanged": |
changedTmp=[x[0] for x in tmp.get('changed',[])] |
changedTmp=[x[0] for x in tmp.get('changed',[])] |
uploadFns=[] |
uploadFns=[] |
|
|
Line 107 class uploadATFfinallyThread:
|
Line 108 class uploadATFfinallyThread:
|
if (not x in tmp['lockerrors']) and ( not x in errorFn): |
if (not x in tmp['lockerrors']) and ( not x in errorFn): |
uploadFns.append(x) |
uploadFns.append(x) |
#or all |
#or all |
elif procedure=="uploadAll": |
elif procedure.lower()=="uploadall": |
uploadFns=[] |
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): |
if (not x in tmp['lockerrors']) and ( not x in errorFn): |
uploadFns.append(x) |
uploadFns.append(x) |
|
|
Line 135 class uploadATFfinallyThread:
|
Line 145 class uploadATFfinallyThread:
|
logging.debug("uploadatffinallythread changing:%s"%fn) |
logging.debug("uploadatffinallythread changing:%s"%fn) |
founds[0].getObject().manage_addCDLIFileObject('',comment,tmp['author'],file=os.path.join(tmp['tmpdir'],fn),from_tmp=True) |
founds[0].getObject().manage_addCDLIFileObject('',comment,tmp['author'],file=os.path.join(tmp['tmpdir'],fn),from_tmp=True) |
if i%200==0: |
if i%200==0: |
#transaction.get().commit() |
transaction.get().commit() |
#logging.debug("uploadatffinallythread changing: do commit") |
logging.debug("uploadatffinallythread changing: do commit") |
self.result.flush() |
self.result.flush() |
|
|
|
|
Line 156 class uploadATFfinallyThread:
|
Line 166 class uploadATFfinallyThread:
|
logging.debug("uploadatffinallythread unlocking start") |
logging.debug("uploadatffinallythread unlocking start") |
self.result.write("<p>Unlock files</p>\n") |
self.result.write("<p>Unlock files</p>\n") |
unlockFns=[] |
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: |
if not x in errorFn: |
unlockFns.append(x) |
unlockFns.append(x) |
|
|
Line 204 class uploadATFfinallyThread:
|
Line 224 class uploadATFfinallyThread:
|
|
|
basket.addObjects(addIds,deleteOld=True,username=str(username)) |
basket.addObjects(addIds,deleteOld=True,username=str(username)) |
|
|
|
transaction.get().commit() |
logging.debug("uploadatffinallythread uploadfinally done") |
logging.debug("uploadatffinallythread uploadfinally done") |
|
|
|
|