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