File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.19: download - view: text, annotated - select for diffs - revision graph
Wed Apr 14 21:26:23 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
erste version nur fulltext

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

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