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