Diff for /cdli/cdli_files.py between versions 1.63 and 1.69

version 1.63, 2007/02/05 15:23:46 version 1.69, 2007/03/20 10:49:15
Line 25  from BTrees.OOBTree import OOBTree Line 25  from BTrees.OOBTree import OOBTree
 import logging  import logging
 import transaction  import transaction
 import copy  import copy
   import codecs
   
 def unique(s):  def unique(s):
     """Return a list of the elements in s, but without duplicates.      """Return a list of the elements in s, but without duplicates.
Line 225  class uploadATFfinallyThread(Thread): Line 226  class uploadATFfinallyThread(Thread):
             i=0              i=0
                 transaction.get().commit()                  transaction.get().commit()
                     logging.info("changing: do commit")                      logging.info("changing: do commit")
           
     transaction.get().commit()      transaction.get().commit()
     logging.info("changing: last commit")      logging.info("changing: last commit")
   
Line 232  class uploadATFfinallyThread(Thread): Line 234  class uploadATFfinallyThread(Thread):
         newPs=SESSION['newPs']          newPs=SESSION['newPs']
         if len(newPs)>0:          if len(newPs)>0:
             tmpDir=SESSION['tmpdir']              tmpDir=SESSION['tmpdir']
               logging.info("adding start")
             self.result="<p>Adding files</p>"+self.result              self.result="<p>Adding files</p>"+self.result
             #TODO: make this configurable, at the moment base folder for the files has to be cdli_main              #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)              ctx2.importFiles(comment=comment,author=str(username) ,folderName=tmpDir, files=newPs,ext=self)
                               logging.info("adding finished")
                   
                   
         #unlock locked files?          #unlock locked files?
         if unlock:          if unlock:
               logging.info("unlocking start")
             self.result="<p>Unlock files</p>"+self.result              self.result="<p>Unlock files</p>"+self.result
             unlockFns=[]              unlockFns=[]
             for x in os.listdir(SESSION['tmpdir']):              for x in os.listdir(SESSION['tmpdir']):
                     if not x in SESSION['errors']:                      if not x in SESSION['errors']:
                         unlockFns.append(x)                          unlockFns.append(x)
               logging.info("unlocking have now what to unlock")
                           
             for fn in unlockFns:              for fn in unlockFns:
                   #logging.info("will unlock: %s"%fn)
                 founds=ctx2.CDLICatalog.search({'title':fn})                  founds=ctx2.CDLICatalog.search({'title':fn})
                   #logging.info("found it: %s"%repr(founds))
                 if len(founds)>0:                  if len(founds)>0:
                       #logging.info("unlock: %s"%founds[0].getObject().getId())
                     SESSION['author']=str(username)                      SESSION['author']=str(username)
                                         
                     founds[0].getObject().lockedBy=""                      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 ==''):          if not (basketname ==''):
             self.result="<p>Add basket</p>"+self.result              logging.info("add to basket %s"%basketname)
               self.result="<p>Add to basket</p>"+self.result
             basketId=ctx2.basketContainer.getBasketIdfromName(basketname)              basketId=ctx2.basketContainer.getBasketIdfromName(basketname)
                           
             if not basketId: # create new basket              if not basketId: # create new basket
                   logging.info("create basket %s"%basketname)
                   self.result="<p>Create a new basket</p>"+self.result
                 ob=ctx2.basketContainer.addBasket(basketname)                  ob=ctx2.basketContainer.addBasket(basketname)
                 basketId=ob.getId()                  basketId=ob.getId()
             basket=getattr(ctx2.basketContainer,str(basketId))              basket=getattr(ctx2.basketContainer,str(basketId))
Line 270  class uploadATFfinallyThread(Thread): Line 282  class uploadATFfinallyThread(Thread):
             RESPONSE.redirect(self.aq_parent.absolute_url())              RESPONSE.redirect(self.aq_parent.absolute_url())
                   
   
                  logging.info("uploadfinally done")
         return True          return True
   
 class tmpStore(SimpleItem):  class tmpStore(SimpleItem):
