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