Annotation of lise/archive.py, revision 1.1

1.1     ! wischi      1: """ TO DO generell falls noch ein File, das nicht index.meta -> archivierung ausgeben """
        !             2: from types import *
        !             3: import urllib
        !             4: import os
        !             5: import sys
        !             6: import re
        !             7: from AccessControl import ClassSecurityInfo
        !             8: from AccessControl.Role import RoleManager
        !             9: from Acquisition import Implicit
        !            10: from Globals import Persistent
        !            11: from time import strptime
        !            12: from time import strftime
        !            13: import time
        !            14: import os.path
        !            15: import dircache
        !            16: import xml.dom.minidom
        !            17: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
        !            18: from Products.PageTemplates.PageTemplate import PageTemplate
        !            19: import tempfile
        !            20: tempfile.tempdir="/var/tmp/archiver"
        !            21: 
        !            22: exclusion=[".HSResource","lost+found","Network Trash Folder","TheFindByContentFolder","TheVolumeSettingsFolder"]
        !            23: class fsentry(Implicit, Persistent, RoleManager):
        !            24:       """File entry class"""
        !            25:       path = ""
        !            26:       user = ""
        !            27:       month = ""
        !            28:       date =""
        !            29:       time = ""
        !            30:       
        !            31:       security=ClassSecurityInfo()
        !            32:       def __init__(self,extpath):
        !            33:         """initialize class"""
        !            34:         extpath=os.path.abspath(re.search(r"(.*)\n",extpath).group(1))
        !            35:              self.all=extpath
        !            36:         self.path=extpath
        !            37:         self.user=""
        !            38:         self.mtime=os.path.getmtime(extpath)
        !            39:           
        !            40:           
        !            41:       security.declarePublic('getPath')
        !            42:       def getPath(self):
        !            43:          """Ausgabe von path"""
        !            44:          return self.path
        !            45: 
        !            46:       security.declarePublic('getUser')
        !            47:       def getUser(self):
        !            48:          """Ausgabe von user"""
        !            49:          return self.user
        !            50: 
        !            51:       security.declarePublic('getDate')
        !            52:       def getDate(self):
        !            53:          """Ausgabe von Date"""
        !            54:      return strftime("%Y%m%d%H%M",time.gmtime(self.mtime))
        !            55:              
        !            56:       security.declarePublic('getDate')
        !            57:       def getID(self):
        !            58:          """Ausgabe einer eindeutigen Sortierbaren ID"""
        !            59:      return self.getDate()+self.getPath()
        !            60:        
        !            61:       security.declarePublic('getTime')
        !            62:       def getTime(self):
        !            63:          """Ausgabe von path"""
        !            64:          return self.time
        !            65:       security.declarePublic('getAll')
        !            66:       def getAll(self):
        !            67:          """Ausgabe von path"""
        !            68:          return self.all
        !            69: 
        !            70: class filesystem(Implicit, Persistent, RoleManager):
        !            71:       """store filesystem"""
        !            72:       node={}
        !            73:       hasindex={}
        !            74:       security=ClassSecurityInfo()
        !            75:      
        !            76:       def getfs(self,start):
        !            77:         """load filessystem"""
        !            78:         f = os.popen("find "+ start+" -name '*' ","r")
        !            79:    lines = f.readlines()
        !            80:    
        !            81:         return lines
        !            82: 
        !            83:       def loadfs(self,start):
        !            84:         """analyse filesystem"""
        !            85:        for line in self.getfs(start):
        !            86:        
        !            87:        g=re.search(r"(.*/)(.*)\n",line)
        !            88:        if not g==None:
        !            89:                path=g.group(1)
        !            90:                file=g.group(2)
        !            91:                if self.node.has_key(path):
        !            92:                 elements=self.node[path]
        !            93:                 elements.append(file)
        !            94:                 self.node[path]=elements
        !            95:                else:
        !            96:             self.node[path]=[file]
        !            97:                    if (file=="index.meta") | (file=="meta"):
        !            98:             self.hasindex[path]="1"
        !            99:        
        !           100:       def __init__(self,start,reload=0):
        !           101:            if reload==1:
        !           102:           self.node={}
        !           103:           self.hasindex={}
        !           104:                   self.loadfs(start)
        !           105:                    
        !           106:           
        !           107:       security.declarePublic('getNode')
        !           108:       def getNode(self):
        !           109:               return self.node
        !           110:       
        !           111:       security.declarePublic('getKeys')
        !           112:       def getKeys(self):
        !           113:               return self.node.keys()
        !           114:       
        !           115:       security.declarePublic('clearnode')
        !           116:       def clearnode(self):
        !           117:       self.node={}
        !           118:               return 0
        !           119: 
        !           120:       security.declarePublic('hasIndex')
        !           121:       def hasIndex(self,path):
        !           122:    
        !           123:               return self.hasindex.has_key(path)
        !           124: 
        !           125:       
        !           126:       def onlyIndex_old(self):
        !           127:       """return only files with archive material"""
        !           128:           j={}
        !           129:       for k in self.node:
        !           130:           if self.hasindex.has_key(k):
        !           131:              if len(self.node[k])>1:
        !           132:             if (len(self.node[k])==2) & ('meta' not in self.node[k]):
        !           133:                j[k]=self.node[k]
        !           134:             elif (len(self.node[k])==2) & ('meta' in self.node[k]):
        !           135:                         """ nothing """
        !           136:             else:
        !           137:                    j[k]=self.node[k]     
        !           138:               return j
        !           139: 
        !           140:       def archive_the_path(self,path):
        !           141:            """parse indexmeta and return digilib path"""
        !           142:            try:
        !           143:                  #f = os.popen("cat "+path+"/index.meta","r")
        !           144:                  f =file(path+"/index.meta","r")
        !           145:                  
        !           146:                  lines = f.read()
        !           147:            
        !           148:                  try:
        !           149:                        dom = xml.dom.minidom.parseString(lines)
        !           150:                        if getText(dom.getElementsByTagName("content-type")[0].childNodes)=="folder":
        !           151:                              """folder nicht archivieren"""
        !           152:                              return 0
        !           153:                        else:
        !           154:                              archive_storage_date=getText(dom.getElementsByTagName("archive-storage-date")[0].childNodes)
        !           155:            
        !           156:                              if archive_storage_date=="":
        !           157:                              
        !           158:                                    """leer also archivieren"""
        !           159:                                    return 1
        !           160:                              else:
        !           161:                                    """nicht archivieren"""
        !           162:                                    return 0
        !           163:                  except:
        !           164:                        """kein tag also archivieren"""
        !           165:                        return 1
        !           166:            except:
        !           167:                  """kein index.meta also nicht archivieren"""
        !           168:                  return 0
        !           169:      
        !           170:       security.declarePublic('onlyIndex')
        !           171:       def onlyIndex(self):
        !           172:       """return only files with archive material (archive-storage-date not set)"""
        !           173:           j={}
        !           174:            
        !           175:       for k in self.node:
        !           176:          if self.archive_the_path(k):
        !           177:                     j[k]=self.node[k]
        !           178:               return j
        !           179:       security.declarePublic('getImageDirs')
        !           180:       def getImageDirs(self,dom,path):
        !           181:          dirs=dom.getElementsByTagName("dir")
        !           182:      dirback=[]
        !           183:      for dir in dirs:
        !           184:          temp=getText(dir.getElementsByTagName("name")[0].childNodes)
        !           185:          temp2=re.search(r"(.*)/mpiwg/online/(.*)",path+"/"+temp)
        !           186:          if not temp2==None:
        !           187:                     try:
        !           188:                           dirback.append(temp2.group(2))
        !           189:                     except:
        !           190:                           """nothing"""
        !           191:          else:
        !           192:        dirback.append(temp)
        !           193:           return dirback
        !           194:       
        !           195:          
        !           196:       
        !           197: 
        !           198:       security.declarePublic('digilib')      
        !           199:       def digilib(self, path):
        !           200:          """check if folder is a container for digilib files"""
        !           201:      if self.hasindex.has_key(path+"/"):
        !           202:            return(self.parseIndexMeta(path))
        !           203:      else:
        !           204:        return "NO"
        !           205: 
        !           206: 
        !           207:      
        !           208: 
        !           209:       security.declarePublic('isdigilib')    
        !           210:       def isdigilib(self, path):
        !           211:      """return number of possible image directories usefull for digilib""" 
        !           212:          if self.hasindex.has_key(path+"/"):
        !           213:         return(len(self.parseIndexMeta(path)))
        !           214:      else:
        !           215:         return 0
        !           216: 
        !           217:       security.declarePublic('parseIndexMeta')
        !           218:       def parseIndexMeta(self,k):
        !           219:          """parse indexmeta and return digilib path"""
        !           220:          f = os.popen("cat "+k+"/index.meta","r")
        !           221:           lines = f.read()
        !           222:      
        !           223:           try:
        !           224:       dom = xml.dom.minidom.parseString(lines)
        !           225:       content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
        !           226:               if (content_type=="scanned-document") or (content_type=="scanned document"):
        !           227:               dirs=self.getImageDirs(dom,k)
        !           228:        
        !           229:       return dirs
        !           230:      except:
        !           231:       return []
        !           232:          
        !           233:      
        !           234: class filesystem2(Implicit, Persistent, RoleManager):
        !           235:       """store filesystem"""
        !           236:       node={}
        !           237:       hasindex={}
        !           238:       security=ClassSecurityInfo()
        !           239:      
        !           240:       def getfs(self,start):
        !           241:         """load filessystem"""
        !           242:         f = os.popen("find "+ start+" -name '*' ","r")
        !           243:    lines = f.readlines()
        !           244:    
        !           245:         return lines
        !           246: 
        !           247:       def loadfs(self,start):
        !           248:         """analyse filesystem"""
        !           249:        for line in self.getfs(start):
        !           250:        
        !           251:        g=re.search(r"(.*/)(.*)\n",line)
        !           252:        if not g==None:
        !           253:                   try:
        !           254:                         path=g.group(1)
        !           255:                         file=g.group(2)
        !           256:                   except:
        !           257:                         """nothing"""
        !           258:                   if self.node.has_key(path):
        !           259:                 elements=self.node[path]
        !           260:                 elements.append(file)
        !           261:                 self.node[path]=elements
        !           262:                   else:
        !           263:             self.node[path]=[file]
        !           264:                   if (file=="index.meta") | (file=="meta"):
        !           265:                      self.hasindex[path]="1"
        !           266:        
        !           267:       def __init__(self,start,reload=0):
        !           268:            """nothing"""
        !           269:          
        !           270:       security.declarePublic('getImageDirs')
        !           271:       def getImageDirs(self,dom,path):
        !           272:          dirs=dom.getElementsByTagName("dir")
        !           273:      dirback=[]
        !           274:      for dir in dirs:
        !           275:          temp=getText(dir.getElementsByTagName("name")[0].childNodes)
        !           276:          temp2=re.search(r"(.*)/mpiwg/online/(.*)",path+"/"+temp)
        !           277:          if not temp2==None:
        !           278:                     try:
        !           279:                           dirback.append(temp2.group(2))
        !           280:                     except:
        !           281:                           """nothing"""
        !           282:          else:
        !           283:        dirback.append(temp)
        !           284:           return dirback
        !           285:       
        !           286:          
        !           287:       security.declarePublic('digilib')      
        !           288:       def digilib(self, path):
        !           289:          """check if folder is a container for digilib files"""
        !           290:      if os.path.exists(path+"/index.meta"):
        !           291:            return(self.parseIndexMeta(path))
        !           292:      else:
        !           293:        return "NO"
        !           294: 
        !           295:       security.declarePublic('isdigilib')    
        !           296:       def isdigilib(self, path):
        !           297:          if os.path.exists(path+"/index.meta"):
        !           298:         return(len(self.parseIndexMeta(path)))
        !           299:      else:
        !           300:         return 0
        !           301:       security.declarePublic('parseIndexMeta')
        !           302:       def parseIndexMeta(self,k):
        !           303:          """parse indexmeta and return digilib path"""
        !           304:          f = os.popen("cat "+k+"/index.meta","r")
        !           305:           lines = f.read()
        !           306:      
        !           307:           try:
        !           308:       dom = xml.dom.minidom.parseString(lines)
        !           309:       content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
        !           310:               if content_type=="scanned-document":
        !           311:               dirs=self.getImageDirs(dom,k)
        !           312:        
        !           313:       return dirs
        !           314:      except:
        !           315:       return []
        !           316:          
        !           317:      
        !           318: class browse(Implicit, Persistent, RoleManager):
        !           319:       
        !           320:       security=ClassSecurityInfo()
        !           321:       tree={}
        !           322:       toggledict={}
        !           323: 
        !           324:       def filterExcluded(self,dir):
        !           325:      ret=[]
        !           326:      for item in dir:
        !           327:        if not item in exclusion:
        !           328:            ret.append(item) 
        !           329:      return ret
        !           330:    
        !           331:       def __init__(self,startpath):
        !           332:          self.tree={}
        !           333:      self.tree[startpath]=self.filterExcluded(dircache.listdir(startpath))
        !           334: 
        !           335:       security.declarePublic('getTree')
        !           336:       def getTree(self,path):  
        !           337:          if self.tree.has_key(path):
        !           338:                return self.tree[path]
        !           339:           else:
        !           340:         self.tree[path]=self.filterExcluded(dircache.listdir(path))
        !           341:         return self.tree[path]
        !           342:       
        !           343:       security.declarePublic('isDirectory')
        !           344:       def isDirectory(self,path,file): 
        !           345:          return os.path.isdir(os.path.abspath(path+"/"+file))
        !           346:       
        !           347:       security.declarePublic('toggle')
        !           348:       def toggle(self,tmppath,file):
        !           349:          path=tmppath+"/"+file
        !           350:      
        !           351:          if self.toggledict.has_key(path):
        !           352:         if self.toggledict[path]==0:
        !           353:            self.toggledict[path]=1
        !           354:        
        !           355:         else:
        !           356:            self.toggledict[path]=0
        !           357:                 
        !           358:           else:
        !           359:         self.toggledict[path]=4
        !           360:         
        !           361: 
        !           362:       security.declarePublic('isToggle')
        !           363:       def isToggle(self,tmppath,file):
        !           364:          path=tmppath+"/"+file
        !           365: 
        !           366:      if self.toggledict.has_key(path):
        !           367:        
        !           368:            return self.toggledict[path]
        !           369:           else:
        !           370:        
        !           371:        return 0      
        !           372: 
        !           373:       
        !           374: def getfs(start):
        !           375:    """return filesystem"""
        !           376:         f = os.popen("find "+ start+" -name '*'","r")
        !           377:    lines = f.readlines()
        !           378:         return lines
        !           379: 
        !           380: def showall(start):
        !           381:    lines = getfs(start)
        !           382:    for line in lines:
        !           383:        print line
        !           384:         return 0
        !           385: 
        !           386: def entries(start):
        !           387:    """retrun list of entries of a filesystem"""
        !           388:    i=0
        !           389:    fs=[]
        !           390:    lines=getfs(start)
        !           391:    for line in lines:
        !           392:             try:
        !           393:                   if os.path.exists(os.path.abspath(re.search(r"(.*)\n",line).group(1))):
        !           394:                         fs.append(fsentry(line))
        !           395:                         i=i+1
        !           396:             except:
        !           397:                   """nothing"""
        !           398:    return fs
        !           399: 
        !           400: def getfilesystem(start,reload=0):
        !           401:    """load filesystem"""
        !           402:    
        !           403:    k=filesystem(start,1)
        !           404:    return k
        !           405: 
        !           406: def getfilesystem2(start,reload=0):
        !           407:    """load filesystem"""
        !           408: 
        !           409:    k=filesystem2(start,1)
        !           410:    return k
        !           411: 
        !           412: def tree(start):
        !           413:    """get the filetree"""
        !           414:    k=browse(start)
        !           415:    return k
        !           416: 
        !           417: def sort_by_date(fs):
        !           418:    """sorts lists of fileentries"""
        !           419:    ls=[]
        !           420:    dict={}
        !           421:    for k in fs:
        !           422:             ls.append(k.getID())
        !           423:        dict[k.getID()]=k
        !           424:    ls.sort()
        !           425:         ls.reverse()
        !           426:         ret=[]
        !           427:    for j in ls:
        !           428:        ret.append(dict[j])
        !           429:         return ret
        !           430: 
        !           431: def path_to_link(path):
        !           432:     """generates navigation bar for showfiles"""
        !           433:     string=""
        !           434:     
        !           435:     tmppath=os.path.dirname(path)
        !           436:     i=0
        !           437:     pathes=[[path, os.path.basename(path)]]
        !           438:     
        !           439:     while not (len(tmppath)==1):
        !           440:          
        !           441:          i=i+1
        !           442:      if i>20: break
        !           443:    
        !           444:          pathes.append([tmppath, os.path.basename(tmppath)])
        !           445:          tmppath=os.path.dirname(tmppath)
        !           446: 
        !           447:     while i>=0:
        !           448:          string=string+"<a href=showfiles?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
        !           449:      
        !           450:      i=i-1
        !           451:     return string
        !           452: 
        !           453: def path_to_link_view(path):
        !           454:     """generates navigation bar for viewfiles"""
        !           455:     string=""
        !           456:     
        !           457:     tmppath=os.path.dirname(path)
        !           458:     i=0
        !           459:     pathes=[[path, os.path.basename(path)]]
        !           460:     
        !           461:     while not (len(tmppath)==1):
        !           462:          
        !           463:          i=i+1
        !           464:      if i>20: break
        !           465:      
        !           466:          pathes.append([tmppath, os.path.basename(tmppath)])
        !           467:          tmppath=os.path.dirname(tmppath)
        !           468: 
        !           469:     while i>=0:
        !           470:          string=string+"<a href=viewfiles?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
        !           471:      
        !           472:      i=i-1
        !           473:     return string
        !           474: 
        !           475: def path_to_link_store(path):
        !           476:     """generates navigation bar for viewfiles"""
        !           477:     string=""
        !           478:     
        !           479:     tmppath=os.path.dirname(path)
        !           480:     i=0
        !           481:     pathes=[[path, os.path.basename(path)]]
        !           482:     
        !           483:     while not (len(tmppath)==1):
        !           484:          
        !           485:          i=i+1
        !           486:      if i>20: break
        !           487:      
        !           488:          pathes.append([tmppath, os.path.basename(tmppath)])
        !           489:          tmppath=os.path.dirname(tmppath)
        !           490: 
        !           491:     while i>=0:
        !           492:          string=string+"<a href=storefiles?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
        !           493:      
        !           494:      i=i-1
        !           495:     return string
        !           496: 
        !           497: 
        !           498: class Error(Implicit, Persistent, RoleManager):
        !           499:    
        !           500:    error=[]
        !           501:        security=ClassSecurityInfo()
        !           502:    def __init__(self,initerror):
        !           503:               self.error=initerror[0:]
        !           504: 
        !           505:    security.declarePublic('getError')
        !           506:    def getError(self):
        !           507:        return self.error
        !           508: 
        !           509: class metacheck(Implicit, Persistent, RoleManager):
        !           510:         lines=[]
        !           511:    security=ClassSecurityInfo()
        !           512:    def parsearchive(self,str):
        !           513:            """parse for error"""
        !           514:            retstr=''
        !           515:                 
        !           516:                 if not len(str)==0:
        !           517:                       for line in str:
        !           518:                             retstr=retstr+line+"<br>"
        !           519:                       check=re.search(r"(.*):(.*)",line)
        !           520:                       if check.group(1)=='ABORT':
        !           521:                             error="error"
        !           522:                       elif check.group(1)=='DONE':
        !           523:                             error="ok"
        !           524:                       else:
        !           525:                             error="running"
        !           526:                             
        !           527:                       return [retstr,error]
        !           528:                 else:
        !           529:                       return ['','running']
        !           530:    def __init__(self,path):
        !           531:        """archive the documents in path"""
        !           532:            self.lines=[]
        !           533:        
        !           534:            if type(path)==StringType:
        !           535:            f = os.popen("/usr/local/mpiwg/archive/metacheck "+path,"r")
        !           536:                self.lines.append(Error([path,self.parsearchive(f.readlines())]))
        !           537:        else:
        !           538:                for singlepath in path:
        !           539:                    f = os.popen("/usr/local/mpiwg/archive/metacheck "+singlepath,"r")
        !           540:                    self.lines.append(Error([singlepath,self.parsearchive(f.readlines())]))
        !           541:         security.declarePublic('messages')
        !           542:    
        !           543:    def messages(self):
        !           544:        return self.lines
        !           545:    
        !           546:        
        !           547: 
        !           548: 
        !           549: class archive(Implicit, Persistent, RoleManager):
        !           550:       lines=[]
        !           551:       security=ClassSecurityInfo()
        !           552:       def parsearchive(self,str):
        !           553:             """parse for error"""
        !           554:             retstr=''
        !           555:             
        !           556:             if not len(str)==0:
        !           557:                   for line in str:
        !           558:                         retstr=retstr+line+"<br>"
        !           559:                   check=re.search(r"(.*):(.*)",line)
        !           560:                   if check.group(1)=='ABORT':
        !           561:                         error="error"
        !           562:                   elif check.group(1)=='DONE':
        !           563:                         error="ok"
        !           564:                   else:
        !           565:                         error="running"
        !           566:                   
        !           567:                   return [retstr,error]
        !           568:             else:
        !           569:                   return ['','running']
        !           570:                   
        !           571:       def __init__(self,path,session):
        !           572:             """archive the documents in path"""
        !           573:             self.lines=[]
        !           574:             self.filenames={}
        !           575:             session['archiver']=self
        !           576:            
        !           577:            
        !           578:             if type(path)==StringType:
        !           579:                   self.filenames[path]=tempfile.mktemp()
        !           580:                   f = os.popen("/usr/local/mpiwg/archive/archiver "+path+" > "+self.filenames[path]+" &","r")
        !           581:             else:
        !           582:                   for singlepath in path:
        !           583:                         self.filenames[singlepath]=tempfile.mktemp()
        !           584:                         f = os.popen("/usr/local/mpiwg/archive/archiver "+singlepath+" > "+self.filenames[singlepath]+" &","r")
        !           585:                             
        !           586:       security.declarePublic('messages')
        !           587:       def messages(self):
        !           588:             self.lines=[]
        !           589:             for path in self.filenames.keys():
        !           590:                   
        !           591:                   self.lines.append(Error([path,self.parsearchive(open(self.filenames[path],"r").readlines())]))
        !           592:             return self.lines
        !           593: 
        !           594:    
        !           595: def evalext(str):
        !           596:      return eval(str)
        !           597: 
        !           598: def storeerror(ret,path,context,i):
        !           599:      session=context.REQUEST.SESSION
        !           600:      session['error%i'%i]=ret
        !           601:      session['path%i'%i]=path
        !           602:      
        !           603:      return 'error?number=%i'%i
        !           604: 
        !           605: def geterror(str,context):
        !           606:      session=context.REQUEST.SESSION
        !           607:      return session[str]
        !           608: 
        !           609: def readfile(path):
        !           610:      
        !           611:      ret=""
        !           612:      f=open(path,'r')
        !           613:      for g in f.readlines():
        !           614:    ret=ret+g
        !           615:      return ret
        !           616: 
        !           617: def writefile(self,path,txt,REQUEST):
        !           618:      f=open(path,'w')
        !           619:      f.write(txt)
        !           620:      f.close()
        !           621:      rval=self.aq_acquire('archive2')
        !           622:      return rval()
        !           623: 
        !           624: 
        !           625: def metachecker(self,path):
        !           626:     """check the metadata the documents in path"""
        !           627:     self.REQUEST.SESSION['path']=self.REQUEST['path']
        !           628:     return metacheck(path)
        !           629: 
        !           630: def archiver(self,path):
        !           631:     """archive the documents in path"""
        !           632:     tmp=archive(path,self.REQUEST.SESSION)
        !           633:     return self.REQUEST.RESPONSE.redirect('archive4')
        !           634: 
        !           635: def getText(nodelist):
        !           636:     
        !           637:     rc = ""
        !           638:     for node in nodelist:
        !           639:        if node.nodeType == node.TEXT_NODE:
        !           640:            rc = rc + node.data
        !           641:     return rc
        !           642: 
        !           643: def getBib(nodelist):
        !           644:     rc= "<table border='0'>"
        !           645:     print "HI"
        !           646:     for node in nodelist:
        !           647:         
        !           648:        if node.nodeType == node.ELEMENT_NODE:
        !           649:       """nothing"""
        !           650:       rc = rc+"<tr><td valign='right'>"+str(node.nodeName)+":</td><td> "+getText(node.childNodes)+"</td></tr>"
        !           651:     #print rc
        !           652:     return rc+"</table>"
        !           653: 
        !           654: def getMetafile(path):
        !           655:     """get index.meta"""
        !           656:     html=[]
        !           657:     if not os.path.exists(path+"/index.meta"):
        !           658:           
        !           659:           return "NO_METADATA"
        !           660:     else:
        !           661:        f = os.popen("cat "+path+"/index.meta","r")
        !           662:        lines = f.read()
        !           663:        dom = xml.dom.minidom.parseString(lines)
        !           664:        name=getText(dom.getElementsByTagName("name")[0].childNodes) 
        !           665:        creator=getText(dom.getElementsByTagName("creator")[0].childNodes)   
        !           666:        creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes) 
        !           667:        description=getText(dom.getElementsByTagName("description")[0].childNodes) 
        !           668:        try:
        !           669:            type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
        !           670:        except:
        !           671:         type=""
        !           672:        if type=="scanned document":
        !           673:        html="<h3>Document: "+name+"</h3>"
        !           674:        elif type=="folder":
        !           675:        html="<h3>Folder: "+name+"</h3>"
        !           676:        else:
        !           677:                html="<h3>Document: "+name+"</h3>"
        !           678: 
        !           679:        html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>" 
        !           680:        html=html+"<h4>Description</h4><p>"+description+"</p>"
        !           681:        try:
        !           682:         bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0]
        !           683:         if bib.attributes.has_key('type'):
        !           684:      html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>"
        !           685:    else:
        !           686:      html=html+"<h4>Info</h4>"
        !           687:         html=html+getBib(bib.childNodes)
        !           688:         print html
        !           689:        except:
        !           690:         """none"""
        !           691:        
        !           692: #        html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace')
        !           693:        
        !           694:        return html
        !           695: 
        !           696: def hasMetafile(path):
        !           697:     """get index.meta"""
        !           698:     return os.path.exists(path+"/index.meta")
        !           699:     #return path
        !           700: 
        !           701: def isdigilib2(path):
        !           702:      """check if folder is candidate for digilib without metadata""" 
        !           703:           try:
        !           704:                 dir=os.listdir(path)
        !           705: 
        !           706:                 imagesuffixes=['.gif','.jpg','.jpeg','.png','.tiff','.tif','.JPG','.TIFF','.TIF']
        !           707:                 ret=""
        !           708:                 for a in dir:
        !           709:                       
        !           710:                       suffix=os.path.splitext(a)
        !           711:        
        !           712:                       if suffix[1] in imagesuffixes:
        !           713:                             return 1
        !           714: 
        !           715:                 try:
        !           716:                       dom=xml.dom.minidom.parse(os.path.split(path)[0]+"/index.meta")
        !           717:                       for node in dom.getElementsByTagName("dir"):
        !           718:                   
        !           719:                             if getText(node.getElementsByTagName("content-type")[0].childNodes)=="images":
        !           720:                         
        !           721:                                   if getText(node.getElementsByTagName("name")[0].childNodes)==os.path.split(path)[1]:
        !           722:                                         return 1
        !           723:                       return 0
        !           724:                 except:
        !           725:             
        !           726:                       return 0
        !           727: 
        !           728: 
        !           729:                 
        !           730:                 
        !           731: 
        !           732:           except:
        !           733:                 return 0
        !           734: 
        !           735: def isFullText(path,folder_name):
        !           736:       """check if foldername in path is full text"""
        !           737:       try:
        !           738:             dom=xml.dom.minidom.parse(path+"/index.meta")
        !           739:             for node in dom.getElementsByTagName("dir"):
        !           740:                   
        !           741:                   if getText(node.getElementsByTagName("content-type")[0].childNodes)=="fulltext":
        !           742:                         
        !           743:                         if getText(node.getElementsByTagName("name")[0].childNodes)==folder_name:
        !           744:                               return 1
        !           745:             return 0
        !           746:       except:
        !           747:             
        !           748:             return 0
        !           749: 
        !           750: 
        !           751: def isPresentation(path,folder_name):
        !           752:       """check if foldername in path is full text"""
        !           753:       try:
        !           754:             dom=xml.dom.minidom.parse(path+"/index.meta")
        !           755:             #print dom.toxml()
        !           756:             for dirnode in dom.getElementsByTagName("dir"):
        !           757:                   try:
        !           758:                          
        !           759:                         if getText(dirnode.getElementsByTagName('content-type')[0].childNodes)=='presentation':
        !           760:                               if getText(dirnode.getElementsByTagName("name")[0].childNodes)==folder_name:
        !           761:                                     return 1
        !           762:                   except:
        !           763:                         """nothing"""
        !           764:             return 0
        !           765:       except:
        !           766:             
        !           767:             return 0
        !           768:                   
        !           769:                   
        !           770:                         
        !           771: 
        !           772: 
        !           773: def changeName(path):
        !           774:       try:
        !           775:          temp2=re.search(r"(.*)/mpiwg/online/(.*)",path)
        !           776:     if temp2==None:     
        !           777:            return "digifiles/"+re.search(r"(.*)/mpiwg/production/docuserver/(.*)",path).group(2)
        !           778:     else:  
        !           779:            return temp2.group(2)
        !           780:       except: # hack - im archivbereich keine online darstellung gibt jetzt ein no zurück.
        !           781:             return "NO"
        !           782: 
        !           783:    
        !           784: def test(self):
        !           785:         self.i=1
        !           786:        #newtemplate=PageTemplateFile('/usr/local/mpiwg/Zope/Extensions/test').__of__(self)
        !           787:         self.manage_addProduct['OFSP'].manage_addDTMLMethod('neu','neu')
        !           788:         self.getattr('neu').manage_edit('HELLO','neu')
        !           789:         return "ok"
        !           790: 
        !           791: 
        !           792: class ls(Implicit, Persistent, RoleManager):
        !           793:       """File entry class"""
        !           794:       path = ""
        !           795:       user = ""
        !           796:       month = ""
        !           797:       date =""
        !           798:       time = ""
        !           799:       
        !           800:       security=ClassSecurityInfo()
        !           801: 
        !           802:       def __init__(self,start):
        !           803:             self.outfile=tempfile.mktemp()
        !           804:             start['outfile']=self
        !           805:             os.popen("ls -R / >"+self.outfile+" &","r")
        !           806:             
        !           807:             
        !           808:       security.declarePublic('read')
        !           809:       def read(self):
        !           810:             return self.f.read()
        !           811:       security.declarePublic('retself')
        !           812:       def retself(self):
        !           813:             return self
        !           814:       security.declarePublic('all')
        !           815:       def all(self):
        !           816:             ret=""
        !           817:             for g in self.f:
        !           818:                   ret=ret+g
        !           819:             return ret
        !           820: 
        !           821:       security.declarePublic('printOutfile')
        !           822:       def printOutfile(self):
        !           823:             while not os.path.exists(self.outfile):
        !           824:                   """nothing"""
        !           825:             return open(self.outfile).readlines()
        !           826:       
        !           827: class overview(Implicit,Persistent, RoleManager):
        !           828:       dir=[]
        !           829:       resources={}
        !           830:       security=ClassSecurityInfo()
        !           831:       
        !           832:       def __init__(self,path):
        !           833:             dir=os.listdir(path)
        !           834:             
        !           835:             for file in dir:
        !           836:                   self.resources[self.getResource(path,file)]=path+"/"+file
        !           837:         
        !           838:             
        !           839:       def getResource(self,path,filename):
        !           840:             f=file(path+"/"+filename,'r')
        !           841:       
        !           842:             for line in f.readlines():
        !           843:                   
        !           844:                   if line[0:4]=="INFO":
        !           845:                         if line[6:14]=="resource":
        !           846:                               return line
        !           847:             return "error"
        !           848: 
        !           849:       def parsearchive(self,str):
        !           850:             """parse for error"""
        !           851:             retstr=''
        !           852:             
        !           853:             if not len(str)==0:
        !           854:                   for line in str:
        !           855:                         retstr=retstr+line+"<br>"
        !           856:                   check=re.search(r"(.*):(.*)",line)
        !           857:                   if check.group(1)=='ABORT':
        !           858:                         error="error"
        !           859:                   elif check.group(1)=='DONE':
        !           860:                         error="ok"
        !           861:                   else:
        !           862:                         error="running"
        !           863:                   
        !           864:                   return [retstr,error]
        !           865:             else:
        !           866:                   return ['','running']
        !           867: 
        !           868:       security.declarePublic('messages')
        !           869:       def messages(self):
        !           870:             self.lines=[]
        !           871:             for name in self.resources.keys():
        !           872:                   path=self.resources[name]
        !           873:                   
        !           874:                   self.lines.append(Error([name,self.parsearchive(open(path,"r").readlines())]))
        !           875:             return self.lines
        !           876: 
        !           877:       security.declarePublic('printResource')
        !           878:       def printResource(self):
        !           879:             return self.resources
        !           880:       
        !           881: def getoverview(path):
        !           882:       
        !           883:       return overview(path)
        !           884: 
        !           885:       
        !           886: def ls_test(self):
        !           887:       tmp=ls(self.REQUEST.SESSION)
        !           888:       return self.REQUEST.RESPONSE.redirect('next')
        !           889: 
        !           890: def storeFile(self,something):
        !           891:       self.REQUEST.SESSION['something']=something
        !           892:       return 1
        !           893: 
        !           894: def getFile(self):
        !           895:       return self.REQUEST.SESSION['something']
        !           896: 
        !           897: def isFolder(self,path):
        !           898:       """returns TRUE, wenn path ein Folder ist in den weitere Objekte Folder oder Dokumente gelegt werden dürfen"""
        !           899:       return not isScannedDocument(self,path) # vorläufig sind alle Documente die keine scanned documente sind folder.
        !           900: 
        !           901: def isScannedDocument(self,path):
        !           902:       """returns TRUE, wenn path der Stammordner eines gescannten Documents ist"""
        !           903:       try:
        !           904:             f = file(path+"/index.meta","r")
        !           905:             lines = f.read()
        !           906:       
        !           907:             try:
        !           908:                   dom = xml.dom.minidom.parseString(lines)
        !           909:                   content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
        !           910:                   if (content_type=="scanned-document") or (content_type=="scanned document"):
        !           911:                         return 1
        !           912:                   else:
        !           913:                         return 0
        !           914:             except:
        !           915:                   return 0
        !           916:       except:
        !           917:             return 0
        !           918: 
        !           919: from time import localtime,strftime
        !           920: 
        !           921: def date(self):
        !           922:    return strftime("%d.%m.%Y",localtime()) 
        !           923: 
        !           924:       
        !           925:       
        !           926: def EditIndex(self,path):
        !           927:       try:
        !           928:             dom=xml.dom.minidom.parse(path+"/index.meta")
        !           929:             indexmeta=dom.toxml()
        !           930:       except:
        !           931:             indexmeta=""
        !           932:       self.REQUEST.SESSION['indexmeta']=indexmeta
        !           933:       self.REQUEST.SESSION['path']=path
        !           934:       newtemplate=PageTemplateFile('/usr/local/mpiwg/Zope/Extensions/editindex').__of__(self)
        !           935:       return newtemplate()
        !           936: 
        !           937: def EditIndex2(self):
        !           938:       if not self.REQUEST.has_key('fileupload'):
        !           939:             #newtext=urllib.unquote(self.REQUEST['indexmeta'])
        !           940:             newtext=self.REQUEST['indexmeta']
        !           941:             print newtext
        !           942:       else:
        !           943:             self.file_name=self.REQUEST['fileupload'].filename
        !           944:             #newtext=self.REQUEST.form['fileupload'].read()
        !           945:             # HACK DW
        !           946:             newtext=self.REQUEST['indexmeta']
        !           947:       
        !           948:       indexmeta=file(self.REQUEST.SESSION['path']+"/index.meta","w")
        !           949:       indexmeta.writelines(newtext)
        !           950:       return self.REQUEST.response.redirect("storage/storefiles?path="+self.REQUEST.SESSION['path'])

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