File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Thu Sep 25 15:25:08 2003 UTC (20 years, 9 months ago) by dwinter
Branches: dwinter
CVS tags: first
first release

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

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