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

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

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