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