Commit 2695762c authored by Christophe Dumez's avatar Christophe Dumez

- added functions to get the XML Tree of the modified files in working copy

git-svn-id: 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4cba39e4
......@@ -32,6 +32,7 @@ from Products.ERP5Type.Utils import convertToUpperCase
from MethodObject import Method
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
import pysvn
......@@ -126,19 +127,23 @@ try:
value = getattr(instance._obj, self._key)
if type(value) == type(u''):
value = value.encode('utf-8')
elif isinstance(value, pysvn.Entry):
#elif isinstance(value, pysvn.Entry):
elif str(type(value)) == "<type 'entry'>":
value = Entry(value)
elif isinstance(value, pysvn.Revision):
#elif isinstance(value, pysvn.Revision):
elif str(type(value)) == "<type 'revision'>":
value = Revision(value)
return value
def initializeAccessors(klass): = ClassSecurityInfo()
for attr in klass.attribute_list:
name = 'get' + convertToUpperCase(attr)
print name
setattr(klass, name, Getter(attr))
class ObjectWrapper(Implicit):
attribute_list = ()
......@@ -147,8 +152,9 @@ try:
self._obj = obj
class Status(ObjectWrapper):
attribute_list = ('path', 'entry', 'is_versioned', 'is_locked', 'is_copied', 'is_switched',
'prop_status', 'text_status', 'repos_prop_status', 'repos_text_status')
# XXX Big Hack to fix a bug
__allow_access_to_unprotected_subobjects__ = 1
attribute_list = ('path', 'entry', 'is_versioned', 'is_locked', 'is_copied', 'is_switched', 'prop_status', 'text_status', 'repos_prop_status', 'repos_text_status')
class Entry(ObjectWrapper):
......@@ -202,6 +208,6 @@ try:
except ImportError:
from zLOG import LOG, WARNING
LOG('SubversionTool', WARNING,
'could not import pysvn; until pysvn is installed properly, this tool will not function.')
'could not import pysvn; until pysvn is installed properly, this tool will not work.')
def newSubversionClient(container, **kw):
raise SubversionInstallationError, 'pysvn is not installed'
......@@ -44,7 +44,42 @@ try:
from base64 import b64encode, b64decode
except ImportError:
from base64 import encodestring as b64encode, decodestring as b64decode
class File :
# Constructor
def __init__(self, fileName) :
self.fileName = fileName
# return the file name
def getName(self) :
return self.fileName
## End of File Class
class Dir :
# Constructor
def __init__(self, dirName) :
self.dirName = dirName
self.subdirs = [] # list of sub directories
# return directory's short name
def getName(self) :
return self.dirName
# return a list of sub directories' names
def getSubDirs(self) :
return [d.getName() for d in self.subdirs]
# add a sub directory to the list
def addSubDir(self, item) :
# return directory in subdirs given its name
def getDir(self, name):
for d in self.subdirs:
if d.getName() == name:
return d
## End of Dir Class
class SubversionTool(UniqueObject, Folder):
"""The SubversionTool provides a Subversion interface to ERP5.
......@@ -244,5 +279,53 @@ class SubversionTool(UniqueObject, Folder):
client = self._getClient()
return client.status(self._getWorkingPath(path), **kw)
def getModifiedTree(self, path) :
if path[-1]=="/" :
path = path[:-1]
root = Dir(path.split('/')[-1])
for statusObj in self.status(path) :
# (normal, added, modified, deleted)
msgStatus = statusObj.getTextStatus()
if str(msgStatus) != "normal" :
relative_path = statusObj.getPath()[len(path)+1:]
# Processing entry
full_path = relative_path.split('/')
filename = full_path[-1]
full_path = full_path[:-1]
parent = root
for rep in full_path :
if rep:
if rep not in parent.getSubDirs():
parent = parent.getDir(rep)
return root
def treeToXML(self, item) :
return self._treeToXML(item, "", 0)
def _treeToXML(self, item, output, ident) :
if isinstance(item, Dir) :
for i in range(ident) :
output += '\t'
output += '<item type="directory" name="%s">'%item.getName() + os.linesep
for it in item.subdirs:
ident += 1
output = self._treeToXML(item.getDir(it.getName()), output, ident)
ident -= 1
for i in range(ident) :
output += '\t'
output += '</item>' + os.linesep
else :
for i in range(ident) :
output += '\t'
output += '<item type="file" name="%s" />'%item.getName() + os.linesep
return output
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment