File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.21: download - view: text, annotated - select for diffs - revision graph
Thu Apr 15 21:30:42 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
bugs in change templates fixed

    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 archive@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,RESPONSE=None):
  262:         """Andere alle Eintraege in index.meta"""
  263:         os.path.walk(path,OSAS_helpers.changeIndexMeta,self.REQUEST.form)
  264: 	if RESPONSE is not None:
  265:         	RESPONSE.redirect(self.REQUEST['URL1']+"?path="+self.REQUEST.SESSION['path'])
  266: 
  267:         
  268: InitializeClass(OSAS_StoreOnline)
  269: 	
  270: def manage_AddOSAS_StoreOnlineForm(self):
  271:     """interface for adding the OSAS_root"""
  272:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_StoreOnline.zpt').__of__(self)
  273:     return pt()
  274: 
  275: def manage_AddOSAS_StoreOnline(self,id,RESPONSE=None):
  276:     """add the OSAS_root"""
  277:     newObj=OSAS_StoreOnline(id)
  278:     self._setObject(id,newObj)
  279:     if RESPONSE is not None:
  280:         RESPONSE.redirect('manage_main')
  281: 
  282: 
  283: 
  284: 
  285: def readContexts(path):
  286:     """ReadContext from index.meta"""
  287:     dom=xml.dom.minidom.parse(path+"/index.meta")
  288:     nodes=dom.getElementsByTagName('context')
  289:     ret=[]
  290:     
  291:     
  292:     for node in nodes:
  293:         try:
  294:             link=getText(node.getElementsByTagName('link')[0].childNodes)
  295:             name=getText(node.getElementsByTagName('name')[0].childNodes)
  296:             ret.append((link,name))
  297:         except:
  298:             """nothing"""
  299:     return ret
  300: 
  301:     
  302: ### Ab hier Baustelle
  303: 
  304:         
  305: from types import *
  306: import urllib
  307: import os
  308: import sys
  309: import re
  310: from AccessControl import ClassSecurityInfo
  311: from AccessControl.Role import RoleManager
  312: from Acquisition import Implicit
  313: from Globals import Persistent
  314: try:
  315:     from time import strptime
  316: except:
  317:     print "ignoring time.strptime import"
  318:     
  319: from time import strftime
  320: import time
  321: import os.path
  322: import dircache
  323: import xml.dom.minidom
  324: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
  325: from Products.PageTemplates.PageTemplate import PageTemplate
  326: import tempfile
  327: tempfile.tempdir="/var/tmp/archiver"
  328: 
  329: exclusion=[".HSResource","lost+found","Network Trash Folder","TheFindByContentFolder","TheVolumeSettingsFolder"]
  330: class fsentry(Implicit, Persistent, RoleManager):
  331:       """File entry class"""
  332:       path = ""
  333:       user = ""
  334:       month = ""
  335:       date =""
  336:       time = ""
  337:       
  338:       security=ClassSecurityInfo()
  339:       def __init__(self,extpath):
  340: 	     """initialize class"""
  341: 	     extpath=os.path.abspath(re.search(r"(.*)\n",extpath).group(1))
  342:              self.all=extpath
  343: 	     self.path=extpath
  344: 	     self.user=""
  345: 	     self.mtime=os.path.getmtime(extpath)
  346:           
  347:           
  348:       security.declarePublic('getPath')
  349:       def getPath(self):
  350:       	  """Ausgabe von path"""
  351:       	  return self.path
  352: 
  353:       security.declarePublic('getUser')
  354:       def getUser(self):
  355:       	  """Ausgabe von user"""
  356:       	  return self.user
  357: 
  358:       security.declarePublic('getDate')
  359:       def getDate(self):
  360:       	  """Ausgabe von Date"""
  361: 	  return strftime("%Y%m%d%H%M",time.gmtime(self.mtime))
  362: 	  		  
  363:       security.declarePublic('getDate')
  364:       def getID(self):
  365:       	  """Ausgabe einer eindeutigen Sortierbaren ID"""
  366: 	  return self.getDate()+self.getPath()
  367: 	  	
  368:       security.declarePublic('getTime')
  369:       def getTime(self):
  370:       	  """Ausgabe von path"""
  371:       	  return self.time
  372:       security.declarePublic('getAll')
  373:       def getAll(self):
  374:       	  """Ausgabe von path"""
  375:       	  return self.all
  376: 
  377: class filesystem(Implicit, Persistent, RoleManager):
  378:       """store filesystem"""
  379:       node={}
  380:       hasindex={}
  381:       security=ClassSecurityInfo()
  382:      
  383:       def getfs(self,start):
  384:         """load filessystem"""
  385:         f = os.popen("find "+ start+" -name '*' ","r")
  386: 	lines = f.readlines()
  387: 	
  388:         return lines
  389: 
  390:       def loadfs(self,start):
  391:         """analyse filesystem"""
  392:      	for line in self.getfs(start):
  393: 	    
  394: 	    g=re.search(r"(.*/)(.*)\n",line)
  395: 	    if not g==None:
  396: 	    	    path=g.group(1)
  397: 	    	    file=g.group(2)
  398: 	    	    if self.node.has_key(path):
  399: 	       	     elements=self.node[path]
  400: 	             elements.append(file)
  401: 	             self.node[path]=elements
  402: 	    	    else:
  403: 		     self.node[path]=[file]
  404:             	    if (file=="index.meta") | (file=="meta"):
  405: 		     self.hasindex[path]="1"
  406:        
  407:       def __init__(self,start,reload=0):
  408:            if reload==1:
  409: 		   self.node={}
  410: 		   self.hasindex={}
  411:     	      	   self.loadfs(start)
  412:                    
  413:           
  414:       security.declarePublic('getNode')
  415:       def getNode(self):
  416:        	   return self.node
  417:       
  418:       security.declarePublic('getKeys')
  419:       def getKeys(self):
  420:        	   return self.node.keys()
  421:       
  422:       security.declarePublic('clearnode')
  423:       def clearnode(self):
  424: 	   self.node={}
  425:        	   return 0
  426: 
  427:       security.declarePublic('hasIndex')
  428:       def hasIndex(self,path):
  429: 	
  430:        	   return self.hasindex.has_key(path)
  431: 
  432:       
  433:       def onlyIndex_old(self):
  434: 	   """return only files with archive material"""
  435:       	   j={}
  436: 	   for k in self.node:
  437: 	       if self.hasindex.has_key(k):
  438: 	       	  if len(self.node[k])>1:
  439: 		     if (len(self.node[k])==2) & ('meta' not in self.node[k]):
  440: 		     	j[k]=self.node[k]
  441: 		     elif (len(self.node[k])==2) & ('meta' in self.node[k]):
  442:                         """ nothing """
  443: 		     else:
  444: 	       	        j[k]=self.node[k]	  
  445:        	   return j
  446: 
  447:       def archive_the_path(self,path):
  448:            """parse indexmeta and return digilib path"""
  449:            
  450:            try:
  451:                  #f = os.popen("cat "+path+"/index.meta","r")
  452:                  f =file(path+"/index.meta","r")
  453:                  
  454:                  lines = f.read()
  455:                  
  456:                  try:
  457:                        dom = xml.dom.minidom.parseString(lines)
  458:                        if dom.getElementsByTagName("content-type"):
  459:                            if getText(dom.getElementsByTagName("content-type")[0].childNodes)=="folder":
  460:                                """folder nicht archivieren"""
  461:                                return 0
  462:                            
  463:                        archive_storage_date=getText(dom.getElementsByTagName("archive-storage-date")[0].childNodes)
  464:                        
  465:                        if archive_storage_date=="":
  466:                            
  467:                            """leer also archivieren"""
  468:                            return 1
  469:                        else:
  470:                            """nicht archivieren"""
  471:                            return 0
  472:                  except:
  473:                        """kein tag also archivieren"""
  474:                        return 1
  475:            except:
  476:                  """kein index.meta also nicht archivieren"""
  477:                  return 0
  478:      
  479:       security.declarePublic('onlyIndex')
  480:       def onlyIndex(self):
  481: 	   """return only files with archive material (archive-storage-date not set)"""
  482:       	   j={}
  483:            
  484: 	   for k in self.node:
  485: 	      if self.archive_the_path(k):
  486:                     j[k]=self.node[k]
  487:        	   return j
  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:       
  506: 
  507:       security.declarePublic('digilib')	  
  508:       def digilib(self, path):
  509:       	  """check if folder is a container for digilib files"""
  510: 	  if self.hasindex.has_key(path+"/"):
  511: 	        return(self.parseIndexMeta(path))
  512: 	  else:
  513: 		return "NO"
  514: 
  515: 
  516:      
  517: 
  518:       security.declarePublic('isdigilib')	  
  519:       def isdigilib(self, path):
  520: 	  """return number of possible image directories usefull for digilib""" 
  521:       	  if self.hasindex.has_key(path+"/"):
  522: 	     return(len(self.parseIndexMeta(path)))
  523: 	  else:
  524: 	     return 0
  525: 
  526:       security.declarePublic('parseIndexMeta')
  527:       def parseIndexMeta(self,k):
  528:       	  """parse indexmeta and return digilib path"""
  529:       	  f = os.popen("cat "+k+"/index.meta","r")
  530:           lines = f.read()
  531: 	  
  532:           try:
  533: 	   dom = xml.dom.minidom.parseString(lines)
  534: 	   content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
  535:        	   if (content_type=="scanned-document") or (content_type=="scanned document"):
  536: 	           dirs=self.getImageDirs(dom,k)
  537: 	  	
  538: 	   return dirs
  539: 	  except:
  540: 	   return []
  541:    	  
  542: 	  
  543: class filesystem2(Implicit, Persistent, RoleManager):
  544:       """store filesystem"""
  545:       node={}
  546:       hasindex={}
  547:       security=ClassSecurityInfo()
  548:      
  549:       def getfs(self,start):
  550:         """load filessystem"""
  551:         
  552:         f = os.popen("find "+ start+" -name '*' ","r")
  553: 	lines = f.readlines()
  554: 	
  555:         return lines
  556: 
  557:       def loadfs(self,start):
  558:         """analyse filesystem"""
  559:      	for line in self.getfs(start):
  560: 	    
  561: 	    g=re.search(r"(.*/)(.*)\n",line)
  562: 	    if not g==None:
  563:                   try:
  564:                         path=g.group(1)
  565:                         file=g.group(2)
  566:                   except:
  567:                         """nothing"""
  568:                   if self.node.has_key(path):
  569: 	       	     elements=self.node[path]
  570: 	             elements.append(file)
  571: 	             self.node[path]=elements
  572:                   else:
  573: 		     self.node[path]=[file]
  574:                   if (file=="index.meta") | (file=="meta"):
  575:                      self.hasindex[path]="1"
  576:        
  577:       def __init__(self,start,reload=0):
  578:            """nothing"""
  579:            
  580:            
  581:       security.declarePublic('getImageDirs')
  582:       def getImageDirs(self,dom,path):
  583:       	  dirs=dom.getElementsByTagName("dir")
  584: 	  dirback=[]
  585: 	  for dir in dirs:
  586: 	      temp=getText(dir.getElementsByTagName("name")[0].childNodes)
  587: 	      temp2=re.search(r"(.*)/mpiwg/online/(.*)",path+"/"+temp)
  588: 	      if not temp2==None:
  589:                     try:
  590:                           dirback.append(temp2.group(2))
  591:                     except:
  592:                           """nothing"""
  593: 	      else:
  594:  		dirback.append(temp)
  595:           return dirback
  596:       
  597:          
  598:       security.declarePublic('digilib')	  
  599:       def digilib(self, path):
  600:       	  """check if folder is a container for digilib files"""
  601: 	  if os.path.exists(path+"/index.meta"):
  602: 	        return(self.parseIndexMeta(path))
  603: 	  else:
  604: 		return "NO"
  605: 
  606:       security.declarePublic('isdigilib')	  
  607:       def isdigilib(self, path):
  608:       	  if os.path.exists(path+"/index.meta"):
  609: 	     return(len(self.parseIndexMeta(path)))
  610: 	  else:
  611: 	     return 0
  612:       security.declarePublic('parseIndexMeta')
  613:       def parseIndexMeta(self,k):
  614:       	  """parse indexmeta and return digilib path"""
  615:       	  f = os.popen("cat "+k+"/index.meta","r")
  616:           lines = f.read()
  617: 	  
  618:           try:
  619: 	   dom = xml.dom.minidom.parseString(lines)
  620: 	   content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
  621:        	   if content_type=="scanned-document":
  622: 	           dirs=self.getImageDirs(dom,k)
  623: 	  	
  624: 	   return dirs
  625: 	  except:
  626: 	   return []
  627:    	  
  628: 	  
  629: class browse(Implicit, Persistent, RoleManager):
  630:       
  631:       security=ClassSecurityInfo()
  632:       tree={}
  633:       toggledict={}
  634: 
  635:       def filterExcluded(self,dir):
  636: 	  ret=[]
  637: 	  for item in dir:
  638: 		if not item in exclusion:
  639: 			ret.append(item) 
  640: 	  return ret
  641: 	
  642:       def __init__(self,startpath):
  643:       	  self.tree={}
  644: 	  self.tree[startpath]=self.filterExcluded(dircache.listdir(startpath))
  645: 
  646:       security.declarePublic('getTree')
  647:       def getTree(self,path):	
  648:       	  if self.tree.has_key(path):
  649: 	            return self.tree[path]
  650:           else:
  651: 	     self.tree[path]=self.filterExcluded(dircache.listdir(path))
  652: 	     return self.tree[path]
  653:       
  654:       security.declarePublic('isDirectory')
  655:       def isDirectory(self,path,file):	
  656:       	  return os.path.isdir(os.path.abspath(path+"/"+file))
  657:       
  658:       security.declarePublic('toggle')
  659:       def toggle(self,tmppath,file):
  660:       	  path=tmppath+"/"+file
  661: 	  
  662:       	  if self.toggledict.has_key(path):
  663: 	     if self.toggledict[path]==0:
  664: 	     	self.toggledict[path]=1
  665: 		
  666: 	     else:
  667: 	        self.toggledict[path]=0
  668:                 
  669:           else:
  670: 	     self.toggledict[path]=4
  671: 	     
  672: 
  673:       security.declarePublic('isToggle')
  674:       def isToggle(self,tmppath,file):
  675:       	  path=tmppath+"/"+file
  676: 
  677: 	  if self.toggledict.has_key(path):
  678: 		
  679: 	        return self.toggledict[path]
  680:           else:
  681: 		
  682: 		return 0      
  683: 
  684:       
  685: def getfs(start):
  686: 	"""return filesystem"""
  687:         
  688: 
  689:         f = os.popen("find "+ start+" -name '*'","r")
  690: 	lines = f.readlines()
  691:         return lines
  692: 
  693: def showall(start):
  694: 	lines = getfs(start)
  695: 	for line in lines:
  696: 	    print line
  697:         return 0
  698: 
  699: def entries(start):
  700: 	"""retrun list of entries of a filesystem"""
  701: 	i=0
  702: 	fs=[]
  703: 	lines=getfs(start)
  704: 	for line in lines:
  705:             try:
  706:                   if os.path.exists(os.path.abspath(re.search(r"(.*)\n",line).group(1))):
  707:                         fs.append(fsentry(line))
  708:                         i=i+1
  709:             except:
  710:                   """nothing"""
  711: 	return fs
  712: 
  713: def getfilesystem(start,reload=0):
  714: 	"""load filesystem"""
  715: 	
  716: 	k=filesystem(start,1)
  717: 	return k
  718: 
  719: 
  720: 
  721: def sort_by_date(fs):
  722: 	"""sorts lists of fileentries"""
  723: 	ls=[]
  724: 	dict={}
  725: 	for k in fs:
  726:             ls.append(k.getID())
  727: 	    dict[k.getID()]=k
  728: 	ls.sort()
  729:         ls.reverse()
  730:         ret=[]
  731: 	for j in ls:
  732: 	    ret.append(dict[j])
  733:         return ret
  734: 
  735: def path_to_link(path):
  736:     """generates navigation bar for showfiles"""
  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=showfiles?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
  753: 	  
  754: 	  i=i-1
  755:     return string
  756: 
  757: def path_to_link_view(URL,path):
  758:     """generates navigation bar for viewfiles"""
  759:     string=""
  760:     
  761:     tmppath=os.path.dirname(path)
  762:     i=0
  763:     pathes=[[path, os.path.basename(path)]]
  764:     
  765:     while not (len(tmppath)==1):
  766:     	  
  767:     	  i=i+1
  768: 	  if i>20: break
  769: 	  
  770:     	  pathes.append([tmppath, os.path.basename(tmppath)])
  771:     	  tmppath=os.path.dirname(tmppath)
  772: 
  773:     while i>=0:
  774:     	  string=string+"<a href="+URL+"?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
  775: 	  
  776: 	  i=i-1
  777:     return string
  778: 
  779: def path_to_link_store(URL,path):
  780:     """generates navigation bar for viewfiles"""
  781:     string=""
  782:     
  783:     tmppath=os.path.dirname(path)
  784:     i=0
  785:     pathes=[[path, os.path.basename(path)]]
  786:     
  787:     while not (len(tmppath)==1):
  788:     	  
  789:     	  i=i+1
  790: 	  if i>20: break
  791: 	  
  792:     	  pathes.append([tmppath, os.path.basename(tmppath)])
  793:     	  tmppath=os.path.dirname(tmppath)
  794: 
  795:     while i>=0:
  796:     	  string=string+"<a href="+URL+"?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
  797: 	  
  798: 	  i=i-1
  799:     return string
  800: 
  801: 
  802: class Error(Implicit, Persistent, RoleManager):
  803: 	
  804: 	error=[]
  805:     	security=ClassSecurityInfo()
  806: 	def __init__(self,initerror):
  807:               self.error=initerror[0:]
  808: 
  809: 	security.declarePublic('getError')
  810: 	def getError(self):
  811: 		return self.error
  812: 
  813: class metacheck(Implicit, Persistent, RoleManager):
  814:         lines=[]
  815: 	security=ClassSecurityInfo()
  816: 	def parsearchive(self,str):
  817:     		"""parse for error"""
  818:     		retstr=''
  819:                 
  820:                 if not len(str)==0:
  821:                       for line in str:
  822:                             retstr=retstr+line+"<br>"
  823:                       check=re.search(r"(.*):(.*)",line)
  824:                       if check.group(1)=='ABORT':
  825:                             error="error"
  826:                       elif check.group(1)=='DONE':
  827:                             error="ok"
  828:                       else:
  829:                             error="running"
  830:                             
  831:                       return [retstr,error]
  832:                 else:
  833:                       return ['','running']
  834: 	def __init__(self,path):
  835: 		"""archive the documents in path"""
  836:     		self.lines=[]
  837: 		
  838: 	        if type(path)==StringType:
  839: 			f = os.popen("/usr/local/mpiwg/archive/metacheck "+path,"r")
  840:      			self.lines.append(Error([path,self.parsearchive(f.readlines())]))
  841: 		else:
  842:     			for singlepath in path:
  843:      				f = os.popen("/usr/local/mpiwg/archive/metacheck "+singlepath,"r")
  844:      				self.lines.append(Error([singlepath,self.parsearchive(f.readlines())]))
  845:         security.declarePublic('messages')
  846: 	
  847: 	def messages(self):
  848: 		return self.lines
  849: 	
  850: 		
  851: 
  852: 
  853: class archive(Implicit, Persistent, RoleManager):
  854:       lines=[]
  855:       security=ClassSecurityInfo()
  856:       def parsearchive(self,str):
  857:             """parse for error"""
  858:             retstr=''
  859:             
  860:             if not len(str)==0:
  861:                   for line in str:
  862:                         retstr=retstr+line+"<br>"
  863:                   check=re.search(r"(.*):(.*)",line)
  864:                   if check.group(1)=='ABORT':
  865:                         error="error"
  866:                   elif check.group(1)=='DONE':
  867:                         error="ok"
  868:                   else:
  869:                         error="running"
  870:                   
  871:                   return [retstr,error]
  872:             else:
  873:                   return ['','running']
  874:                   
  875:       def __init__(self,path,session):
  876:             """archive the documents in path"""
  877:             self.lines=[]
  878:             self.filenames={}
  879:             session['archiver']=self
  880:            
  881:            
  882:             if type(path)==StringType:
  883:                   self.filenames[path]=tempfile.mktemp()
  884:                   f = os.popen("/usr/local/mpiwg/archive/archiver "+path+" > "+self.filenames[path]+" &","r")
  885:             else:
  886:                   for singlepath in path:
  887:                         self.filenames[singlepath]=tempfile.mktemp()
  888:                         f = os.popen("/usr/local/mpiwg/archive/archiver "+singlepath+" > "+self.filenames[singlepath]+" &","r")
  889:                             
  890:       security.declarePublic('messages')
  891:       def messages(self):
  892:             self.lines=[]
  893:             for path in self.filenames.keys():
  894:                   
  895:                   self.lines.append(Error([path,self.parsearchive(open(self.filenames[path],"r").readlines())]))
  896:             return self.lines
  897: 
  898: 	
  899: def evalext(str):
  900:      return eval(str)
  901: 
  902: def storeerror(ret,path,context,i):
  903:      session=context.REQUEST.SESSION
  904:      session['error%i'%i]=ret
  905:      session['path%i'%i]=path
  906:      
  907:      return 'error?number=%i'%i
  908: 
  909: def geterror(str,context):
  910:      session=context.REQUEST.SESSION
  911:      return session[str]
  912: 
  913: def readfile(path):
  914:      
  915:      ret=""
  916:      f=open(path,'r')
  917:      for g in f.readlines():
  918: 	ret=ret+g
  919:      return ret
  920: 
  921: def writefile(self,path,txt,REQUEST):
  922:      f=open(path,'w')
  923:      f.write(txt)
  924:      f.close()
  925:      rval=self.aq_acquire('archive2')
  926:      return rval()
  927: 
  928: 
  929: def metachecker(self,path):
  930:     """check the metadata the documents in path"""
  931:     self.REQUEST.SESSION['path']=self.REQUEST['path']
  932:     return metacheck(path)
  933: 
  934: def archiver(self,path):
  935:     """archive the documents in path"""
  936:     tmp=archive(path,self.REQUEST.SESSION)
  937:     return self.REQUEST.RESPONSE.redirect('archive4')
  938: 
  939: def getText(nodelist):
  940:     
  941:     rc = ""
  942:     for node in nodelist:
  943:     	if node.nodeType == node.TEXT_NODE:
  944:            rc = rc + node.data
  945:     return rc
  946: 
  947: def getBib(nodelist):
  948:     rc= "<table border='0'>"
  949:     
  950:     for node in nodelist:
  951:         
  952:     	if node.nodeType == node.ELEMENT_NODE:
  953: 	   """nothing"""
  954: 	   rc = rc+"<tr><td valign='right'>"+str(node.nodeName)+":</td><td> "+getText(node.childNodes)+"</td></tr>"
  955:     #print rc
  956:     return rc+"</table>"
  957: 
  958: def getMetafile(path):
  959:     """get index.meta and translate it to an HTML"""
  960:     html=[]
  961:     if not os.path.exists(path+"/index.meta"):
  962:           
  963:           return "NO_METADATA"
  964:     else:
  965:        f = os.popen("cat "+path+"/index.meta","r")
  966:        lines = f.read()
  967:        dom = xml.dom.minidom.parseString(lines)
  968:        try:
  969:            name=getText(dom.getElementsByTagName("name")[0].childNodes)
  970:        except:
  971:            name="NOT_DEFINED!!!"
  972:        try:
  973:            creator=getText(dom.getElementsByTagName("creator")[0].childNodes)
  974:        except:
  975:            creator="NOT_DEFINED!!!"
  976: 
  977:        try:
  978:            creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes)
  979:        except:
  980:            creation_date="NOT_DEFINED!!!"
  981: 
  982:        try:
  983:            description=getText(dom.getElementsByTagName("description")[0].childNodes)
  984:        except:
  985:            description="NOT_DEFINED!!!"
  986:            
  987:        try:
  988:        	type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
  989:        except:
  990:         type=""
  991:        if type=="scanned document":
  992: 		html="<h3>Document: "+name+"</h3>"
  993:        elif type=="folder":
  994: 		html="<h3>Folder: "+name+"</h3>"
  995:        else:
  996:        		html="<h3>Document: "+name+"</h3>"
  997: 
  998:        html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>" 
  999:        html=html+"<h4>Description</h4><p>"+description+"</p>"
 1000:        try:
 1001:         bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0]
 1002:         if bib.attributes.has_key('type'):
 1003: 	  html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>"
 1004: 	else:
 1005: 	  html=html+"<h4>Info</h4>"
 1006:         html=html+getBib(bib.childNodes)
 1007:         
 1008:        except:
 1009:         """none"""
 1010:        
 1011: #        html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace')
 1012:        
 1013:        return html
 1014: 
 1015: def hasMetafile(path):
 1016:     """get index.meta"""
 1017:     return os.path.exists(path+"/index.meta")
 1018:     #return path
 1019: 
 1020: 
 1021: 
 1022: def isdigilib2(path):
 1023: 	  """check if folder is candidate for digilib without metadata""" 
 1024:           try:
 1025:                 dir=os.listdir(path)
 1026: 
 1027:                 imagesuffixes=['.gif','.jpg','.jpeg','.png','.tiff','.tif','.JPG','.TIFF','.TIF']
 1028:                 ret=""
 1029:                 for a in dir:
 1030:                       
 1031:                       suffix=os.path.splitext(a)
 1032: 		
 1033:                       if suffix[1] in imagesuffixes:
 1034:                             return 1
 1035: 
 1036:                 try:
 1037:                       dom=xml.dom.minidom.parse(os.path.split(path)[0]+"/index.meta")
 1038:                       for node in dom.getElementsByTagName("dir"):
 1039:                   
 1040:                             if getText(node.getElementsByTagName("content-type")[0].childNodes)=="images":
 1041:                         
 1042:                                   if getText(node.getElementsByTagName("name")[0].childNodes)==os.path.split(path)[1]:
 1043:                                         return 1
 1044:                       return 0
 1045:                 except:
 1046:             
 1047:                       return 0
 1048: 
 1049: 
 1050:                 
 1051:                 
 1052: 
 1053:           except:
 1054:                 return 0
 1055: 
 1056: def isFullText(path,folder_name):
 1057:       """check if foldername in path is full text"""
 1058:       try:
 1059:             dom=xml.dom.minidom.parse(path+"/index.meta")
 1060:             for node in dom.getElementsByTagName("dir"):
 1061:                   
 1062:                   if getText(node.getElementsByTagName("content-type")[0].childNodes)=="fulltext":
 1063:                         
 1064:                         if getText(node.getElementsByTagName("name")[0].childNodes)==folder_name:
 1065:                               return 1
 1066:             return 0
 1067:       except:
 1068:             
 1069:             return 0
 1070: 
 1071: 
 1072: def isPresentation(path,folder_name):
 1073:       """check if foldername in path is full text"""
 1074:       try:
 1075:             dom=xml.dom.minidom.parse(path+"/index.meta")
 1076:             #print dom.toxml()
 1077:             for dirnode in dom.getElementsByTagName("dir"):
 1078:                   try:
 1079:                          
 1080:                         if getText(dirnode.getElementsByTagName('content-type')[0].childNodes)=='presentation':
 1081:                               if getText(dirnode.getElementsByTagName("name")[0].childNodes)==folder_name:
 1082:                                     return 1
 1083:                   except:
 1084:                         """nothing"""
 1085:             return 0
 1086:       except:
 1087:             
 1088:             return 0
 1089:                   
 1090:                   
 1091:                         
 1092: 
 1093: 
 1094: def changeName(path):
 1095:       try:
 1096:          temp2=re.search(r"(.*)/mpiwg/online/(.*)",path)
 1097: 	 if temp2==None:	 
 1098: 			return "digifiles/"+re.search(r"(.*)/mpiwg/production/docuserver/(.*)",path).group(2)
 1099: 	 else:	
 1100: 	  		return temp2.group(2)
 1101:       except: # hack - im archivbereich keine online darstellung gibt jetzt ein no zurück.
 1102:             return "NO"
 1103: 
 1104: 	
 1105: def test(self):
 1106:         self.i=1
 1107:       	#newtemplate=PageTemplateFile('/usr/local/mpiwg/Zope/Extensions/test').__of__(self)
 1108:         self.manage_addProduct['OFSP'].manage_addDTMLMethod('neu','neu')
 1109:         self.getattr('neu').manage_edit('HELLO','neu')
 1110:         return "ok"
 1111: 
 1112: 
 1113: class ls(Implicit, Persistent, RoleManager):
 1114:       """File entry class"""
 1115:       path = ""
 1116:       user = ""
 1117:       month = ""
 1118:       date =""
 1119:       time = ""
 1120:       
 1121:       security=ClassSecurityInfo()
 1122: 
 1123:       def __init__(self,start):
 1124:             self.outfile=tempfile.mktemp()
 1125:             start['outfile']=self
 1126:             os.popen("ls -R / >"+self.outfile+" &","r")
 1127:             
 1128:             
 1129:       security.declarePublic('read')
 1130:       def read(self):
 1131:             return self.f.read()
 1132:       security.declarePublic('retself')
 1133:       def retself(self):
 1134:             return self
 1135:       security.declarePublic('all')
 1136:       def all(self):
 1137:             ret=""
 1138:             for g in self.f:
 1139:                   ret=ret+g
 1140:             return ret
 1141: 
 1142:       security.declarePublic('printOutfile')
 1143:       def printOutfile(self):
 1144:             while not os.path.exists(self.outfile):
 1145:                   """nothing"""
 1146:             return open(self.outfile).readlines()
 1147:       
 1148: class overview(Implicit,Persistent, RoleManager):
 1149:       dir=[]
 1150:       resources={}
 1151:       security=ClassSecurityInfo()
 1152:       
 1153:       def __init__(self,path):
 1154:             dir=os.listdir(path)
 1155:             
 1156:             for file in dir:
 1157:                   self.resources[self.getResource(path,file)]=path+"/"+file
 1158:         
 1159:             
 1160:       def getResource(self,path,filename):
 1161:             f=file(path+"/"+filename,'r')
 1162:       
 1163:             for line in f.readlines():
 1164:                   
 1165:                   if line[0:4]=="INFO":
 1166:                         if line[6:14]=="resource":
 1167:                               return line
 1168:             return "error"
 1169: 
 1170:       def parsearchive(self,str):
 1171:             """parse for error"""
 1172:             retstr=''
 1173:             
 1174:             if not len(str)==0:
 1175:                   for line in str:
 1176:                         retstr=retstr+line+"<br>"
 1177:                   check=re.search(r"(.*):(.*)",line)
 1178:                   if check.group(1)=='ABORT':
 1179:                         error="error"
 1180:                   elif check.group(1)=='DONE':
 1181:                         error="ok"
 1182:                   else:
 1183:                         error="running"
 1184:                   
 1185:                   return [retstr,error]
 1186:             else:
 1187:                   return ['','running']
 1188: 
 1189:       security.declarePublic('messages')
 1190:       def messages(self):
 1191:             self.lines=[]
 1192:             for name in self.resources.keys():
 1193:                   path=self.resources[name]
 1194:                   
 1195:                   self.lines.append(Error([name,self.parsearchive(open(path,"r").readlines())]))
 1196:             return self.lines
 1197: 
 1198:       security.declarePublic('printResource')
 1199:       def printResource(self):
 1200:             return self.resources
 1201:       
 1202: def getoverview(path):
 1203:       
 1204:       return overview(path)
 1205: 
 1206:       
 1207: def ls_test(self):
 1208:       tmp=ls(self.REQUEST.SESSION)
 1209:       return self.REQUEST.RESPONSE.redirect('next')
 1210: 
 1211: def storeFile(self,something):
 1212:       self.REQUEST.SESSION['something']=something
 1213:       return 1
 1214: 
 1215: def getFile(self):
 1216:       return self.REQUEST.SESSION['something']
 1217: 
 1218: def isFolder(self,path):
 1219:       """returns TRUE, wenn path ein Folder ist in den weitere Objekte Folder oder Dokumente gelegt werden dürfen"""
 1220:       return not isScannedDocument(self,path) # vorläufig sind alle Documente die keine scanned documente sind folder.
 1221: 
 1222: def isScannedDocument(self,path):
 1223:       """returns TRUE, wenn path der Stammordner eines gescannten Documents ist"""
 1224:       try:
 1225:             f = file(path+"/index.meta","r")
 1226:             lines = f.read()
 1227:       
 1228:             try:
 1229:                   dom = xml.dom.minidom.parseString(lines)
 1230:                   content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) 
 1231:                   if (content_type=="scanned-document") or (content_type=="scanned document") or (content_type=="fulltext document"):
 1232:                         return 1
 1233:                   else:
 1234:                         return 0
 1235:             except:
 1236:                   return 0
 1237:       except:
 1238:             return 0
 1239: 
 1240: from time import localtime,strftime
 1241: 
 1242: def date(self):
 1243: 	return strftime("%d.%m.%Y",localtime())	
 1244: 
 1245:       
 1246:       

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