File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Oct 1 08:20:47 2003 UTC (20 years, 9 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
New files for upload and editing

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

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