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