File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.20: download - view: text, annotated - select for diffs - revision graph
Thu Apr 15 20:48:01 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
change all template of tree and subtree addede

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

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