Diff for /cdli/cdli_files.py between versions 1.73 and 1.80.2.4

version 1.73, 2007/03/23 13:58:10 version 1.80.2.4, 2007/10/24 20:36:07
Line 26  import logging Line 26  import logging
 import transaction  import transaction
 import copy  import copy
 import codecs  import codecs
   import sys
   
   import cdliSplitter
   
   
   def unicodify(s):
       """decode str (utf-8 or latin-1 representation) into unicode object"""
       if not s:
           return u""
       if isinstance(s, str):
           try:
               return s.decode('utf-8')
           except:
               return s.decode('latin-1')
       else:
           return s
   
   def utf8ify(s):
       """encode unicode object or string into byte string in utf-8 representation.
          assumes string objects to be utf-8"""
       if not s:
           return ""
       if isinstance(s, str):
           return s
       else:
           return s.encode('utf-8')
   
   def formatAtfLineHtml(l, nolemma=True):
       """escape special ATF characters for HTML"""
       if not l:
           return ""
   
       if nolemma:
           # ignore lemma lines
           if l.lstrip().startswith('#lem:'):
               return ""
       # replace &
       l = l.replace('&','&')
       # replace angular brackets
       l = l.replace('<','&lt;')
       l = l.replace('>','&gt;')
       return l
   
   
 def generateXMLReturn(hash):  def generateXMLReturn(hash):
     """erzeugt das xml file als returnwert fuer uploadATFRPC"""      """erzeugt das xml file als returnwert fuer uploadATFRPC"""
Line 530  class CDLIBasketContainer(OrderedFolder) Line 573  class CDLIBasketContainer(OrderedFolder)
                   
         return ret          return ret
           
       security.declareProtected('manage','getBasketAsOneFile')       
     def getBasketAsOneFile(self,basketName,current="no"):      def getBasketAsOneFile(self,basketName,current="no"):
         """returns all files of the basket combined in one file          """returns all files of the basket combined in one file
         @param basketName: Name of the basket          @param basketName: Name of the basket
Line 553  class CDLIBasketContainer(OrderedFolder) Line 597  class CDLIBasketContainer(OrderedFolder)
                                 ret+=str(founds[0].getObject().getLastVersion().getData())+"\n"                                  ret+=str(founds[0].getObject().getLastVersion().getData())+"\n"
         return ret          return ret
           
       security.declareProtected('manage','upDateBaskets') 
     def upDateBaskets(self):      def upDateBaskets(self):
         """update content in to objects"""          """update content in to objects"""
                   
Line 623  class CDLIBasketContainer(OrderedFolder) Line 668  class CDLIBasketContainer(OrderedFolder)
         return pt(basketId=basketId,basketName=basketName)          return pt(basketId=basketId,basketName=basketName)
         
   
     security.declareProtected('View','index_html')          security.declareProtected('manage','index_html')    
     def index_html(self):      def index_html(self):
         """stanadard ansicht"""          """stanadard ansicht"""
                   
Line 827  class CDLIBasketContainer(OrderedFolder) Line 872  class CDLIBasketContainer(OrderedFolder)
         """get name of the actualuser"""          """get name of the actualuser"""
         return str(self.REQUEST['AUTHENTICATED_USER'])          return str(self.REQUEST['AUTHENTICATED_USER'])
           
           security.declareProtected('manage','addBasket') 
     def addBasket(self,newBasketName):      def addBasket(self,newBasketName):
         """add a new basket"""          """add a new basket"""
                   
Line 883  class CDLIBasket(Folder,CatalogAware): Line 928  class CDLIBasket(Folder,CatalogAware):
     meta_type="CDLIBasket"      meta_type="CDLIBasket"
     default_catalog="CDLIBasketCatalog"      default_catalog="CDLIBasketCatalog"
           
       def searchInBasket(self,indexName,searchStr,regExp=False):
           """searchInBasket"""
   
           lst=self.searchInLineIndexDocs(indexName,searchStr,uniq=True,regExp=regExp) #TODO: fix this
           ret={}
           
           lv=self.getLastVersion()
   
   
           for obj in lv.content.getContent():
               id=obj[1].getId().split(".")[0]
               if id in lst:
           
                   ret[id]=self.showWordInFile(id,searchStr,lineList=self.getLinesFromIndex(indexName,searchStr,id,regExp=regExp),regExp=regExp,indexName=indexName)
           
           
           pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','searchResultsInBasket')).__of__(self)
           return pt(result=ret,indexName=indexName,regExp=regExp,word=searchStr)
           
            
    
           
       def searchInBasket_v1(self,searchStr):
           """search occurences of searchStr in files im basket"""
           ret=[]
           lv=self.getLastVersion()
           logging.info("searching")
           for obj in lv.content.getContent():
               txt=obj[0].getData()
               for x in txt.split("\n"):
                   logging.info("search %s"%x)
                   if re.match(searchStr,x):
                       ret.append(x)
           
           return "\n".join(ret)
                   
   
     def getFile(self,obj):      def getFile(self,obj):
         return obj[1]          return obj[1]
