Commit d3542150 authored by Christophe Dumez's avatar Christophe Dumez

- Improved XML Export (was programming like in Java :p)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6174 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74aaae83
...@@ -198,6 +198,9 @@ try: ...@@ -198,6 +198,9 @@ try:
def trustSSLServer(self, trust_dict): def trustSSLServer(self, trust_dict):
return self.aq_parent._trustSSLServer(trust_dict) return self.aq_parent._trustSSLServer(trust_dict)
def checkin(self, path, log_message, recurse):
return self.client.checkin(path, log_message=log_message, recurse=recurse)
def status(self, path, **kw): def status(self, path, **kw):
# Since plain Python classes are not convenient in Zope, convert the objects. # Since plain Python classes are not convenient in Zope, convert the objects.
return [Status(x) for x in self.client.status(path, **kw)] return [Status(x) for x in self.client.status(path, **kw)]
......
...@@ -52,19 +52,7 @@ class File : ...@@ -52,19 +52,7 @@ class File :
def __init__(self, fullPath, msgStatus) : def __init__(self, fullPath, msgStatus) :
self.fullPath = fullPath self.fullPath = fullPath
self.msgStatus = msgStatus self.msgStatus = msgStatus
self.fileName = fullPath.split('/')[-1] self.name = fullPath.split('/')[-1]
# return the file name
def getName(self) :
return self.fileName
# return the file path
def getFullPath(self) :
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 :
...@@ -72,37 +60,17 @@ class Dir : ...@@ -72,37 +60,17 @@ class Dir :
def __init__(self, fullPath, msgStatus) : def __init__(self, fullPath, msgStatus) :
self.fullPath = fullPath self.fullPath = fullPath
self.msgStatus = msgStatus self.msgStatus = msgStatus
self.dirName = fullPath.split('/')[-1] self.name = fullPath.split('/')[-1]
self.subdirs = [] # list of sub directories self.subDirs = [] # list of sub directories
# return directory's short name
def getName(self) :
return self.dirName
# return directory's path
def getFullPath(self) :
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.fullPath for d in self.subDirs]
# add a sub directory to the list
def addSubDir(self, item) :
self.subdirs.append(item)
# return directory in subdirs given its name # return directory in subdirs given its name
def getDir(self, name): def getDir(self, fullPath):
for d in self.subdirs: for d in self.subDirs:
if d.getName() == name: if d.fullPath == fullPath:
return d return d
## End of Dir Class ## End of Dir Class
...@@ -293,11 +261,12 @@ class SubversionTool(UniqueObject, Folder): ...@@ -293,11 +261,12 @@ class SubversionTool(UniqueObject, Folder):
return client.revert(self._getWorkingPath(path)) return client.revert(self._getWorkingPath(path))
security.declareProtected('Import/Export objects', 'checkin') security.declareProtected('Import/Export objects', 'checkin')
def checkin(self, path, log_message = None): def checkin(self, path, log_message = 'None', recurse=True):
"""Commit local changes. """Commit local changes.
""" """
client = self._getClient(log_message = log_message) client = self._getClient()
return client.checkin(self._getWorkingPath(path)) #return client.checkin(self._getWorkingPath(path), log_message, recurse)
return client.checkin(path, log_message, recurse)
security.declareProtected('Import/Export objects', 'status') security.declareProtected('Import/Export objects', 'status')
def status(self, path, **kw): def status(self, path, **kw):
...@@ -311,13 +280,13 @@ class SubversionTool(UniqueObject, Folder): ...@@ -311,13 +280,13 @@ class SubversionTool(UniqueObject, Folder):
if path[-1]=="/" : if path[-1]=="/" :
path = path[:-1] path = path[:-1]
#root = Dir(path.split('/')[-1])
root = Dir(path, "normal") root = Dir(path, "normal")
somethingModified = False
for statusObj in self.status(path) : for statusObj in self.status(path) :
# (normal, added, modified, deleted) # can be (normal, added, modified, deleted)
msgStatus = statusObj.getTextStatus() msgStatus = statusObj.getTextStatus()
if str(msgStatus) != "normal" : if str(msgStatus) != "normal" :
somethingModified = True
full_path = statusObj.getPath() full_path = statusObj.getPath()
full_path_list = full_path.split('/')[1:] full_path_list = full_path.split('/')[1:]
relative_path = full_path[len(path)+1:] relative_path = full_path[len(path)+1:]
...@@ -332,19 +301,21 @@ class SubversionTool(UniqueObject, Folder): ...@@ -332,19 +301,21 @@ class SubversionTool(UniqueObject, Folder):
for d in relative_path_list : for d in relative_path_list :
i += 1 i += 1
if d : if d :
if d not in parent.getSubDirs(): fullPathOfd = '/'+'/'.join(full_path_list[:i]).strip()
parent.addSubDir(Dir('/'+'/'.join(full_path_list[:i]).strip(), if fullPathOfd not in parent.subDirs :
"normal")) parent.subDirs.append(Dir(fullPathOfd, "normal"))
parent = parent.getDir(d) parent = parent.getDir(fullPathOfd)
if os.path.isdir(full_path) : if os.path.isdir(full_path) :
if filename not in parent.getSubDirs() : if full_path == parent.fullPath :
parent.addSubDir(Dir(full_path, str(msgStatus))) parent.msgStatus = str(msgStatus)
elif full_path not in parent.subDirs :
parent.subDirs.append(Dir(full_path, str(msgStatus)))
else : else :
tmp = parent.getDir(filename) tmp = parent.getDir(full_path)
tmp.setMsgStatus(str(msgStatus)) tmp.msgStatus = str(msgStatus)
else : else :
parent.addSubDir(File(full_path, str(msgStatus))) parent.subDirs.append(File(full_path, str(msgStatus)))
return root return somethingModified and root
def treeToXML(self, item) : def treeToXML(self, item) :
output = StringIO() output = StringIO()
...@@ -361,7 +332,7 @@ class SubversionTool(UniqueObject, Folder): ...@@ -361,7 +332,7 @@ class SubversionTool(UniqueObject, Folder):
#return output #return output
def _treeToXML(self, item, output, ident, first) : def _treeToXML(self, item, output, ident, first) :
itemStatus = item.getMsgStatus() itemStatus = item.msgStatus
if itemStatus == 'added' : if itemStatus == 'added' :
itemColor='green' itemColor='green'
elif itemStatus == 'modified' : elif itemStatus == 'modified' :
...@@ -376,16 +347,16 @@ class SubversionTool(UniqueObject, Folder): ...@@ -376,16 +347,16 @@ class SubversionTool(UniqueObject, Folder):
if first : if first :
output.write('<item open="1" text="%s" id="%s" aCol="%s" '\ output.write('<item open="1" text="%s" id="%s" aCol="%s" '\
'im0="folder.png" im1="folder_open.png" '\ 'im0="folder.png" im1="folder_open.png" '\
'im2="folder.png">'%(item.getName(), 'im2="folder.png">'%(item.name,
item.getFullPath(), itemColor,) + os.linesep) item.fullPath, itemColor,) + os.linesep)
first=False first=False
else : else :
output.write('<item text="%s" id="%s" aCol="%s" im0="folder.png" ' \ output.write('<item text="%s" id="%s" aCol="%s" im0="folder.png" ' \
'im1="folder_open.png" im2="folder.png">'%(item.getName(), 'im1="folder_open.png" im2="folder.png">'%(item.name,
item.getFullPath(), itemColor,) + os.linesep) item.fullPath, 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.fullPath), output, ident,
first) first)
ident -= 1 ident -= 1
for i in range(ident) : for i in range(ident) :
...@@ -395,8 +366,8 @@ first) ...@@ -395,8 +366,8 @@ first)
for i in range(ident) : for i in range(ident) :
output.write('\t') output.write('\t')
output.write('<item text="%s" id="%s" aCol="%s" im0="document.png" ' \ output.write('<item text="%s" id="%s" aCol="%s" im0="document.png" ' \
'im1="document.png" im2="document.png"/>'%(item.getName(), 'im1="document.png" im2="document.png"/>'%(item.name,
item.getFullPath(), itemColor,) + os.linesep) item.fullPath, 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