File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.13: download - view: text, annotated - select for diffs - revision graph
Fri Jan 9 12:47:04 2004 UTC (20 years, 6 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
bug in hasindex fixed

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

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