Line 413  class uploadATFThread(Thread): Line 425  class uploadATFThread(Thread):
             #if not than add filename to the list of newfiles              #if not than add filename to the list of newfiles
                           
             data=file(os.path.join(dir,fn)).read()              data=file(os.path.join(dir,fn)).read()
             #status,msg=checkFile(fn,data,dir)              status,msg=checkFile(fn,data,dir)
             status=True              #status=True
             msg=""              
               
             if not status: # error              if not status: # error
                 errors.append((fn,msg))                  errors.append((fn,msg))
               
             else:              else:
                 if len(founds)==0:                  if len(founds)==0:
                     newPs.append(fn)                      newPs.append(fn)
Line 832  class CDLIBasket(Folder,CatalogAware): Line 846  class CDLIBasket(Folder,CatalogAware):
           
     def addObjects(self,ids,deleteOld=None,username=None):      def addObjects(self,ids,deleteOld=None,username=None):
         """generate a new version of the basket with objects added"""          """generate a new version of the basket with objects added"""
                  logging.info("add to basket (%s)"%(self.getId()))
         lastVersion=self.getLastVersion()          lastVersion=self.getLastVersion()
                   
         if lastVersion is None:          if lastVersion is None:
Line 850  class CDLIBasket(Folder,CatalogAware): Line 864  class CDLIBasket(Folder,CatalogAware):
         founds=self.CDLICatalog.search({'title':id})          founds=self.CDLICatalog.search({'title':id})
         except:          except:
         founds=[]          founds=[]
              
             for found in founds:              for found in founds:
                 if found.getObject() not in oldContent:                  if found.getObject() not in oldContent:
                     #TODO: was passiert wenn, man eine Object dazufŸgt, das schon da ist aber eine neuere version                      #TODO: was passiert wenn, man eine Object dazufŸgt, das schon da ist aber eine neuere version
Line 863  class CDLIBasket(Folder,CatalogAware): Line 878  class CDLIBasket(Folder,CatalogAware):
             user = username              user = username
                           
         ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=content)          ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=content)
               logging.info("add to basket (%s) done"%(self.getId()))
         return added          return added
           
           
