--- OSAS/OSA_system/OSAS_show.py 2003/09/25 15:25:08 1.1 +++ OSAS/OSA_system/OSAS_show.py 2005/05/04 14:06:32 1.31 @@ -1,21 +1,31 @@ -# Classes for displaying, browsing and organizing the archive +""" Classes for displaying, browsing and organizing the archive +20040303 Needs configuration for rescaling thumbs +""" + +import addFolder +import OSAS_helpers from OFS.Folder import Folder from OFS.SimpleItem import SimpleItem from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate +from AccessControl import ClassSecurityInfo +from Globals import InitializeClass,package_home class OSAS_ShowOnline(SimpleItem): + security=ClassSecurityInfo() + """OnlineBrowser""" def __init__(self,id): """initialize a new instance""" self.id = id meta_type="OSAS_ShowOnline" - + + security.declareProtected('View','index_html') def index_html(self): """main view""" - pt=PageTemplateFile('products/OSA_system/OSAS_ViewFiles.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_ViewFiles.zpt')).__of__(self) return pt() def getfilesystem2(self,start,reload=0): @@ -44,16 +54,20 @@ class OSAS_ShowOnline(SimpleItem): return hasMetafile(path) def getMetafile(self,path): - return getMetafile(path) + + return getMetafile(path).decode('utf-8') def toggle_view(self,path,file): """Oeffnen bzw. schließen der Subfolders""" self.tree(path).toggle(path,file) return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+"?path="+path) + +InitializeClass(OSAS_ShowOnline) + def manage_AddOSAS_ShowOnlineForm(self): """interface for adding the OSAS_root""" - pt=PageTemplateFile('products/OSA_system/AddOSAS_ShowOnline.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddOSAS_ShowOnline.zpt')).__of__(self) return pt() def manage_AddOSAS_ShowOnline(self,id,RESPONSE=None): @@ -64,9 +78,241 @@ def manage_AddOSAS_ShowOnline(self,id,RE RESPONSE.redirect('manage_main') +class OSAS_StoreOnline(SimpleItem): + """Webfrontend für das Storagesystem""" + security=ClassSecurityInfo() + + def __init__(self,id): + """initialize a new instance""" + self.id = id + + meta_type="OSAS_StoreOnline" + + security.declareProtected('View','index_html') + def index_html(self): + """main view""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_StoreFiles.zpt')).__of__(self) + return pt() + + def readContexts(self,path): + """Zeige Contexte""" + if os.path.exists(path+"/index.meta"): + + return readContexts(path) + + else: + + return [] + + def rescaleThumbs(self,path): + """rescale thumbs of images in path""" + + dlpath = re.sub('/mpiwg/online/','',self.REQUEST['path']) + os.popen("ssh archive@nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat -src=/mpiwg/online -dest=/mpiwg/temp/online/scaled/thumb -dir=%s -scaleto=90 -sync >> /tmp/sc.out &"%dlpath ) + #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'])) + + self.REQUEST.SESSION['path']=self.REQUEST['path'] + #return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_scaled.zpt')).__of__(self) + return pt() + + + def getfilesystem2(self,start,reload=0): + """load filesystem""" + + k=filesystem2(start,1) + return k + + def tree(self,start): + """get the filetree""" + k=browse(start) + return k + + def path_to_link_store(self,path): + """generates navigation bar for viewfiles""" + return path_to_link_store(self.REQUEST['URL'],path) + + def isdigilib2(self,path): + """check if digilib""" + return isdigilib2(path) + + def changeName(self,name): + return changeName(name) + + def hasMetafile(self,path): + return hasMetafile(path) + + def getMetafile(self,path): + + return getMetafile(path).decode('utf-8') + + def toggle_view(self,path,file): + """Oeffnen bzw. schließen der Subfolders""" + self.tree(path).toggle(path,file) + return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+"?path="+path) + + def isFolder(self,path): + """Test ob Eintrag ein Folder ist""" + return isFolder(self,path) + + def isScannedDocument(self,path): + """Test ob Eintrag ein Scanned Document ist""" + return isScannedDocument(self,path) + + def isFullText(self,path,folder_name): + """Test ob Eintrag ein Folder ist""" + return isFullText(path,folder_name) + + def isPdf(self,path,folder_name): + """Test ob Eintrag ein Folder mit pdf2 ist""" + return isPdf(path,folder_name) + + + def isPresentation(self,path,folder_name): + """Test ob Eintrag ein Folder ist""" + return isPresentation(path,folder_name) + + def date(self): + return strftime("%d.%m.%Y",localtime()) + + def addFolderForm(self,path): + """add a new path""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_addFolder.zpt')).__of__(self) + return pt() + + def showHelp(self,refType,genericTag): + """helptext""" + for reference in self.ZopeFind(self.standardMD): + if reference[1].title==refType: + text=getattr(reference[1],'md_'+genericTag)[2] + return text + return "NO EXPLANATION" + + def showHelpTag(self,url,reftype,item): + """gen javascript for showhelp""" + url2=url+'/showHelp?refType=%s&genericTag=%s'%(reftype,item) + ret="""javascript:wd=window.open(\'%s\',\'Help\',\'width=300,height=250\');void(\'\');wd.focus();"""%url2 + return ret + + def addFolder(self,path,folder_name,description,archive_creation_date,creator): + """add the folder to the filesystem and write the metadata files""" + return addFolder.addFolder(self,path,folder_name,description,archive_creation_date,creator) + + def EditIndex(self,path): + """Editiere das Index Metafile""" + try: + dom=xml.dom.minidom.parse(path+"/index.meta") + indexmeta=dom.toxml(encoding='UTF-8') + except: + indexmeta="" + + self.REQUEST.SESSION['indexmeta']=indexmeta + self.REQUEST.SESSION['path']=path + newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editindex')).__of__(self) + return newtemplate() + + def EditIndex2(self): + """Sichern der Aenderungen in Index.meta""" + if not self.REQUEST.has_key('fileupload'): + #newtext=urllib.unquote(self.REQUEST['indexmeta']) + newtext=self.REQUEST['indexmeta'] + + else: + self.file_name=self.REQUEST['fileupload'].filename + #newtext=self.REQUEST.form['fileupload'].read() + # HACK DW + newtext=self.REQUEST['indexmeta'] + + indexmeta=file(self.REQUEST.SESSION['path']+"/index.meta","w") + indexmeta.writelines(newtext) + return self.REQUEST.response.redirect(self.REQUEST['URL1']+"?path="+self.REQUEST.SESSION['path']) + + def add_metafile(self): + """nothing""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_addmetadata.zpt')).__of__(self) + return pt() + + def getTextToolsField(self,path,name,default=''): + """Lese Textoolsfelder aus index.meta im path aus""" + + try: + dom=xml.dom.minidom.parse(path+"/index.meta") + node=dom.getElementsByTagName('texttool')[0] #getNode + subnode=node.getElementsByTagName(name)[0] + + # bei text wird nur der Folder gebraucht + if name=="text": + splitted=getText(subnode.childNodes).split("/") + return splitted[len(splitted)-2] + else: + return getText(subnode.childNodes) + except: + return default + + def getViewerTemplateSets(self,obj_ids=None): + """Get the ViewerTemplateSet title for configuration""" + ret=[] + + try: + viewerTemplateSets=self.ZopeFind(self.viewerTemplateSets,obj_metatypes=['OSAS_viewerTemplateSet'],obj_ids=obj_ids)#assumes viewerTemplateSets folder somewhere in the hierarchie. + + for viewerTemplateSet in viewerTemplateSets: + ret.append((viewerTemplateSet[1].title,viewerTemplateSet[0],viewerTemplateSet[1])) + + return ret + + except: + return [('no ViewerTemplateSetfolders','')] + + def changeTemplatesForm(self,path): + """changeform""" + path=self.REQUEST.SESSION['path']=path + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeTemplatesForm.zpt')).__of__(self) + return pt() + + + + def changeTemplates(self,path,RESPONSE=None): + """Andere alle Eintraege in index.meta""" + os.path.walk(path,OSAS_helpers.changeIndexMeta,self.REQUEST.form) + if RESPONSE is not None: + RESPONSE.redirect(self.REQUEST['URL1']+"?path="+self.REQUEST.SESSION['path']) + + +InitializeClass(OSAS_StoreOnline) + +def manage_AddOSAS_StoreOnlineForm(self): + """interface for adding the OSAS_root""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddOSAS_StoreOnline.zpt')).__of__(self) + return pt() + +def manage_AddOSAS_StoreOnline(self,id,RESPONSE=None): + """add the OSAS_root""" + newObj=OSAS_StoreOnline(id) + self._setObject(id,newObj) + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + +def readContexts(path): + """ReadContext from index.meta""" + dom=xml.dom.minidom.parse(path+"/index.meta") + nodes=dom.getElementsByTagName('context') + ret=[] + + + for node in nodes: + try: + link=getText(node.getElementsByTagName('link')[0].childNodes) + name=getText(node.getElementsByTagName('name')[0].childNodes) + ret.append((link,name)) + except: + """nothing""" + return ret + ### Ab hier Baustelle @@ -79,7 +325,11 @@ from AccessControl import ClassSecurityI from AccessControl.Role import RoleManager from Acquisition import Implicit from Globals import Persistent -from time import strptime +try: + from time import strptime +except: + print "ignoring time.strptime import" + from time import strftime import time import os.path @@ -88,7 +338,7 @@ import xml.dom.minidom from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate import tempfile -tempfile.tempdir="/var/tmp/archiver" +tempfile.tempdir="/var/tmp" exclusion=[".HSResource","lost+found","Network Trash Folder","TheFindByContentFolder","TheVolumeSettingsFolder"] class fsentry(Implicit, Persistent, RoleManager): @@ -210,27 +460,29 @@ class filesystem(Implicit, Persistent, R def archive_the_path(self,path): """parse indexmeta and return digilib path""" + try: #f = os.popen("cat "+path+"/index.meta","r") f =file(path+"/index.meta","r") lines = f.read() - + try: dom = xml.dom.minidom.parseString(lines) - if getText(dom.getElementsByTagName("content-type")[0].childNodes)=="folder": - """folder nicht archivieren""" - return 0 + if dom.getElementsByTagName("content-type"): + if getText(dom.getElementsByTagName("content-type")[0].childNodes)=="folder": + """folder nicht archivieren""" + return 0 + + archive_storage_date=getText(dom.getElementsByTagName("archive-storage-date")[0].childNodes) + + if archive_storage_date=="": + + """leer also archivieren""" + return 1 else: - archive_storage_date=getText(dom.getElementsByTagName("archive-storage-date")[0].childNodes) - - if archive_storage_date=="": - - """leer also archivieren""" - return 1 - else: - """nicht archivieren""" - return 0 + """nicht archivieren""" + return 0 except: """kein tag also archivieren""" return 1 @@ -310,6 +562,7 @@ class filesystem2(Implicit, Persistent, def getfs(self,start): """load filessystem""" + f = os.popen("find "+ start+" -name '*' ","r") lines = f.readlines() @@ -445,6 +698,8 @@ class browse(Implicit, Persistent, RoleM def getfs(start): """return filesystem""" + + f = os.popen("find "+ start+" -name '*'","r") lines = f.readlines() return lines @@ -535,7 +790,7 @@ def path_to_link_view(URL,path): i=i-1 return string -def path_to_link_store(path): +def path_to_link_store(URL,path): """generates navigation bar for viewfiles""" string="" @@ -552,7 +807,7 @@ def path_to_link_store(path): tmppath=os.path.dirname(tmppath) while i>=0: - string=string+""+pathes[i][1]+"/" + string=string+""+pathes[i][1]+"/" i=i-1 return string @@ -705,17 +960,19 @@ def getText(nodelist): def getBib(nodelist): rc= "" - print "HI" + for node in nodelist: if node.nodeType == node.ELEMENT_NODE: """nothing""" + rc = rc+"" + #print rc return rc+"
"+str(node.nodeName)+": "+getText(node.childNodes)+"
" def getMetafile(path): - """get index.meta""" + """get index.meta and translate it to an HTML""" html=[] if not os.path.exists(path+"/index.meta"): @@ -724,10 +981,25 @@ def getMetafile(path): f = os.popen("cat "+path+"/index.meta","r") lines = f.read() dom = xml.dom.minidom.parseString(lines) - name=getText(dom.getElementsByTagName("name")[0].childNodes) - creator=getText(dom.getElementsByTagName("creator")[0].childNodes) - creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes) - description=getText(dom.getElementsByTagName("description")[0].childNodes) + try: + name=getText(dom.getElementsByTagName("name")[0].childNodes) + except: + name="NOT_DEFINED!!!" + try: + creator=getText(dom.getElementsByTagName("creator")[0].childNodes) + except: + creator="NOT_DEFINED!!!" + + try: + creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes) + except: + creation_date="NOT_DEFINED!!!" + + try: + description=getText(dom.getElementsByTagName("description")[0].childNodes) + except: + description="NOT_DEFINED!!!" + try: type=getText(dom.getElementsByTagName("content-type")[0].childNodes) except: @@ -748,19 +1020,21 @@ def getMetafile(path): else: html=html+"

Info

" html=html+getBib(bib.childNodes) - print html + except: """none""" # html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace') - return html + return html.encode('utf-8') def hasMetafile(path): """get index.meta""" return os.path.exists(path+"/index.meta") #return path + + def isdigilib2(path): """check if folder is candidate for digilib without metadata""" try: @@ -810,6 +1084,20 @@ def isFullText(path,folder_name): return 0 +def isPdf(path,folder_name): + """check if foldername in path is full text""" + try: + dom=xml.dom.minidom.parse(path+"/index.meta") + for node in dom.getElementsByTagName("dir"): + + if getText(node.getElementsByTagName("content-type")[0].childNodes).lower()=="pdf": + + if getText(node.getElementsByTagName("name")[0].childNodes)==folder_name: + return 1 + return 0 + except: + + return 0 def isPresentation(path,folder_name): """check if foldername in path is full text""" @@ -970,7 +1258,7 @@ def isScannedDocument(self,path): try: dom = xml.dom.minidom.parseString(lines) content_type=getText(dom.getElementsByTagName("content-type")[0].childNodes) - if (content_type=="scanned-document") or (content_type=="scanned document"): + if (content_type=="scanned-document") or (content_type=="scanned document") or (content_type=="fulltext document"): return 1 else: return 0 @@ -986,30 +1274,3 @@ def date(self): -def EditIndex(self,path): - try: - dom=xml.dom.minidom.parse(path+"/index.meta") - indexmeta=dom.toxml() - except: - indexmeta="" - self.REQUEST.SESSION['indexmeta']=indexmeta - self.REQUEST.SESSION['path']=path - newtemplate=PageTemplateFile('/usr/local/mpiwg/Zope/Extensions/editindex').__of__(self) - return newtemplate() - -def EditIndex2(self): - if not self.REQUEST.has_key('fileupload'): - #newtext=urllib.unquote(self.REQUEST['indexmeta']) - newtext=self.REQUEST['indexmeta'] - print newtext - else: - self.file_name=self.REQUEST['fileupload'].filename - #newtext=self.REQUEST.form['fileupload'].read() - # HACK DW - newtext=self.REQUEST['indexmeta'] - - indexmeta=file(self.REQUEST.SESSION['path']+"/index.meta","w") - indexmeta.writelines(newtext) - return self.REQUEST.response.redirect("storage/storefiles?path="+self.REQUEST.SESSION['path']) - -