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