File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Mon Apr 5 21:54:42 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
major changes: metadata now configurable with osas_metadatamapping, servlet for upload in osas root

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

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