Commit 529301aa authored by Christophe Dumez's avatar Christophe Dumez

- Improved XML Generation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6155 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 42f269b6
...@@ -47,23 +47,33 @@ except ImportError: ...@@ -47,23 +47,33 @@ except ImportError:
class File : class File :
# Constructor # Constructor
def __init__(self, fileName) : def __init__(self, fullPath) :
self.fileName = fileName self.fullPath = fullPath
self.fileName = fullPath.split('/')[-1]
# return the file name # return the file name
def getName(self) : def getName(self) :
return self.fileName return self.fileName
# return the file path
def getFullPath(self) :
return self.fullPath
## End of File Class ## End of File Class
class Dir : class Dir :
# Constructor # Constructor
def __init__(self, dirName) : def __init__(self, fullPath) :
self.dirName = dirName self.fullPath = fullPath
self.dirName = fullPath.split('/')[-1]
self.subdirs = [] # list of sub directories self.subdirs = [] # list of sub directories
# return directory's short name # return directory's short name
def getName(self) : def getName(self) :
return self.dirName return self.dirName
# return directory's path
def getFullPath(self) :
return self.fullPath
# return a list of sub directories' names # return a list of sub directories' names
def getSubDirs(self) : def getSubDirs(self) :
...@@ -281,39 +291,55 @@ class SubversionTool(UniqueObject, Folder): ...@@ -281,39 +291,55 @@ class SubversionTool(UniqueObject, Folder):
return client.status(self._getWorkingPath(path), **kw) return client.status(self._getWorkingPath(path), **kw)
def getModifiedTree(self, path) : def getModifiedTree(self, path) :
# Remove trailing slash if it's present
if path[-1]=="/" : if path[-1]=="/" :
path = path[:-1] path = path[:-1]
root = Dir(path.split('/')[-1]) #root = Dir(path.split('/')[-1])
root = Dir(path)
for statusObj in self.status(path) : for statusObj in self.status(path) :
# (normal, added, modified, deleted) # (normal, added, modified, deleted)
msgStatus = statusObj.getTextStatus() msgStatus = statusObj.getTextStatus()
f = file('/tmp/py.log','w')
if str(msgStatus) != "normal" : if str(msgStatus) != "normal" :
relative_path = statusObj.getPath()[len(path)+1:] full_path = statusObj.getPath()
full_path_list = full_path.split('/')[1:]
f.write('full_path_list = %s\n' % full_path_list)
relative_path = full_path[len(path)+1:]
relative_path_list = relative_path.split('/')
f.write('relative_path_list = %s\n' % relative_path_list)
# Processing entry # Processing entry
full_path = relative_path.split('/') filename = relative_path_list[-1]
filename = full_path[-1] # Needed or files will be both File & Dir objects
full_path = full_path[:-1] relative_path_list = relative_path_list[:-1]
parent = root parent = root
for rep in full_path : i = len(path.split('/'))-1
if rep:
if rep not in parent.getSubDirs(): for d in relative_path_list :
parent.addSubDir(Dir(rep)) i += 1
parent = parent.getDir(rep) if d :
parent.addSubDir(File(filename)) if d not in parent.getSubDirs():
f.write('d is = %s\n'% d)
f.write('adding subdir %s to parent %s\n'% ('/'+'/'.join(full_path_list[:i]).strip(), parent.getFullPath()))
parent.addSubDir(Dir('/'+'/'.join(full_path_list[:i]).strip()))
parent = parent.getDir(d)
parent.addSubDir(File(full_path))
f.close()
return root return root
def treeToXML(self, item) : def treeToXML(self, item) :
return self._treeToXML(item, "", 0) output = "<?xml version='1.0' encoding='iso-8859-1'?>"+ os.linesep
output += "<tree id='0'>" + os.linesep
output = self._treeToXML(item, output, 1)
output += "</tree>" + os.linesep
return output
def _treeToXML(self, item, output, ident) : def _treeToXML(self, item, output, ident) :
if isinstance(item, Dir) : if isinstance(item, Dir) :
for i in range(ident) : for i in range(ident) :
output += '\t' output += '\t'
output += '<item type="directory" name="%s">'%item.getName() + os.linesep output += '<item text="%s" id="%s" im0="folderClosed.gif" im1="folderOpen.gif" im2="folderClosed.gif">'%(item.getName(), item.getFullPath(),) + 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)
...@@ -324,7 +350,7 @@ class SubversionTool(UniqueObject, Folder): ...@@ -324,7 +350,7 @@ class SubversionTool(UniqueObject, Folder):
else : else :
for i in range(ident) : for i in range(ident) :
output += '\t' output += '\t'
output += '<item type="file" name="%s" />'%item.getName() + os.linesep output += '<item text="%s" id="%s" im0="leaf.gif" im1="leaf.gif" im2="leaf.gif"/>'%(item.getName(), item.getFullPath(),) + 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