--- OSA_system2/OSAS_server.py 2005/02/10 19:50:18 1.1
+++ OSA_system2/OSAS_server.py 2005/12/01 10:43:18 1.20
@@ -1,18 +1,68 @@
import os
import os.path
import stat
+import OSAS_helpers
+import xmlrpclib
+import bz2
+import base64
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Globals import InitializeClass,package_home
from OFS.SimpleItem import SimpleItem
-import xml.dom.minidom
-import OSAS_helpers
-from OSAS_helpers import *
+import zLOG
+import sys
+
+def encodeRPC(string):
+ return base64.encodestring(bz2.compress(string))
+def decodeRPC(string):
+ return bz2.decompress(base64.decodestring(string))
+
class OSAS_storeOnlineServer(SimpleItem):
"""Server for store Online system"""
-
+
+
meta_type="OSAS_server"
+
+ def __init__(self,id):
+ """initalize osas_server"""
+ self.id = id
+
+ def getImages(self,path):
+ """hack"""
+ imageEnding=['.gif','.jpg','.jpeg','.png','.tiff','.tif']
+
+ dirs=os.listdir(path)
+ ret=[]
+
+ for dir in dirs:
+
+ if os.path.isdir(os.path.join(path,dir)):
+
+ for subdir in os.listdir(os.path.join(path,dir)):
+ if os.path.splitext(subdir)[1].lower() in imageEnding:
+ ret.append(os.path.join(dir,subdir))
+ else:
+ if os.path.splitext(dir)[1] in imageEnding:
+ ret.append(os.path.join(dir))
+ return ret
+
+
+ def getMovies(self,path):
+ """hack"""
+ movieEnding=['.dv','.mov','.mp4']
+ dirs=os.listdir(path)
+ ret=[]
+ for dir in dirs:
+ if os.path.isdir(os.path.join(path,dir)):
+ for subdir in os.listdir(os.path.join(path,dir)):
+ if os.path.splitext(subdir)[1].lower() in movieEnding:
+ ret.append(os.path.join(dir,subdir))
+ else:
+ if os.path.splitext(dir)[1] in movieEnding:
+ ret.append(os.path.join(dir))
+ return ret
+
def findIndexMeta(self,realPath=""):
"""finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
@keyword path: default ist "", Pfad auf das Object
@@ -62,139 +112,66 @@ class OSAS_storeOnlineServer(SimpleItem)
"""list dir"""
return os.listdir(path)
+ def isdir(self,path=""):
+ """list dir"""
+ return os.path.isdir(path)
- def getMetaFile(self,path):
- """get index.meta and translate it to HTML"""
- html=[]
-
- 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="
Document: "+name+"
"
- elif type=="folder":
- html="Folder: "+name+"
"
- else:
- html="Document: "+name+"
"
-
- html=html+"created by: "+creator+" at: "+creation_date+"
"
- html=html+"Description
"+description+"
"
- try:
- bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0]
- if bib.attributes.has_key('type'):
- html=html+"Info ("+bib.attributes['type'].value+")
"
- else:
- html=html+"Info
"
- html=html+getBib(bib.childNodes)
-
- except:
- """none"""
+ def isfile(self,path=""):
+ """list dir"""
+ return os.path.isfile(path)
- # html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace')
- return html
+ def getFile(self,path):
+ """getFile"""
- 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.
- """
+ if not os.path.exists(path):
+ return None
- indexMeta=self.findIndexMeta(path) # suche index.meta
+ f=file(path,'r')
- if not indexMeta:
- return None
+ ret=f.read()
- realPath=os.path.split(indexMeta)[0]
- path=os.path.normpath(path)
+ f.close()
+
+ return ret
+ def getAllIndexMetasOfSubDirs(self,path):
+ """get all index Metas"""
+ ret={}
+ if os.path.exists(path+"/index.meta"):
+ compressed=encodeRPC(file(path+"/index.meta","r").read())
+ ret["."]=('OSAS_dir',compressed)
+ for dir in os.listdir(path):
+ zLOG.LOG("SERVER",zLOG.INFO,"get all index meta in %s"%dir)
+ 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:
+ ret[dir]=(fileType,None)
+ return ret
+
+ def writeMetaDataFile(self,path,metadata,compressed=None):
+ """writefiletoserver"""
+ if compressed:
+ metadata=decodeRPC(metadata)
+
try:
- dom=xml.dom.minidom.parse(indexMeta)
+ fh=file(path,"w")
+ fh.write(metadata)
+ fh.close
+ return True
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))
- if checkpath==path:
-
- return dir.toxml()
-
- #ist path ein file?
- files=dom.getElementsByTagName('file')
- 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))
- if checkpath==path:
-
- return dir.toxml()
-
-
- return None
+ zLOG.LOG("SERVER (writeMetadataFile)",zLOG.ERROR,"%s (%s)"%sys.exc_info()[0:2])
+ return False
+ def generateMovieThumb(self,input,output):
+ """generate Movie"""
+ zLOG.LOG("SERVER",zLOG.INFO,"/usr/local/bin/thumbbite.pl %s %s"%(input,output))
+ ret=os.popen("/usr/local/bin/thumbbite.pl %s %s"%(input,output))
+ zLOG.LOG("SERVER",zLOG.INFO,ret)
+ return "ok"
def manage_addOSAS_storeOnlineServerForm(self):
"""interface for adding the OSAS_storeOnline"""