Line 1204  class CDLIBasketVersion(Implicit,Persist Line 1285  class CDLIBasketVersion(Implicit,Persist
         self.REQUEST.RESPONSE.setHeader("Content-Length",length)          self.REQUEST.RESPONSE.setHeader("Content-Length",length)
         self.REQUEST.RESPONSE.write(ret)              self.REQUEST.RESPONSE.write(ret)    
                   
     security.declareProtected('View','downloadObjectsAsOneFile')      security.declareProtected('manage','downloadObjectsAsOneFile')
     def downloadObjectsAsOneFile(self,lock=None,procedure=None,REQUEST=None,check="yes",current="no"):      def downloadObjectsAsOneFile(self,lock=None,procedure=None,REQUEST=None,check="yes",current="no"):
         """download all selected files in one file"""          """download all selected files in one file"""
                   
Line 1322  class CDLIBasketVersion(Implicit,Persist Line 1403  class CDLIBasketVersion(Implicit,Persist
     def __init__(self,id,user,comment="",basketContent=[]):      def __init__(self,id,user,comment="",basketContent=[]):
         """ init a basket version"""          """ init a basket version"""
         self.id=id          self.id=id
         self.coment=comment          self.comment=comment
         self._setObject('content',BasketContent(basketContent))          self._setObject('content',BasketContent(basketContent))
         #self.basketContent=basketContent[0:]a          #self.basketContent=basketContent[0:]a
         self.user=user          self.user=user
Line 1336  class CDLIBasketVersion(Implicit,Persist Line 1417  class CDLIBasketVersion(Implicit,Persist
         """get Comment"""          """get Comment"""
         return self.comment          return self.comment
     
     security.declareProtected('View','index_html')      security.declareProtected('manage','index_html')
     def index_html(self):      def index_html(self):
             """view the basket"""              """view the basket"""
   
Line 1388  class CDLIFileObject(CatalogAware,extVer Line 1469  class CDLIFileObject(CatalogAware,extVer
           
     security=ClassSecurityInfo()      security=ClassSecurityInfo()
           
        security.declareProtected('manage','index_html')
     security.declarePublic('makeThisVersionCurrent')  
           
     def PrincipiaSearchSource(self):      def PrincipiaSearchSource(self):
            """Return cataloguable key for ourselves."""             """Return cataloguable key for ourselves."""
Line 1400  class CDLIFileObject(CatalogAware,extVer Line 1480  class CDLIFileObject(CatalogAware,extVer
                   
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','makeThisVersionCurrent.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','makeThisVersionCurrent.zpt')).__of__(self)
         return pt()                           return pt()                 
   
       security.declarePublic('makeThisVersionCurrent')
     def makeThisVersionCurrent(self,comment,author,RESPONSE=None):      def makeThisVersionCurrent(self,comment,author,RESPONSE=None):
         """copy this version to current"""          """copy this version to current"""
         parent=self.aq_parent          parent=self.aq_parent
           
           
         newversion=parent.manage_addCDLIFileObject('',comment,author)          newversion=parent.manage_addCDLIFileObject('',comment,author)
         newversion.manage_upload(self.getData())          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')
   
   
         return True          return True
           
     security.declarePublic('view')  
    
     def getFormattedData(self):      def getFormattedData(self):
         """fromat text"""          """fromat text"""
         data=self.getData()          data=self.getData()
 #        return re.sub("\s\#lem"," #lem",data) #remove return vor #lem  #        return re.sub("\s\#lem"," #lem",data) #remove return vor #lem
         return re.sub("#lem","       #lem",data) #remove return vor #lem          return re.sub("#lem","       #lem",data) #remove return vor #lem
                   
       security.declarePublic('view')
     def view(self):      def view(self):
         """view file"""          """view file"""
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','viewCDLIFile.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','viewCDLIFile.zpt')).__of__(self)
Line 1457  class CDLIFileObject(CatalogAware,extVer Line 1535  class CDLIFileObject(CatalogAware,extVer
                   
 manage_addCDLIFileObjectForm=DTMLFile('dtml/fileAdd', globals(),Kind='CDLIFileObject',kind='CDLIFileObject', version='1')  manage_addCDLIFileObjectForm=DTMLFile('dtml/fileAdd', globals(),Kind='CDLIFileObject',kind='CDLIFileObject', version='1')
   
 def manage_addCDLIFileObject(self,id,vC='',author='', file='',title='',precondition='', content_type='',  def manage_addCDLIFileObject(self,id,vC='',author='', file='',title='',versionNumber=0,
                                precondition='', content_type='',
                              from_tmp=False,REQUEST=None):                               from_tmp=False,REQUEST=None):
     """Add a new File object.      """Add a new File object.
   
     Creates a new File object 'id' with the contents of 'file'"""      Creates a new File object 'id' with the contents of 'file'"""
     
     id=str(id)      id=str(id)
Line 1473  def manage_addCDLIFileObject(self,id,vC= Line 1551  def manage_addCDLIFileObject(self,id,vC=
     self=self.this()      self=self.this()
   
     # First, we create the file without data:      # First, we create the file without data:
     self._setObject(id, CDLIFileObject(id,title,'',content_type, precondition))      self._setObject(id, CDLIFileObject(id,title,versionNumber=versionNumber,versionComment=vC,time=time.localtime(),author=author))
     self._getOb(id).versionComment=str(vC)      fob = self._getOb(id)
     self._getOb(id).time=time.localtime()  
       
     setattr(self._getOb(id),'author',author)  
       
           
     # Now we "upload" the data.  By doing this in two steps, we      # Now we "upload" the data.  By doing this in two steps, we
     # can use a database trick to make the upload more efficient.      # can use a database trick to make the upload more efficient.
   
     if file and not from_tmp:      if file and not from_tmp:
         self._getOb(id).manage_upload(file)          fob.manage_upload(file)
     elif file and from_tmp:      elif file and from_tmp:
         self._getOb(id).manage_upload_from_tmp(file)          fob.manage_file_upload(file) # manage_upload_from_tmp doesn't exist in ExtFile2
       #    fob.manage_upload_from_tmp(file) # manage_upload_from_tmp doesn't exist in ExtFile2
     if content_type:      if content_type:
         self._getOb(id).content_type=content_type          fob.content_type=content_type
   
       logging.debug("manage_add: lastversion=%s"%self.getData())
       logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog)))
     self.reindex_object()      self.reindex_object()
     self._getOb(id).reindex_object()      logging.debug("manage_add: fob_data=%s"%fob.getData())
       logging.debug("reindex2: %s in %s"%(repr(fob), repr(fob.default_catalog)))
       fob.index_object()
   
     if REQUEST is not None:      if REQUEST is not None:
         REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')          REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
           
   
 class CDLIFile(extVersionedFile,CatalogAware):  class CDLIFile(extVersionedFile,CatalogAware):
     """CDLI file"""      """CDLI file"""
           
       security=ClassSecurityInfo()
     meta_type="CDLI file"      meta_type="CDLI file"
       content_meta_type = ["CDLI File Object"]
       
     default_catalog='CDLICatalog'      default_catalog='CDLICatalog'
       security.declareProtected('manage','index_html')
           
     #security.declarePublic('history')  
     def getLastVersionData(self):      def getLastVersionData(self):
         """get last version data"""          """get last version data"""
         return self.getLastVersion().getData()          return self.getData()
   
     def getLastVersionFormattedData(self):      def getLastVersionFormattedData(self):
         """get last version data"""          """get last version data"""
         return self.getLastVersion().getFormattedData()          return self.getContentObject().getFormattedData()
   
     #security.declarePublic('history')      #security.declarePublic('history')
       
       
     def history(self):      def history(self):
         """history"""            """history"""  
   
Line 1558  class CDLIFile(extVersionedFile,CatalogA Line 1639  class CDLIFile(extVersionedFile,CatalogA
         #return [x.getObject() for x in context.CDLIBasketCatalog.search({'getFileNamesInLastVersion':self.getId()})]          #return [x.getObject() for x in context.CDLIBasketCatalog.search({'getFileNamesInLastVersion':self.getId()})]
                   
                   
       def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):
           """factory for content objects. to be overridden in derived classes."""
           return CDLIFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author)
   
   
     def addCDLIFileObjectForm(self):      def addCDLIFileObjectForm(self):
         """add a new version"""          """add a new version"""
                   
Line 1583  class CDLIFile(extVersionedFile,CatalogA Line 1669  class CDLIFile(extVersionedFile,CatalogA
         except:          except:
             pass              pass
                   
           ob = self.addContentObject(id, vC, author, file, title, changeName=changeName, newName=newName, from_tmp=from_tmp,
                                      precondition=precondition, content_type=content_type)
                   
         if changeName=="yes":  
             filename=file.filename  
             self.title=filename[max(filename.rfind('/'),  
                         filename.rfind('\\'),  
                         filename.rfind(':'),  
                         )+1:]  
   
   
         if not newName=='':  
             self.title=newName[0:]  
           
           
   
      
         positionVersionNum=getattr(self,'positionVersionNum','front')  
           
         if positionVersionNum=='front':  
             id="V%i"%self.getVersion()+"_"+self.title  
         else:  
             tmp=os.path.splitext(self.title)  
             if len(tmp)>1:  
                 id=tmp[0]+"_V%i"%self.getVersion()+tmp[1]  
             else:  
                 id=tmp[0]+"_V%i"%self.getVersion()  
               
         
         manage_addCDLIFileObject(self,id,vC,author,file,id,precondition, content_type,from_tmp=from_tmp)  
         #objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion()))  
         objs=getattr(self,id).setVersionNumber(int(self.getVersion()))  
         try:          try:
           #FIXME: wozu ist das gut?            #FIXME: wozu ist das gut?
           self.REQUEST.SESSION['objID_parent']=self.getId()            self.REQUEST.SESSION['objID_parent']=self.getId()
Line 1620  class CDLIFile(extVersionedFile,CatalogA Line 1679  class CDLIFile(extVersionedFile,CatalogA
           pass            pass
       
         if RESPONSE:          if RESPONSE:
                   if ob.getSize()==0:
             obj=self.ZopeFind(self,obj_ids=[id])[0][1]                  self.REQUEST.SESSION['objID']=ob.getId()
             if obj.getSize()==0:  
                 self.REQUEST.SESSION['objID']=obj.getId()  
                 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)                  pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)
                 return pt()                  return pt()
   
             else:              else:
                 if come_from and (come_from!=""):                  if come_from and (come_from!=""):
                                         RESPONSE.redirect(come_from+"?change="+self.getId())                                          RESPONSE.redirect(come_from+"?change="+self.getId())
                 else:                  else:
                     RESPONSE.redirect(self.REQUEST['URL2']+'?uploaded=%s'%self.title)                      RESPONSE.redirect(self.REQUEST['URL2']+'?uploaded=%s'%self.title)
   
         else:          else:
             return self.ZopeFind(self,obj_ids=[id])[0][1]              return ob
                   
                   
 def manage_addCDLIFileForm(self):  def manage_addCDLIFileForm(self):
Line 1649  def manage_addCDLIFile(self,id,title,loc Line 1704  def manage_addCDLIFile(self,id,title,loc
     tryToggle=True      tryToggle=True
     tryCount=0      tryCount=0
           
     
   
     self._setObject(id,newObj)                        self._setObject(id,newObj)                  
     getattr(self,id).reindex_object()      getattr(self,id).reindex_object()
                   
Line 1740  class CDLIFileFolder(extVersionedFileFol Line 1793  class CDLIFileFolder(extVersionedFileFol
           
     security=ClassSecurityInfo()      security=ClassSecurityInfo()
     meta_type="CDLI Folder"      meta_type="CDLI Folder"
     filesMetaType=['CDLI file']      file_meta_type=['CDLI file']
     folderMetaType=['CDLI Folder']      folder_meta_type=['CDLI Folder']
       
     default_catalog='CDLICatalog'      default_catalog='CDLICatalog'
     defaultFileCatalog=default_catalog #wenn dieses definiert ist, wird beim hinzufŸgen einer neuen version eines files dieser catalog neuiniziert      defaultFileCatalog=default_catalog #wenn dieses definiert ist, wird beim hinzufuegen einer neuen version eines files dieser catalog neuindiziert
     #downloadCounter=0 # counts how many download for all files currently run, be mehr als 5 wird verweigert.      #downloadCounter=0 # counts how many download for all files currently run, be mehr als 5 wird verweigert.
     tmpStore2={}      tmpStore2={}
   
     def setTemp(self,name,value):      def setTemp(self,name,value):
         """set tmp"""          """set tmp"""
   
Line 1753  class CDLIFileFolder(extVersionedFileFol Line 1808  class CDLIFileFolder(extVersionedFileFol
                                                                                   
                                                                                 
     def delete(self,ids):      def delete(self,ids):
         """delete this file, i.e. move into a trash folder"""          """delete these files"""
                
         found=self.ZopeFind(self,obj_ids=['.trash'])  
           
         if len(found)<1:  
             manage_addCDLIFileFolder(self, '.trash',title="Trash")  
             trash=self._getOb('.trash')  
         else:  
             trash=found[0][1]  
           
         if type(ids) is not ListType:          if type(ids) is not ListType:
             ids=[ids]              ids=[ids]
         cut=self.manage_cutObjects(ids)  
         trash.manage_pasteObjects(cut)          self.manage_delObjects(ids)
   
                   
     def getVersionNumbersFromIds(self,ids):      def getVersionNumbersFromIds(self,ids):
         """get the numbers of the current versions of documents described by their ids"""          """get the numbers of the current versions of documents described by their ids"""
Line 1777  class CDLIFileFolder(extVersionedFileFol Line 1824  class CDLIFileFolder(extVersionedFileFol
         founds=self.CDLICatalog.search({'title':searchStr})          founds=self.CDLICatalog.search({'title':searchStr})
                   
         for found in founds:          for found in founds:
             lastVersion=found.getObject().getLastVersion()              lastVersion=found.getObject().getContentObject()
             ret.append((found.getId,lastVersion))              ret.append((found.getId,lastVersion))
                   
         return ret          return ret
           
     def getFile(self,fn):      def getFile(self,fn):
         """get the content of the file fn"""          """get the content of the file fn"""
           logging.debug("getFile: %s"%repr(fn))
           if not self.hasObject(fn):
               # search deeper
         founds=self.CDLICatalog.search({'title':fn})          founds=self.CDLICatalog.search({'title':fn})
         if not founds:              if founds:
                   obj=founds[0].getObject().getContentObject()
               else:
             return ""               return "" 
         else:          else:
             obj=founds[0].getObject().getLastVersion()              obj = self[fn].getContentObject()
   
             return obj.getData()[0:]               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
                     
                   
                                      
     def findObjectsFromListWithVersion(self,list,author=None):      def findObjectsFromListWithVersion(self,list,author=None):
         """find objects from a list with versions          """find objects from a list with versions
         @param list: list of tuples  (cdliFile,version)          @param list: list of tuples  (cdliFile,version)
         """          """
           
          
          
         #self.REQUEST.SESSION['fileIds']=list#store fieldIds in session for further usage          #self.REQUEST.SESSION['fileIds']=list#store fieldIds in session for further usage
         #self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds']          #self.REQUEST.SESSION['searchList']=self.REQUEST.SESSION['fileIds']
                   
           
         pt=getattr(self,'filelistVersioned.html')          pt=getattr(self,'filelistVersioned.html')
                           
         return pt(search=list,author=author)          return pt(search=list,author=author)
Line 1916  class CDLIFileFolder(extVersionedFileFol Line 1964  class CDLIFileFolder(extVersionedFileFol
                                   
                 #os.write(tf,obj.getLastVersion().data)                  #os.write(tf,obj.getLastVersion().data)
                 if RESPONSE:                  if RESPONSE:
                     RESPONSE.write(obj.getLastVersion().getData()[0:])                      RESPONSE.write(obj.getData()[0:])
                     RESPONSE.write("\n")                      RESPONSE.write("\n")
                 self.temp_folder.downloadCounter-=1                   self.temp_folder.downloadCounter-=1 
                 self._p_changed=1                  self._p_changed=1
Line 1936  class CDLIFileFolder(extVersionedFileFol Line 1984  class CDLIFileFolder(extVersionedFileFol
     def hasParent(self):      def hasParent(self):
         """returns true falls subfolder"""          """returns true falls subfolder"""
               
         if self.aq_parent.meta_type in self.folderMetaType:          if self.aq_parent.meta_type in self.folder_meta_type:
             return True              return True
         else:          else:
             return False              return False
Line 1944  class CDLIFileFolder(extVersionedFileFol Line 1992  class CDLIFileFolder(extVersionedFileFol
     def getFolders(self):      def getFolders(self):
         """get all subfolders"""          """get all subfolders"""
         ret=[]          ret=[]
         folders=self.ZopeFind(self,obj_metatypes=self.folderMetaType)          folders=self.ZopeFind(self,obj_metatypes=self.folder_meta_type)
         for folder in folders:          for folder in folders:
             ret.append((folder[1],              ret.append((folder[1],
                         len(self.ZopeFind(folder[1],obj_metatypes=self.folderMetaType)),                          len(self.ZopeFind(folder[1],obj_metatypes=self.folder_meta_type)),
                         len(self.ZopeFind(folder[1],obj_metatypes=self.filesMetaType))                          len(self.ZopeFind(folder[1],obj_metatypes=self.file_meta_type))
                         ))                          ))
         return ret          return ret
           
                           
     security.declareProtected('View','index_html')      security.declareProtected('manage','index_html')
     def index_html(self):      def index_html(self):
         """main"""          """main"""
         ext=self.ZopeFind(self,obj_ids=["index.html"])          ext=self.ZopeFind(self,obj_ids=["index.html"])
Line 2002  class CDLIRoot(Folder): Line 2050  class CDLIRoot(Folder):
     meta_type="CDLIRoot"      meta_type="CDLIRoot"
     downloadCounterBaskets=0# counts the current basket downloads if counter > 10 no downloads are possible      downloadCounterBaskets=0# counts the current basket downloads if counter > 10 no downloads are possible
           
     def deleteFiles(self,ids):      file_catalog = 'CDLICatalog'
         """delete files (resp. move into .trash folder)"""  
         # find or generete trash folder  
           
         found=self.ZopeFind(self,obj_ids=['.trash'])  
                   
         if len(found)<1:      # word splitter for search
             manage_addCDLIFileFolder(self, '.trash',title="Trash")      splitter = {'words':cdliSplitter.wordSplitter(),
             trash=self._getOb('.trash')                  'graphemes':cdliSplitter.graphemeSplitter()}
         else:  
             logging.info(found)  
             trash=found[0][1]  
                   
                   
       def deleteFiles(self,ids):
           """delete files"""
         for id in ids:          for id in ids:
             founds=self.CDLICatalog.search({'title':id.split(".")[0]})              founds=self.CDLICatalog.search({'title':id.split(".")[0]})
             if founds:              if founds:
                 logging.info(founds)                  logging.debug("deleting %s"%founds)
                 folder=founds[0].getObject().aq_parent #get the parent folder of the object                  folder=founds[0].getObject().aq_parent #get the parent folder of the object
                 logging.info(folder)                  logging.debug("deleting from %s"%folder)
                 cut=folder.manage_cutObjects([founds[0].getId]) #cut it out                  cut=folder.delete([founds[0].getId]) #cut it out
                 trash.manage_pasteObjects(cut)  #paste it in the trash  
   
   
     def findWordRegExp(self,indexName,searchTerm):  
         """find all words in index which match regexp in SearchTerm  
         @param indexName: name of the index to be searched in  
         @param searchTerm: word to be searched"""  
           
         ret=[]  
         for x in self.lineIndexes[indexName].iterkeys():  
             if re.match(searchTerm,x):  
                 ret.append(x)  
         return ret  
       
     def searchRegExpInLineIndexDocs(self,indexName,searchTerm):  
         """search in inLineIndex with regexp  
         @param indexName: name of the index to be searched in  
         @param searchTerm: term to be searched  
         """  
         if not searchTerm:  
             return []  
         ret=[]  
         words=self.findWordRegExp(indexName,searchTerm) # suche nach allen Treffern  
         logging.info("wd:%s"%words)  
         for word in words:  
             ret+=self.searchInLineIndexDocs(indexName,word)  
           
         return unique(ret)  
           
     def showInLineIndex(self):  
         """get the index for debug purposes"""  
         print "show"  
         for key in self.lineIndexes.keys():  
             logging.info("index:%s"%key)  
             for x in self.lineIndexes[key].iterkeys():  
                 logging.info("word:%s"%repr(x))  
                 #for y in self.lineIndex[x].iterkeys():  
                 #    print "doc",repr(y),repr(self.lineIndex[x][y])  
                       
         return self.lineIndexes  
           
     def searchInLineIndexDocs(self,indexName,word,uniq=True,regExp=False):  
         """search occurences in an index  
         @param indexName: name of the index to be searched in  
         @param word: word to be searched  
         @param unique: (optional) unify the list of results  
         @param regExp: (optional) use regular expressions  
         """  
   
         if regExp:  
             return self.searchRegExpInLineIndexDocs(indexName,word)  
                   
         try:      
                   
                 lst=list(self.lineIndexes[indexName].get(word).keys())  
         except:  
             logging.error("error: searchInLineIndexDocs (%s %s)"%(sys.exc_info()[0:2]))  
             lst=[]  
         if uniq:  
             return unique(lst)  
         else:  
             return lst  
           
     def getLinesFromIndex(self,indexName,word,doc,regExp=False):  
         """return all lines from a document where word is found  
         @param indexName: Name of the index  
         @param word: word to be searched  
         @param doc: name of the document (usuallay the p-number)  
         @param regExp: (optional) use regExp         
         """  
           
         if not regExp:  
             return self.lineIndexes[indexName].get(word)[doc]  
         else: # wenn regexp, suche welches word  
             for w in self.findWordRegExp(indexName,word):  
                 if self.lineIndexes[indexName].get(w): # ein word in im dex gefunden  
                     try:      
                         dc=self.lineIndex[indexName].get(word)[doc]  
                         return dc # und ein document dann gib es zurueck  
                     except:  
                          pass #andernfalls weiter  
                        
     def cleanInLineIndex(self,indexName):  
         """empty an InlineIndex  
         @param indexName: name of the index  
         """  
         for x in list(self.lineIndexes[indexName].keys()):  
             del(self.lineIndexes[indexName][x])  
         print [x for x in self.lineIndexes[indexName].keys()]  
        
         return "ok"  
       
     def storeInLineIndex(self,indexName,key,value):  
         """store in index, key is normally a word or grapheme   
         and value is a tuple (documentname, line) where the word can be found  
         @param indexName: name of the index  
         @param key: key in index  
         @param value: value in index, value is a tuple (document name, line)  
         """  
         logging.error("indexing: %s %s"%(indexName,key))  
         if (not hasattr(self,'lineIndexes')):  
         
             self.lineIndexes={}  
                           
         if self.lineIndexes.get(indexName,None) is None:  
             #index exisitiert noch nicht dann anlegen  
                           
             self.lineIndexes[indexName]=OOBTree()      def searchText(self, query, index='words'):
         lis=self.lineIndexes          """searches query in the fulltext index and returns a list of file ids/P-numbers"""
         li=lis[indexName]          idxQuery = {index:{'query':query}}
           idx = getattr(self, self.file_catalog)
           results = []
           # do search
           resultset = idx.search(idxQuery)
           for res in resultset:
               # put only the P-Number in the result 
               results.append(res.getId[:7])
           return results
   
           # from PluginINdexes.common.util.py:parseIndexRequest:
           #
           #      The class understands the following type of parameters:
           #
           #    - old-style parameters where the query for an index as value inside
           #      the request directory where the index name is the name of the key.
           #      Additional parameters for an index could be passed as index+"_usage" ...
           #
           #
           #    - dictionary-style parameters specify a query for an index as
           #      an entry in the request dictionary where the key corresponds to the
           #      name of the index and the key is a dictionary with the parameters
           #      passed to the index.
           #
           #      Allowed keys of the parameter dictionary:
           #
           #      'query'  - contains the query (either string, list or tuple) (required)
           #
           #      other parameters depend on the the index
           #
           #
           #   - record-style parameters specify a query for an index as instance of the
           #     Record class. This happens usually when parameters from a web form use
           #     the "record" type e.g. <input type="text" name="path.query:record:string">.
           #     All restrictions of the dictionary-style parameters apply to the record-style
           #     parameters
                   
         if li.has_key(key):  
   
 #            if li[key].has_key(value[0]) and (not (value[1] in li[key][value[0]])):  
             if li[key].has_key(value[0]):  
                 tmp=li[key][value[0]]  
                 tmp.append(value[1]) # add it if now in the array  
                 li[key][value[0]]=tmp[0:]  
             else:  
                 li[key][value[0]]=[value[1]] # new array for lines  
                   
         else:  
               
             li[key]=OOBTree()# new btree for lines  
             li[key][value[0]]=[value[1]]   
                       
           
         self.lineIndexes=lis  
        
         transaction.get().commit()  
                   
   
     def showFile(self,fileId):      def showFile(self,fileId,wholePage=False):
         """show a file          """show a file
         @param fileId: P-Number of the document to be displayed          @param fileId: P-Number of the document to be displayed
         """          """
Line 2163  class CDLIRoot(Folder): Line 2118  class CDLIRoot(Folder):
         if not f:          if not f:
             return ""              return ""
                   
           if wholePage:
               logging.debug("show whole page")
               return f[0].getObject().getContentObject().view()
           else:
         return f[0].getObject().getLastVersionFormattedData()          return f[0].getObject().getLastVersionFormattedData()
           
   
     def showWordInFile(self,fileId,word,lineList=None,regExp=True,indexName=""):      def showWordInFile(self,fileId,word,lineList=None,regExp=False,indexName=""):
         """get lines with word  fromFileId"""          """get lines with word  fromFileId"""
                   
         file=self.showFile(fileId)          file=self.showFile(fileId)
           logging.debug("show word regEXP %s"%regExp)
         ret=[]          ret=[]
         if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen          if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen
             wordlist=self.findWordRegExp(indexName,word)              wordlist=self.findWordRegExp(indexName,word)
Line 2178  class CDLIRoot(Folder): Line 2137  class CDLIRoot(Folder):
             wordlist=[word]              wordlist=[word]
                   
         for line in file.split("\n"):          for line in file.split("\n"):
               line = formatAtfLineHtml(unicodify(line))
             found=False              found=False
             for word in wordlist:              for word in wordlist:
                   try: # just a hack because of possible unicode errors in line
                 if line.find(word)>-1:                  if line.find(word)>-1:
                         if lineList: #liste of moeglichen Zeilennummern                          if lineList: #liste of moeglichen Zeilennummern
                                 num=line.split(".")[0] #Zeilenummer ist alles vor dem . in der Zeile                                  num=line.split(".")[0] #Zeilenummer ist alles vor dem . in der Zeile
   
                                 if num in lineList:                                   if num in lineList: 
   
                                         ret.append(line)                                          ret.append(line)
                         else: # nimm alles ohne line check                          else: # nimm alles ohne line check
                                 ret.append(line)                                  ret.append(line)
                           
                         break;                          break;
                   except:
                       pass
         return ret          return ret
   
     def tagWordInFile(self,fileId,word,lineList=None,regExp=True,indexName=""):  
         """get lines with word  fromFileId"""      def tagWordInFile(self,fileId,word,indexName='words',regExp=False):
           """get text with word highlighted from FileId"""
                   
         file=self.showFile(fileId)          file=self.showFile(fileId)
         tagStr="""<span class="found">%s</span>"""          tagStr=u'<span class="found">%s</span>'
         ret=[]          ret=[]
           # search using lowercase
           word = word.lower()
                   
         if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen          if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen
             wordlist=self.findWordRegExp(indexName,word)              wordlist=self.findWordRegExp(indexName,word)
         else:          else:
             wordlist=[word]              # split the search term into words according to the corresponding splitter
               #try:
               wordlist = self.splitter[indexName].process([word])
               #except:
               #    wordlist=[word]
                           
         for line in file.split("\n"):          for line in file.split("\n"):
             found=False              line = formatAtfLineHtml(unicodify(line))
             for word in wordlist:              if not line:
                 if line.find(word)>-1: #word ist gefunden dann makiere und breche die Schleife ab                  # formatAtf can produce empty lines
                         if lineList: #liste of moeglichen Zeilennummern                  continue
                                 num=line.split(".")[0] #Zeilenummer ist alles vor dem . in der Zeile              
               for w in wordlist:
                   if line.lower().find(w)>-1: 
                       #word ist gefunden dann makiere
                       line = line.replace(w,tagStr%w)
   
                                 if num in lineList:   
   
                                         ret.append(line.replace(word,tagStr%word))  
                           
                         else: # nimm alles ohne line check  
                                 ret.append(line.replace(word,tagStr%word))  
                         found=True  
                         break  
             if not found: #word wurde nicht gefunden keine makierung  
                         ret.append(line)                          ret.append(line)
                                                   
         return "<br>\n".join(ret)          return u'<br>\n'.join(ret)
   
     def URLquote(self,str):      def URLquote(self,str):
         """quote url"""          """quote url"""

Removed from v.1.73  
changed lines
  Added in v.1.80.2.4


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