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