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

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

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