--- cdli/cdli_files.py 2007/02/05 16:20:38 1.64 +++ cdli/cdli_files.py 2007/03/19 18:34:01 1.67 @@ -25,6 +25,7 @@ from BTrees.OOBTree import OOBTree import logging import transaction import copy +import codecs def unique(s): """Return a list of the elements in s, but without duplicates. @@ -174,8 +175,8 @@ class uploadATFfinallyThread(Thread): conn.close() #set flag for end of this method self.end=True - logging.info("ended") - return True + logging.info("ended") + return True def __del__(self): """delete""" @@ -196,7 +197,7 @@ class uploadATFfinallyThread(Thread): #shall I only upload the changed files? if procedure=="uploadchanged": - changed=[x[0] for x in SESSION.get('changed',[])] + changed=[x[0] for x in SESSION.get('changed',[])] uploadFns=changed+SESSION.get('newPs',[]) #or all @@ -213,53 +214,64 @@ class uploadATFfinallyThread(Thread): uploadFns=[] #do first the changed files - i=0 + i=0 for fn in uploadFns: - i+=1 + i+=1 founds=ctx2.CDLICatalog.search({'title':fn}) if len(founds)>0: SESSION['author']=str(username) self.result="
Changing : %s"%fn+self.result founds[0].getObject().manage_addCDLIFileObject('',comment,SESSION['author'],file=os.path.join(SESSION['tmpdir'],fn),from_tmp=True) if i==200: - i=0 - transaction.get().commit() - logging.info("changing: do commit") - transaction.get().commit() - logging.info("changing: last commit") + i=0 + transaction.get().commit() + logging.info("changing: do commit") + + transaction.get().commit() + logging.info("changing: last commit") #now add the new files newPs=SESSION['newPs'] if len(newPs)>0: tmpDir=SESSION['tmpdir'] + logging.info("adding start") self.result="
Adding files
"+self.result #TODO: make this configurable, at the moment base folder for the files has to be cdli_main ctx2.importFiles(comment=comment,author=str(username) ,folderName=tmpDir, files=newPs,ext=self) - + logging.info("adding finished") #unlock locked files? if unlock: + logging.info("unlocking start") self.result="Unlock files
"+self.result unlockFns=[] for x in os.listdir(SESSION['tmpdir']): if not x in SESSION['errors']: unlockFns.append(x) - + logging.info("unlocking have now what to unlock") + for fn in unlockFns: + #logging.info("will unlock: %s"%fn) founds=ctx2.CDLICatalog.search({'title':fn}) + #logging.info("found it: %s"%repr(founds)) if len(founds)>0: + #logging.info("unlock: %s"%founds[0].getObject().getId()) SESSION['author']=str(username) founds[0].getObject().lockedBy="" + logging.info("unlocking done") - #if a basketname is give, add files to the basket + #if a basketname is given, add files to the basket if not (basketname ==''): - self.result="Add basket
"+self.result + logging.info("add to basket %s"%basketname) + self.result="Add to basket
"+self.result basketId=ctx2.basketContainer.getBasketIdfromName(basketname) if not basketId: # create new basket + logging.info("create basket %s"%basketname) + self.result="Create a new basket
"+self.result ob=ctx2.basketContainer.addBasket(basketname) basketId=ob.getId() basket=getattr(ctx2.basketContainer,str(basketId)) @@ -270,7 +282,7 @@ class uploadATFfinallyThread(Thread): RESPONSE.redirect(self.aq_parent.absolute_url()) - + logging.info("uploadfinally done") return True class tmpStore(SimpleItem): @@ -338,7 +350,7 @@ class uploadATFThread(Thread): #ctx.cdliRoot.cdli_main.tmpStore2[self.getName()[0:]]=self.returnValue - + transaction.get().commit() conn.close() @@ -561,7 +573,7 @@ class CDLIBasketContainer(OrderedFolder) ret+= "BASKET:"+com+"\t"+user+"\t"+time+"\n" for x in values: ret+= x[0]+"\t"+x[1]+"\n" - return ret + return ret def getBaskets(self,sortField='title'): """get all baskets files""" @@ -636,11 +648,11 @@ class CDLIBasketContainer(OrderedFolder) def setActiveBasket(self,basketId,REQUEST=None): """store active basketId in a cookie""" self.REQUEST.RESPONSE.setCookie("CDLIActiveBasket",basketId,path="/") - try: - qs=cgi.parse_qs(REQUEST['QUERY_STRING']) - del(qs['basketId']) - except: - qs={} + try: + qs=cgi.parse_qs(REQUEST['QUERY_STRING']) + del(qs['basketId']) + except: + qs={} if REQUEST: REQUEST.RESPONSE.redirect(REQUEST['URL1']+'?'+urllib.urlencode(qs)) @@ -832,7 +844,7 @@ class CDLIBasket(Folder,CatalogAware): def addObjects(self,ids,deleteOld=None,username=None): """generate a new version of the basket with objects added""" - + logging.info("add to basket (%s)"%(self.getId())) lastVersion=self.getLastVersion() if lastVersion is None: @@ -846,10 +858,11 @@ class CDLIBasket(Folder,CatalogAware): newContent=[] added=0 for id in ids: - try: - founds=self.CDLICatalog.search({'title':id}) - except: - founds=[] + try: + founds=self.CDLICatalog.search({'title':id}) + except: + founds=[] + for found in founds: if found.getObject() not in oldContent: #TODO: was passiert wenn, man eine Object dazufgt, das schon da ist aber eine neuere version @@ -863,7 +876,7 @@ class CDLIBasket(Folder,CatalogAware): user = username ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=content) - + logging.info("add to basket (%s) done"%(self.getId())) return added @@ -1437,40 +1450,42 @@ def splitatf(fh,dir=None,ext=None): i=0 for lineTmp in fh.readlines(): - for line in lineTmp.split("\r"): - if ext: - i+=1 - if (i%100)==0: - ext.result+="." - if i==10000: - i=0 - ext.result+="adding: %s
"%f + ext.result="adding: %s
"%f+ext.result if not obj: manage_addCDLIFileFolder(root,folder,folder) fobj=getattr(root,folder) @@ -2180,13 +2211,13 @@ class CDLIRoot(Folder): self.CDLICatalog.catalog_object(ob) #self.CDLICatalog.manage_catalogFoundItems(obj_ids=[id],search_sub=1) #self.CDLICatalog.manage_catalogObject(self.REQUEST, self.REQUEST.RESPONSE, 'CDLICatalog', urlparse.urlparse(ob.absolute_url())[1]) - count+=1 + count+=1 - if count > 1000: - print "committing" - transaction.get().commit() - count=0 - transaction.get().commit() + if count > 1000: + print "committing" + transaction.get().commit() + count=0 + transaction.get().commit() return "ok" @@ -2207,9 +2238,9 @@ def manage_addCDLIRoot(self, id, title=' ob.id=str(id) ob.title=title try: - self._setObject(id, ob) + self._setObject(id, ob) except: - pass + pass ob=self._getOb(id) checkPermission=getSecurityManager().checkPermission