File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Sun Oct 12 21:19:13 2003 UTC (20 years, 8 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
minor changes and sorfield

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

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