Commit 9a9476a2 authored by Christophe Dumez's avatar Christophe Dumez

- Create tree.xml file


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6163 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c3da6225
...@@ -39,6 +39,8 @@ from DateTime import DateTime ...@@ -39,6 +39,8 @@ from DateTime import DateTime
from cPickle import dumps, loads from cPickle import dumps, loads
from App.config import getConfiguration from App.config import getConfiguration
from zExceptions import Unauthorized from zExceptions import Unauthorized
from OFS.Image import manage_addFile
from cStringIO import StringIO
try: try:
from base64 import b64encode, b64decode from base64 import b64encode, b64decode
...@@ -47,8 +49,9 @@ except ImportError: ...@@ -47,8 +49,9 @@ except ImportError:
class File : class File :
# Constructor # Constructor
def __init__(self, fullPath) : def __init__(self, fullPath, msgStatus) :
self.fullPath = fullPath self.fullPath = fullPath
self.msgStatus = msgStatus
self.fileName = fullPath.split('/')[-1] self.fileName = fullPath.split('/')[-1]
# return the file name # return the file name
...@@ -58,12 +61,17 @@ class File : ...@@ -58,12 +61,17 @@ class File :
# return the file path # return the file path
def getFullPath(self) : def getFullPath(self) :
return self.fullPath return self.fullPath
# return the file's msgStatus
def getMsgStatus(self) :
return self.msgStatus
## End of File Class ## End of File Class
class Dir : class Dir :
# Constructor # Constructor
def __init__(self, fullPath) : def __init__(self, fullPath, msgStatus) :
self.fullPath = fullPath self.fullPath = fullPath
self.msgStatus = msgStatus
self.dirName = fullPath.split('/')[-1] self.dirName = fullPath.split('/')[-1]
self.subdirs = [] # list of sub directories self.subdirs = [] # list of sub directories
...@@ -75,6 +83,14 @@ class Dir : ...@@ -75,6 +83,14 @@ class Dir :
def getFullPath(self) : def getFullPath(self) :
return self.fullPath return self.fullPath
# return directory's msgStatus
def getMsgStatus(self) :
return self.msgStatus
# Set Directory's msgStatus
def setMsgStatus(self, msgStatus) :
self.msgStatus = msgStatus
# return a list of sub directories' names # return a list of sub directories' names
def getSubDirs(self) : def getSubDirs(self) :
return [d.getName() for d in self.subdirs] return [d.getName() for d in self.subdirs]
...@@ -296,7 +312,7 @@ class SubversionTool(UniqueObject, Folder): ...@@ -296,7 +312,7 @@ class SubversionTool(UniqueObject, Folder):
path = path[:-1] path = path[:-1]
#root = Dir(path.split('/')[-1]) #root = Dir(path.split('/')[-1])
root = Dir(path) root = Dir(path, "normal")
for statusObj in self.status(path) : for statusObj in self.status(path) :
# (normal, added, modified, deleted) # (normal, added, modified, deleted)
...@@ -317,34 +333,70 @@ class SubversionTool(UniqueObject, Folder): ...@@ -317,34 +333,70 @@ class SubversionTool(UniqueObject, Folder):
i += 1 i += 1
if d : if d :
if d not in parent.getSubDirs(): if d not in parent.getSubDirs():
parent.addSubDir(Dir('/'+'/'.join(full_path_list[:i]).strip())) parent.addSubDir(Dir('/'+'/'.join(full_path_list[:i]).strip(),
"normal"))
parent = parent.getDir(d) parent = parent.getDir(d)
parent.addSubDir(File(full_path)) if os.path.isdir(full_path) :
if filename not in parent.getSubDirs() :
parent.addSubDir(Dir(full_path, str(msgStatus)))
else :
tmp = parent.getDir(filename)
tmp.setMsgStatus(str(msgStatus))
else :
parent.addSubDir(File(full_path, str(msgStatus)))
return root return root
def treeToXML(self, item) : def treeToXML(self, item) :
output = "<?xml version='1.0' encoding='iso-8859-1'?>"+ os.linesep output = StringIO()
output += "<tree id='0'>" + os.linesep output.write("<?xml version='1.0' encoding='iso-8859-1'?>"+ os.linesep)
output = self._treeToXML(item, output, 1) output.write("<tree id='0'>" + os.linesep)
output += "</tree>" + os.linesep output = self._treeToXML(item, output, 1, True)
return output output.write("</tree>" + os.linesep)
try :
def _treeToXML(self, item, output, ident) : self.getPortalObject()["portal_skins"]["erp5_svn"].manage_addFile(id="tree.xml", file=output)
except :
self.getPortalObject()["portal_skins"]["erp5_svn"]["tree.xml"].manage_upload(file=output)
output.close()
#return output
def _treeToXML(self, item, output, ident, first) :
itemStatus = item.getMsgStatus()
if itemStatus == 'added' :
itemColor='green'
elif itemStatus == 'modified' :
itemColor='orange'
elif itemStatus == 'deleted' :
itemColor='red'
else :
itemColor='black'
if isinstance(item, Dir) : if isinstance(item, Dir) :
for i in range(ident) : for i in range(ident) :
output += '\t' output.write('\t')
output += '<item text="%s" id="%s" im0="folder.png" im1="folder_open.png" im2="folderClosed.gif">'%(item.getName(), item.getFullPath(),) + os.linesep if first :
output.write('<item open="1" text="%s" id="%s" aCol="%s" '\
'im0="folder.png" im1="folder_open.png" '\
'im2="folder.png">'%(item.getName(),
item.getFullPath(), itemColor,) + os.linesep)
first=False
else :
output.write('<item text="%s" id="%s" aCol="%s" im0="folder.png" ' \
'im1="folder_open.png" im2="folder.png">'%(item.getName(),
item.getFullPath(), itemColor,) + os.linesep)
for it in item.subdirs: for it in item.subdirs:
ident += 1 ident += 1
output = self._treeToXML(item.getDir(it.getName()), output, ident) output = self._treeToXML(item.getDir(it.getName()), output, ident,
first)
ident -= 1 ident -= 1
for i in range(ident) : for i in range(ident) :
output += '\t' output.write('\t')
output += '</item>' + os.linesep output.write('</item>' + os.linesep)
else : else :
for i in range(ident) : for i in range(ident) :
output += '\t' output.write('\t')
output += '<item text="%s" id="%s" im0="document.png" im1="document.png" im2="document.png"/>'%(item.getName(), item.getFullPath(),) + os.linesep output.write('<item text="%s" id="%s" aCol="%s" im0="document.png" ' \
'im1="document.png" im2="document.png"/>'%(item.getName(),
item.getFullPath(), itemColor,) + os.linesep)
return output return output
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment