Annotation of OSAS/OSA_system/OSAS_show.py.~1.11.~, revision 1.1

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

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