File:  [Repository] / OSAS / OSA_system / OSAS_show.py
Revision 1.24: download - view: text, annotated - select for diffs - revision graph
Thu Jul 1 07:46:42 2004 UTC (20 years ago) by dwinter
Branches: MAIN
CVS tags: HEAD
minors

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

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