File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.9: download - view: text, annotated - select for diffs - revision graph
Fri Dec 19 13:58:52 2003 UTC (20 years, 6 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
rescale images add

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

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