version 1.1, 2005/02/10 19:50:18
|
version 1.10, 2005/02/14 18:15:16
|
Line 1
|
Line 1
|
import os |
import os |
import os.path |
import os.path |
import stat |
import stat |
|
import OSAS_helpers |
|
import xmlrpclib |
|
import bz2 |
|
import base64 |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Globals import InitializeClass,package_home |
from Globals import InitializeClass,package_home |
from OFS.SimpleItem import SimpleItem |
from OFS.SimpleItem import SimpleItem |
import xml.dom.minidom |
|
import OSAS_helpers |
def encodeRPC(string): |
from OSAS_helpers import * |
return base64.encodestring(bz2.compress(string)) |
|
|
|
|
class OSAS_storeOnlineServer(SimpleItem): |
class OSAS_storeOnlineServer(SimpleItem): |
"""Server for store Online system""" |
"""Server for store Online system""" |
|
|
|
|
meta_type="OSAS_server" |
meta_type="OSAS_server" |
|
|
|
|
def findIndexMeta(self,realPath=""): |
def findIndexMeta(self,realPath=""): |
"""finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file |
"""finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file |
@keyword path: default ist "", Pfad auf das Object |
@keyword path: default ist "", Pfad auf das Object |
Line 62 class OSAS_storeOnlineServer(SimpleItem)
|
Line 69 class OSAS_storeOnlineServer(SimpleItem)
|
"""list dir""" |
"""list dir""" |
return os.listdir(path) |
return os.listdir(path) |
|
|
|
def isdir(self,path=""): |
|
"""list dir""" |
|
return os.path.isdir(path) |
|
|
def getMetaFile(self,path): |
def isfile(self,path=""): |
"""get index.meta and translate it to HTML""" |
"""list dir""" |
html=[] |
return os.path.isfile(path) |
|
|
if not os.path.exists(path+"/index.meta"): |
|
|
|
return self.getMetaInfoFromIndexMeta(path) |
|
#return "NO_METADATA" |
|
else: |
|
|
|
f = os.popen("cat "+path+"/index.meta","r") |
|
lines = f.read() |
|
|
|
dom = xml.dom.minidom.parseString(lines) |
|
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: |
|
type="" |
|
if type=="scanned document": |
|
html="<h3>Document: "+name+"</h3>" |
|
elif type=="folder": |
|
html="<h3>Folder: "+name+"</h3>" |
|
else: |
|
html="<h3>Document: "+name+"</h3>" |
|
|
|
html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>" |
|
html=html+"<h4>Description</h4><p>"+description+"</p>" |
|
try: |
|
bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0] |
|
if bib.attributes.has_key('type'): |
|
html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>" |
|
else: |
|
html=html+"<h4>Info</h4>" |
|
html=html+getBib(bib.childNodes) |
|
|
|
except: |
|
"""none""" |
|
|
|
# html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace') |
|
|
|
return html |
|
|
|
|
|
def getMetaInfoFromIndexMeta(self,path): |
|
"""metadaten zu path als html aus dem index.meta file zu path (meta tag im file bzw. dir container) |
|
@param path: Pfad auf das Object relativ zum rootFolderName |
|
@return: metadata als html |
|
""" |
|
xmlInfos=self.findEntryInIndexMeta(path) |
|
if xmlInfos: |
|
return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) |
|
else: |
|
return "" |
|
|
|
def findEntryInIndexMeta(self,path): |
|
"""Finde im naechstgelegenden index.meta relativ zu path den entprechenden Eintrag fuer diesen Pfad. |
|
@param path: Pfad auf das Object relativ zum rootFolderName |
|
@return: den Teil von Index.meta der Informationen zu path enthaelt, None wenn error. |
|
""" |
|
|
|
indexMeta=self.findIndexMeta(path) # suche index.meta |
def getFile(self,path): |
|
"""getFile""" |
|
|
if not indexMeta: |
if not os.path.exists(path): |
return None |
return None |
|
|
realPath=os.path.split(indexMeta)[0] |
f=file(path,'r') |
path=os.path.normpath(path) |
|
|
|
try: |
ret=f.read() |
dom=xml.dom.minidom.parse(indexMeta) |
|
except: |
|
zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) |
|
#ist path ein directory? |
|
dirs=dom.getElementsByTagName('dir') |
|
for dir in dirs: |
|
pathes=dir.getElementsByTagName('path') |
|
if pathes: |
|
pathX=OSAS_helpers.getText(pathes[0].childNodes) |
|
else: |
|
pathX="" |
|
names=dir.getElementsByTagName('name') |
|
if names: |
|
name=OSAS_helpers.getText(names[0].childNodes) |
|
else: |
|
name="" |
|
|
|
checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) |
f.close() |
if checkpath==path: |
|
|
|
return dir.toxml() |
return ret |
|
|
#ist path ein file? |
def getAllIndexMetasOfSubDirs(self,path): |
files=dom.getElementsByTagName('file') |
"""get all index Metas""" |
for dir in dirs: |
ret={} |
pathes=dir.getElementsByTagName('path') |
if os.path.exists(path+"/index.meta"): |
if pathes: |
compressed=encodeRPC(file(path+"/index.meta","r").read()) |
pathX=OSAS_helpers.getText(pathes[0].childNodes) |
ret["."]=('OSAS_dir',compressed) |
|
for dir in os.listdir(path): |
|
fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir)) |
|
if os.path.exists(os.path.join(path,dir,"index.meta")): |
|
compressed=encodeRPC(file(os.path.join(path,dir,"index.meta"),"r").read()) |
|
ret[dir]=('OSAS_dir',compressed) |
else: |
else: |
pathX="" |
ret[dir]=(fileType,None) |
names=dir.getElementsByTagName('name') |
return ret |
if names: |
|
name=OSAS_helpers.getText(names[0].childNodes) |
|
else: |
|
name="" |
|
|
|
checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) |
|
if checkpath==path: |
|
|
|
return dir.toxml() |
|
|
|
|
|
return None |
|
|
|
|
|
def manage_addOSAS_storeOnlineServerForm(self): |
def manage_addOSAS_storeOnlineServerForm(self): |