Line 1157  class CDLIFileObject(CatalogAware,extVer Line 1172  class CDLIFileObject(CatalogAware,extVer
                   
                   
         newversion=parent.manage_addCDLIFileObject('',comment,author)          newversion=parent.manage_addCDLIFileObject('',comment,author)
         newversion.data=self.data[0:]          newversion.manage_upload(self.getData())
                                                                                   
         if RESPONSE is not None:          if RESPONSE is not None:
             RESPONSE.redirect(self.aq_parent.absolute_url()+'/history')              RESPONSE.redirect(self.aq_parent.absolute_url()+'/history')
Line 1407  def manage_addCDLIFile(self,id,title,loc Line 1422  def manage_addCDLIFile(self,id,title,loc
     if RESPONSE is not None:      if RESPONSE is not None:
         RESPONSE.redirect('manage_main')          RESPONSE.redirect('manage_main')
   
   def checkUTF8(data):
       """check utf 8"""
       try:
           data.encode('utf-8')
           return True
       except:
           return False
   
   
 def checkFile(filename,data,folder):  def checkFile(filename,data,folder):
Line 1418  def checkFile(filename,data,folder): Line 1440  def checkFile(filename,data,folder):
         return False,"P missing in the filename"          return False,"P missing in the filename"
     elif len(fn[0])!=7:      elif len(fn[0])!=7:
         return False,"P number has not the right length 6"          return False,"P number has not the right length 6"
     else:      elif not checkUTF8(data):
         fn=os.path.join(folder,filename)          return False,"not utf-8"
         stin,out=os.popen4("/usr/bin/atfcheck.plx %s"%fn)  
         value=out.read()  
         ret= out.close()  
   
         if value:  
        
             return False,"atf checker error: %s"%value  
         else:          else:
             return True,""              return True,""
           
   #    else:
   #        fn=os.path.join(folder,filename)
   #        stin,out=os.popen4("/usr/bin/atfcheck.plx %s"%fn)
   #        value=out.read()
   #        ret= out.close()
   #
   #        if value:
   #     
   #            return False,"atf checker error: %s"%value
   #        else:
   #            return True,""
       
 def splitatf(fh,dir=None,ext=None):  def splitatf(fh,dir=None,ext=None):
     """split it"""      """split it"""
     ret=None      ret=None
Line 1437  def splitatf(fh,dir=None,ext=None): Line 1464  def splitatf(fh,dir=None,ext=None):
     i=0      i=0
   
     for lineTmp in fh.readlines():      for lineTmp in fh.readlines():
           lineTmp=lineTmp.replace(codecs.BOM_UTF8,'') # make sure that all BOM are removed..
     for line in lineTmp.split("\r"):      for line in lineTmp.split("\r"):
               #logging.log("Deal with: %s"%line)
         if ext:          if ext:
         i+=1          i+=1
         if (i%100)==0:          if (i%100)==0:
Line 1522  class CDLIFileFolder(extVersionedFileFol Line 1551  class CDLIFileFolder(extVersionedFileFol
                   
         return ret          return ret
           
       def getFile(self,fn):
           """get the content of the file fn"""
           founds=self.CDLICatalog.search({'title':fn})
           if not founds:
               return []
           else:
               obj=founds[0].getObject().getLastVersion()
   
               return obj.getData()[0:] 
       
     def checkCatalog(self,fn):      def checkCatalog(self,fn):
         """check if fn is in the catalog"""          """check if fn is in the catalog"""
         #TODO add checkCatalog          #TODO add checkCatalog
Line 1544  class CDLIFileFolder(extVersionedFileFol Line 1583  class CDLIFileFolder(extVersionedFileFol
         return pt(search=list,author=author)          return pt(search=list,author=author)
           
           
       def getAllPNumbers(self):
           """get a list of all files (resp their p-numbers) stored"""
           
           ret=[x.getId for x in  self.CDLICatalog()]
        
           return ret
                           
     def findObjectsFromList(self,enterList=None,display=False,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None):      def findObjectsFromList(self,enterList=None,display=False,start=None,upload=None,list=None,basketName=None,numberOfObjects=None,RESPONSE=None):
         """findObjectsFromList (, TAB oder LINE separated)"""          """findObjectsFromList (, TAB oder LINE separated)"""
Line 1993  class CDLIRoot(Folder): Line 2038  class CDLIRoot(Folder):
                                                                                         
           
     def uploadATF(self,repeat=None,upload=None,basketId=0,RESPONSE=None):      def uploadATF(self,repeat=None,upload=None,basketId=0,RESPONSE=None):
         """standard ausgabe"""          """upload an atf file / basket file"""
         #self._v_uploadATF.returnValue=None          #self._v_uploadATF.returnValue=None
         from random import randint          from random import randint
         if (not self.REQUEST.SESSION.get('idTmp',None)):          if (not self.REQUEST.SESSION.get('idTmp',None)):
Line 2152  class CDLIRoot(Folder): Line 2197  class CDLIRoot(Folder):
             obj=self.ZopeFind(root,obj_ids=[folder])              obj=self.ZopeFind(root,obj_ids=[folder])
             if ext:              if ext:
       
                 ext.result+="<p>adding: %s </p>"%f                  ext.result="<p>adding: %s </p>"%f+ext.result
             if not obj:              if not obj:
                 manage_addCDLIFileFolder(root,folder,folder)                  manage_addCDLIFileFolder(root,folder,folder)
                 fobj=getattr(root,folder)                  fobj=getattr(root,folder)

Removed from v.1.63  
changed lines
  Added in v.1.69


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>