Annotation of OSAS/OSA_system/OSAS_show.py, revision 1.4

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

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