Annotation of OSAS/OSA_system/OSAS_archiver.py, revision 1.4
1.1 dwinter 1: # Methoden und Klassen fuer den MPIWG Archiver
2:
3: from OFS.Image import Image
4: from OFS.Folder import Folder
5: from OFS.SimpleItem import SimpleItem
6: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
7: from Products.PageTemplates.PageTemplate import PageTemplate
8: from AccessControl import ClassSecurityInfo
9: from Globals import InitializeClass
10: from Globals import Persistent
11: from Acquisition import Implicit
12: from OSAS_show import *
1.3 dwinter 13: from OSAS_helpers import *
1.1 dwinter 14:
15: import os.path
16: import os
17: import OSAS_ids
18: import archive #Baustelle
1.3 dwinter 19: import time
20:
21: class OSAS_archiveInbox(SimpleItem,Persistent,Implicit):
22: """Inbox"""
23:
24: meta_type="OSAS_archiveInbox"
25: pathes=[]
26:
27: def __init__(self,id,title):
28: """init"""
29: self.id=id
30: self.title=title
31: self.pathes=[]
32:
33: def addPath(self,path):
34: today=time.localtime()
35: self.pathes.append([path,today])
36:
37: def index_html(self):
38: """main"""
39: pt=PageTemplateFile('Products/OSA_system/OSAS_archiveInboxIndex.zpt').__of__(self)
40: return pt()
41:
42: def manage_AddOSAS_archiveInboxForm(self):
43: """interface for adding the OSAS_root"""
44: pt=PageTemplateFile('Products/OSA_system/AddOSAS_archiveInbox.zpt').__of__(self)
45: return pt()
46:
47:
48: def manage_AddOSAS_archiveInbox(self,id,title="",RESPONSE=None):
49: """add the OSAS_root"""
50: if title=="":
51: title=id
52:
53: newObj=OSAS_archiveInbox(id, title)
54: self._setObject(id,newObj)
55: if RESPONSE is not None:
56: RESPONSE.redirect('manage_main')
57:
58:
1.1 dwinter 59:
60: class OSAS_metadataOrganizer(SimpleItem,Persistent,Implicit):
61: """Eingabe von Metadaten"""
62:
63: meta_type="OSAS_metadataOrganizer"
1.3 dwinter 64: mediaTypes=["image","video","text","audio","data"]
65: acquisitionTypes=["Image-Acquisition"]
66: mediaToAcquisition={"image":"Image-Acquisition"}
67: metaDataSets={'Image-Acquisition': [('device','opt'),('image-type','opt'),('production-comment','opt')]}
68: imgData={'image':[('dpi','req')]}
69:
70: bibDataSets={'Book':[('author','opt'),('year','opt'),('title','opt'),('series editor','opt'),('series title','opt'),('series volume','opt'),('number of pages','opt'),('city','opt'),('publisher','opt'),('edition','opt'),('number of volumes','opt'),('translator','opt'),('ISBN ISSN','opt')],
71: 'Journal Article':[('author','opt'),('year','opt'),('title','opt'),('journal','opt'),('volume','opt'),('issue','opt'),('pages','opt'),('alternate journal','opt'),('call number','opt')],
72: 'Manuscript':[('author','opt'),('year','opt'),('title','opt'),('location','opt'),('signature','opt'),('pages','opt'),('editorial remarks','opt'),('description','opt'),('keywords','opt')]}
73:
74:
75: referenceTypes=['Book','Journal Article','Manuscript']
1.1 dwinter 76:
77: def __init__(self,id,title):
78: """init"""
79: self.id=id
80: self.title=title
81: #self.acquisitionData=['provider_name','provider_address','provider_contact','provider_url','date','description']
82:
83: def addAcquisition(self,path):
84: """Hinzufügen von Acquisition Daten"""
85: self.REQUEST.SESSION['path']=path
86: pt=PageTemplateFile('Products/OSA_system/inputAcquisitionData.zpt').__of__(self)
87: return pt()
88:
1.3 dwinter 89: def writeAcquisitionMetadata(self,date,path,media_type,producer="mpiwg",description=""):
1.1 dwinter 90: """Schreibe Acquisiondata in index.meta"""
91:
1.3 dwinter 92:
93: #schreibe in index.meta
94: subnodes={}
95: subnodes['media-type']=media_type
96: changeNodesInIndexMeta(path,"",subnodes)
97:
98: subnodes={}
99: subnodes['date']=date
100: subnodes['description']=description
101:
102: changeNodesInIndexMeta(path,"acquisition",subnodes)
103: #print "HI"
104:
105: subnodes={}
106: subnodes['provider-id']=producer
107: subnodes['url']=getattr(self.producerFolder,producer).url
108: subnodes['contact']=getattr(self.producerFolder,producer).contact
109: subnodes['address']=getattr(self.producerFolder,producer).address
110:
111: changeNodesInIndexMeta(path,"provider",subnodes,parent="acquisition")
112:
113:
114: self.metaDataSet=self.metaDataSets[self.mediaToAcquisition[media_type]]
115: self.media_type=self.mediaToAcquisition[media_type]
116:
117: pt=PageTemplateFile('Products/OSA_system/inputDocumentMetadata.zpt').__of__(self)
118: return pt()
119:
120:
121: def writeDocumentMetadata(self,referenceType):
122:
123: """write document metadata"""
124: form=self.REQUEST.form
125: #schreibe in index.meta
126: self.bibDataSet=self.bibDataSets[form['referenceType']]
127: self.bibdata_type=form['referenceType']
128:
129: subnodes={}
130: subnodes['device']=form['device']
131: subnodes['image-type']=form['image-type']
132: subnodes['production-comment']=form['production-comment']
133: changeNodesInIndexMeta(self.REQUEST.SESSION['path'],"image-acquisition",subnodes)
134:
135: subnodes={}
136: subnodes['dpi']=form['dpi']
137:
138:
139: changeNodesInIndexMeta(self.REQUEST.SESSION['path'],"img",subnodes)
140:
141:
142: pt=PageTemplateFile('Products/OSA_system/inputBiblioMetadata.zpt').__of__(self)
143: return pt()
144:
145: def writeBiblioMetadata(self,bibdata_type,RESPONSE=None):
146: """Write all"""
147: #to do write metadata
148:
149: subnodes={}
150: form=self.REQUEST.form
151: #for key in form.keys():
152: # subnodes[key]=form['device']
153: subnodes=form
154: changeNodesInIndexMeta(self.REQUEST.SESSION['path'],"bib",subnodes,nodeAttributes={'type':bibdata_type},parent="meta")
155: self.inbox.addPath(self.REQUEST.SESSION['path'])
156: RESPONSE.redirect(self.REQUEST['URL2'])
157:
158:
159:
160:
161:
162:
163:
1.1 dwinter 164: def manage_AddOSAS_metadataOrganizerForm(self):
165: """interface for adding the OSAS_root"""
166: pt=PageTemplateFile('Products/OSA_system/AddOSAS_metadataOrganizer.zpt').__of__(self)
167: return pt()
168:
169:
170: def manage_AddOSAS_metadataOrganizer(self,id,title="",RESPONSE=None):
171: """add the OSAS_root"""
172: if title=="":
173: title=id
174:
175: newObj=OSAS_metadataOrganizer(id, title)
176: self._setObject(id,newObj)
177: if RESPONSE is not None:
178: RESPONSE.redirect('manage_main')
179:
180:
181: class OSAS_processViewer(SimpleItem,Persistent,Implicit):
182: """Process viewer for archiving"""
183:
184: meta_type="OSAS_processViewer"
185:
186: def __init__(self, id, title):
187: """init"""
188: self.id=id
189: self.title=title
190:
191: def index_html(self):
192: """main page"""
193: pt=PageTemplateFile('Products/OSA_system/processViewerIndex.zpt').__of__(self)
194: return pt()
195:
196: def storeFile(self,something):
197: """store info in session"""
198: self.REQUEST.SESSION['something']=something
199: return 1
200:
201: def getFile(self):
202: """get info from session"""
203: return self.REQUEST.SESSION['something']
204:
205: def getoverview(self,path):
206: """get overview"""
207: return archive.overview(path)
208:
209: def storeerror(self,ret,path,context,i):
210: """store an error"""
211: session=context.REQUEST.SESSION
212: session['error%i'%i]=ret
213: session['path%i'%i]=path
214:
215: return 'error?number=%i'%i
216:
1.4 ! dwinter 217: def geterror(self,str,context):
! 218: session=context.REQUEST.SESSION
! 219: return session[str]
! 220:
! 221:
! 222: def readfile(self,path):
! 223:
! 224: ret=""
! 225: f=open(path,'r')
! 226: for g in f.readlines():
! 227: ret=ret+g
! 228: return ret
! 229:
! 230: def writefile(self,path,txt,REQUEST):
! 231: f=open(path,'w')
! 232: f.write(txt)
! 233: f.close()
! 234: rval=self.aq_acquire('archive2')
! 235: return rval()
! 236:
! 237:
1.1 dwinter 238: def view(self):
239: """view page"""
240: pt=PageTemplateFile('Products/OSA_system/processViewerView.zpt').__of__(self)
241: return pt()
1.4 ! dwinter 242:
! 243: def error(self):
! 244: """view errors"""
! 245: pt=PageTemplateFile('Products/OSA_system/processViewerError.zpt').__of__(self)
! 246: return pt()
1.1 dwinter 247:
248: def manage_AddOSAS_processViewerForm(self):
249: """interface for adding the OSAS_processViewer"""
250: pt=PageTemplateFile('Products/OSA_system/AddOSAS_processViewer.zpt').__of__(self)
251: return pt()
252:
253:
254: def manage_AddOSAS_processViewer(self,id,title="",RESPONSE=None):
255: """add the OSAS_processViewer"""
256: if title=="":
257: title=id
258:
259: newObj=OSAS_processViewer(id, title)
260: self._setObject(id,newObj)
261: if RESPONSE is not None:
262: RESPONSE.redirect('manage_main')
263:
264:
265:
266: class OSAS_archiver(Folder, Persistent,Implicit):
267: """Hauptklasse fuer das Archiv"""
268:
269: meta_type="OSAS_archiver"
270:
271: # to be deleted later
272: #startPath="/mpiwg"
273: ## methoden aus dem alten archive.py
274:
1.3 dwinter 275:
276:
1.1 dwinter 277: def archiver(self,path):
278: """archive the documents in path"""
279: tmp=archive.archive(path,self.REQUEST.SESSION)
280: pt=PageTemplateFile('Products/OSA_system/archiveStatus.zpt').__of__(self)
281: return pt()
282:
283:
284:
285:
286: def metachecker(self,path):
287: """check the metadata the documents in path"""
288: self.REQUEST.SESSION['path']=self.REQUEST['path']
289: return archive.metacheck(path)
290:
291: ## methods from OSAS_show
292: def changeName(self,name):
293: return changeName(name)
294:
295: def hasMetafile(self,path):
296: return hasMetafile(path)
297:
298: def getMetafile(self,path):
299: return getMetafile(path)
300:
301: def toggle_view(self,path,file):
302: """Oeffnen bzw. schließen der Subfolders"""
303: self.tree(path).toggle(path,file)
304: return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+"?path="+path)
305:
306:
307:
308: def isdigilib2(self,path):
309: """check if digilib"""
310: return isdigilib2(path)
311:
312: def path_to_link_view(self,path):
313: """generates navigation bar for viewfiles"""
314: return path_to_link_view(self.REQUEST['URL'],path)
315:
316:
317: def tree(self,start):
318: """get the filetree"""
319: k=browse(start)
320: return k
321:
322: def getfilesystem2(self,start,reload=0):
323: """load filesystem"""
324:
325: k=filesystem2(start,1)
326: return k
327:
328: def getfilesystem(self,start,reload=0):
329: """load filesystem"""
330:
331: k=filesystem(start,1)
332: return k
333:
334:
335: ##init
336: def __init__(self, id, title,startPath):
337: """init"""
338: self.id=id
339: self.title=title
340: self.startPath=startPath
341:
342: def archiver_html(self):
343: """archiver"""
344: pt=PageTemplateFile('Products/OSA_system/OSAS_Archiver.zpt').__of__(self)
345: return pt()
346:
347: def index_html(self):
348: """main page"""
349: pt=PageTemplateFile('Products/OSA_system/archiverIndex.zpt').__of__(self)
350: return pt()
1.3 dwinter 351:
352: def getDate(self):
353: """date"""
354: return time.strftime("%Y-%m-%d",time.localtime())
1.1 dwinter 355:
356: def newFolders_html(self):
357: """main page"""
358: pt=PageTemplateFile('Products/OSA_system/newFolders.zpt').__of__(self)
359: return pt()
360:
361: def getProducers(self):
362: """Ausgabe der registrierten Benutzer"""
363: ret=[]
1.3 dwinter 364: #x=7
365: id=self.producerFolder.getId()
1.1 dwinter 366: for list in self.producerFolder.__dict__:
367: obj=getattr(self.producerFolder,list)
368: if (hasattr(obj,"meta_type")):
369: if (obj.meta_type=="OSAS_producer"):
370: ret.append(obj.getId())
371: return ret
372:
373: def getProducer(self,id):
374: """Gebe ProducerObjekt zurück"""
375: obj=getattr(self.aq_parent.producerFolder,id)
376: return obj
377:
378:
379:
380: def createFoldersForm(self,producer,number):
381: """Erzeuge Folder im producer Verzeichnis mit ids"""
382: self.REQUEST.SESSION['producer']=producer
383: self.REQUEST.SESSION['ids']=self.idGenerator.giveIdsOut(number)
384: pt=PageTemplateFile('Products/OSA_system/createFoldersForm.zpt').__of__(self)
385: return pt()
386:
387: def createFolders(self,folderList,producer):
388: """Erzeug die entsprechenden Folder"""
389: for folder in folderList:
390: os.mkdir(self.startPath+"/"+producer+"/"+folder)
391: self.REQUEST.SESSION['folderList']=folderList
392: pt=PageTemplateFile('Products/OSA_system/createFolders.zpt').__of__(self)
393: return pt()
394:
1.4 ! dwinter 395: def storeerror(self,ret,path,context,i):
! 396: """store an error"""
! 397: session=context.REQUEST.SESSION
! 398: session['error%i'%i]=ret
! 399: session['path%i'%i]=path
! 400:
! 401: return 'error?number=%i'%i
! 402:
! 403: def geterror(self,str,context):
! 404: session=context.REQUEST.SESSION
! 405: return session[str]
! 406:
! 407: def readfile(self,path):
! 408:
! 409: ret=""
! 410: f=open(path,'r')
! 411: for g in f.readlines():
! 412: ret=ret+g
! 413: return ret
! 414:
! 415: def writefile(self,path,txt,REQUEST):
! 416: f=open(path,'w')
! 417: f.write(txt)
! 418: f.close()
! 419: rval=self.aq_acquire('archive2')
! 420: return rval()
! 421:
! 422: def error(self):
! 423: """view errors"""
! 424: pt=PageTemplateFile('Products/OSA_system/processViewerError.zpt').__of__(self)
! 425: return pt()
! 426:
! 427:
1.1 dwinter 428: def archiveSelected(self):
429: """Archiviere ausgewaehlte files"""
430: pt=PageTemplateFile('Products/OSA_system/archiveSelected.zpt').__of__(self)
431: return pt()
432:
433: def enterAcquisitionMetadata(self):
434: """Erstelle Metadaten fuer Acquisition"""
435:
436: def enterPreliminaryBibMeta(self):
437: """Erstelle Metadaten fuer Bibliography"""
438:
439: def showFilesForArchiving(self):
440: """Anzeige der noch zu archivieren Files"""
441:
442:
443:
444:
445:
446: def manage_AddOSAS_archiverForm(self):
447: """interface for adding the OSAS_root"""
448: pt=PageTemplateFile('Products/OSA_system/AddOSAS_archiver.zpt').__of__(self)
449: return pt()
450:
451:
452: def manage_AddOSAS_archiver(self,id,startPath,title="",RESPONSE=None):
453: """add the OSAS_root"""
454: if title=="":
455: title=id
456:
457: newObj=OSAS_archiver(id, title,startPath)
458: self._setObject(id,newObj)
459: if RESPONSE is not None:
460: RESPONSE.redirect('manage_main')
461:
462:
1.3 dwinter 463: class OSAS_producer(SimpleItem,Persistent,Implicit):
1.2 dwinter 464: """Klasse fuer Produzenteninformationen
465: Metadaten nach V1.1.1"""
1.1 dwinter 466:
467: meta_type="OSAS_producer"
468:
1.2 dwinter 469: def __init__(self,shortName,fullName,address="",url="",contact=""):
1.1 dwinter 470:
471: self.id=shortName
472: self.title=fullName
1.2 dwinter 473: self.address=address
474: self.url=url
475: self.contact=contact
476:
1.3 dwinter 477: manage_options = SimpleItem.manage_options+(
1.2 dwinter 478: {'label':'Main Config','action':'changeOSAS_producerForm'},
479: )
480:
481: def changeOSAS_producerForm(self):
482: """change"""
483: pt=PageTemplateFile('Products/OSA_system/ChangeOSAS_producer.zpt').__of__(self)
484: return pt()
1.3 dwinter 485:
486: def changeOSAS_producer(self,title,address,contact="",url=""):
487: """change"""
488: self.title=fullName
489: self.address=address
490: self.url=url
491: self.contact=contact
1.1 dwinter 492:
493: def manage_AddOSAS_producerForm(self):
494: """interface for adding the OSAS_root"""
495: pt=PageTemplateFile('Products/OSA_system/AddOSAS_producer.zpt').__of__(self)
496: return pt()
497:
498:
1.2 dwinter 499: def manage_AddOSAS_producer(self,id,title="",contact="",address="",url="",RESPONSE=None):
1.1 dwinter 500: """add the OSAS_root"""
501: if title=="":
502: title=id
503:
1.2 dwinter 504: newObj=OSAS_producer(id, title,address,contact,url)
1.1 dwinter 505: self._setObject(id,newObj)
506: if RESPONSE is not None:
507: RESPONSE.redirect('manage_main')
508:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>