Commit cf7446c1 authored by Christophe Dumez's avatar Christophe Dumez

- Fixed a nasty bug in xml creation

- improved performance a little


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6200 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 765c2e87
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from Acquisition import Implicit from Acquisition import Implicit
import time import time, os
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from MethodObject import Method from MethodObject import Method
from Globals import InitializeClass from Globals import InitializeClass
...@@ -181,38 +181,45 @@ try: ...@@ -181,38 +181,45 @@ try:
self.client.set_auth_cache(0) self.client.set_auth_cache(0)
self.client.callback_cancel = CancelCallback(self) self.client.callback_cancel = CancelCallback(self)
self.client.callback_get_log_message = GetLogMessageCallback(self) self.client.callback_get_log_message = GetLogMessageCallback(self)
#self.client.callback_get_login = GetLoginCallback(self) self.client.callback_get_login = GetLoginCallback(self)
self.client.callback_get_login = self.callback_get_Login #self.client.callback_get_login = self.callback_get_Login
self.client.callback_notify = NotifyCallback(self) self.client.callback_notify = NotifyCallback(self)
#self.client.callback_ssl_server_trust_prompt = SSLServerTrustPromptCallback(self) self.client.callback_ssl_server_trust_prompt = SSLServerTrustPromptCallback(self)
self.client.callback_ssl_server_trust_prompt = self.callback_ssl_server_trust_prompt #self.client.callback_ssl_server_trust_prompt = self.callback_ssl_server_trust_prompt
self.creation_time = time.time() self.creation_time = time.time()
self.__dict__.update(kw) self.__dict__.update(kw)
def getLogMessage(self): def getLogMessage(self):
return self.log_message return self.log_message
def _getPreferences(self):
self.working_path = self.getPortalObject().portal_preferences.getPreference('subversion_working_copy')
if not self.working_path :
raise "Error: Please set Subversion working path in preferences"
self.svn_username = self.getPortalObject().portal_preferences.getPreference('preferred_subversion_user_name')
os.chdir(self.working_path);
def getTimeout(self): def getTimeout(self):
return self.timeout return self.timeout
def callback_get_Login( self, realm, username, may_save ): # def callback_get_Login( self, realm, username, may_save ):
#Retrieving saved username/password # #Retrieving saved username/password
#raise 'realm is '+realm+' && username is '+username # username, password = self.login
username, password = self.login # if not username :
if not username : # raise "Error: Couldn't retrieve saved username !"
raise "Error: Couldn't retrieve saved username !" # if not password :
if not password : # raise "Error: Couldn't retrieve saved password !"
raise "Error: Couldn't retrieve saved password !" # return 1, username, password, True
return 1, username, password, True
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 callback_ssl_server_trust_prompt( self, trust_data ): # def callback_ssl_server_trust_prompt( self, trust_data ):
# Always trusting # # Always trusting
return True, trust_data['failures'], True # return True, trust_data['failures'], True
def checkin(self, path, log_message, recurse): def checkin(self, path, log_message, recurse):
self._getPreferences()
return self.client.checkin(path, log_message=log_message, recurse=recurse) return self.client.checkin(path, log_message=log_message, recurse=recurse)
def status(self, path, **kw): def status(self, path, **kw):
......
...@@ -65,12 +65,12 @@ class Dir : ...@@ -65,12 +65,12 @@ class Dir :
# return a list of sub directories' names # return a list of sub directories' names
def getSubDirs(self) : def getSubDirs(self) :
return [d.full_path for d in self.sub_dirs] return [d.name for d in self.sub_dirs]
# return directory in subdirs given its name # return directory in subdirs given its name
def getDir(self, full_path): def getDir(self, name):
for d in self.sub_dirs: for d in self.sub_dirs:
if d.full_path == full_path: if d.name == name:
return d return d
## End of Dir Class ## End of Dir Class
...@@ -85,7 +85,7 @@ class SubversionTool(UniqueObject, Folder): ...@@ -85,7 +85,7 @@ class SubversionTool(UniqueObject, Folder):
login_cookie_name = 'erp5_subversion_login' login_cookie_name = 'erp5_subversion_login'
ssl_trust_cookie_name = 'erp5_subversion_ssl_trust' ssl_trust_cookie_name = 'erp5_subversion_ssl_trust'
top_working_path = os.path.join(getConfiguration().instancehome, 'svn') top_working_path = os.path.join(getConfiguration().instancehome, 'svn')
os.chdir(top_working_path)
# Declarative Security # Declarative Security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -105,6 +105,8 @@ class SubversionTool(UniqueObject, Folder): ...@@ -105,6 +105,8 @@ class SubversionTool(UniqueObject, Folder):
# Filter content (ZMI)) # Filter content (ZMI))
def __init__(self): def __init__(self):
# working_path = self.getPortalObject().portal_preferences.getPreference('subversion_working_copy')
# svn_username = self.getPortalObject().portal_preferences.getPreference('preferred_subversion_user_name')
return Folder.__init__(self, SubversionTool.id) return Folder.__init__(self, SubversionTool.id)
# Filter content (ZMI)) # Filter content (ZMI))
...@@ -148,26 +150,26 @@ class SubversionTool(UniqueObject, Folder): ...@@ -148,26 +150,26 @@ class SubversionTool(UniqueObject, Folder):
# Decode login information. # Decode login information.
return loads(b64decode(login)) return loads(b64decode(login))
# def setLogin(self, realm, user, password): def setLogin(self, realm, user, password):
# """Set login information. """Set login information.
# """ """
# # Get existing login information. Filter out old information. # Get existing login information. Filter out old information.
# login_list = [] login_list = []
# request = self.REQUEST request = self.REQUEST
# cookie = request.get(self.login_cookie_name) cookie = request.get(self.login_cookie_name)
# if cookie: if cookie:
# for login in cookie.split(','): for login in cookie.split(','):
# if self._decodeLogin(login)[0] != realm: if self._decodeLogin(login)[0] != realm:
# login_list.append(login) login_list.append(login)
# # Set the cookie. # Set the cookie.
# response = request.RESPONSE response = request.RESPONSE
# login_list.append(self._encodeLogin(realm, user, password)) login_list.append(self._encodeLogin(realm, user, password))
# value = ','.join(login_list) value = ','.join(login_list)
# expires = (DateTime() + 1).toZone('GMT').rfc822() expires = (DateTime() + 1).toZone('GMT').rfc822()
# response.setCookie(self.login_cookie_name, value, path = '/', expires = expires) response.setCookie(self.login_cookie_name, value, path = '/', expires = expires)
def setLogin(self, username, passwd): # def setLogin(self, username, passwd):
self.login = (username, passwd) # self.login = (username, passwd)
def _getLogin(self, target_realm): def _getLogin(self, target_realm):
request = self.REQUEST request = self.REQUEST
...@@ -289,6 +291,7 @@ class SubversionTool(UniqueObject, Folder): ...@@ -289,6 +291,7 @@ class SubversionTool(UniqueObject, Folder):
root = Dir(path, "normal") root = Dir(path, "normal")
somethingModified = False somethingModified = False
for statusObj in self.status(path) : for statusObj in self.status(path) :
# can be (normal, added, modified, deleted) # can be (normal, added, modified, deleted)
msg_status = statusObj.getTextStatus() msg_status = statusObj.getTextStatus()
...@@ -309,36 +312,30 @@ class SubversionTool(UniqueObject, Folder): ...@@ -309,36 +312,30 @@ class SubversionTool(UniqueObject, Folder):
i += 1 i += 1
if d : if d :
full_pathOfd = '/'+'/'.join(full_path_list[:i]).strip() full_pathOfd = '/'+'/'.join(full_path_list[:i]).strip()
if full_pathOfd not in parent.sub_dirs : if d not in parent.getSubDirs() :
parent.sub_dirs.append(Dir(full_pathOfd, "normal")) parent.sub_dirs.append(Dir(full_pathOfd, "normal"))
parent = parent.getDir(full_pathOfd) parent = parent.getDir(d)
if os.path.isdir(full_path) : if os.path.isdir(full_path) :
if full_path == parent.full_path : if full_path == parent.full_path :
parent.msg_status = str(msg_status) parent.msg_status = str(msg_status)
elif full_path not in parent.sub_dirs : elif filename not in parent.getSubDirs() :
parent.sub_dirs.append(Dir(full_path, str(msg_status))) parent.sub_dirs.append(Dir(filename, str(msg_status)))
else : else :
tmp = parent.getDir(full_path) tmp = parent.getDir(filename)
tmp.msg_status = str(msg_status) tmp.msg_status = str(msg_status)
else : else :
parent.sub_dirs.append(File(full_path, str(msg_status))) parent.sub_dirs.append(File(filename, str(msg_status)))
return somethingModified and root return somethingModified and root
def treeToXML(self, item) : def treeToXML(self, item) :
output = StringIO() output = "<?xml version='1.0' encoding='iso-8859-1'?>"+ os.linesep
output.write("<?xml version='1.0' encoding='iso-8859-1'?>"+ os.linesep) output += "<tree id='0'>" + os.linesep
output.write("<tree id='0'>" + os.linesep)
output = self._treeToXML(item, output, 1, True) output = self._treeToXML(item, output, 1, True)
output.write("</tree>" + os.linesep) output += "</tree>" + os.linesep
try : return output
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) : def _treeToXML(self, item, output, ident, first) :
# Choosing a color coresponding to the status
itemStatus = item.msg_status itemStatus = item.msg_status
if itemStatus == 'added' : if itemStatus == 'added' :
itemColor='green' itemColor='green'
...@@ -348,34 +345,33 @@ class SubversionTool(UniqueObject, Folder): ...@@ -348,34 +345,33 @@ class SubversionTool(UniqueObject, Folder):
itemColor='red' itemColor='red'
else : else :
itemColor='black' itemColor='black'
if isinstance(item, Dir) : if isinstance(item, Dir) :
for i in range(ident) : for i in range(ident) :
output.write('\t') output += '\t'
if first : if first :
output.write('<item open="1" text="%s" id="%s" aCol="%s" '\ output += '<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.name, 'im2="folder.png">'%(item.name,
item.full_path, itemColor,) + os.linesep) item.full_path, itemColor,) + os.linesep
first=False first=False
else : else :
output.write('<item text="%s" id="%s" aCol="%s" im0="folder.png" ' \ output += '<item text="%s" id="%s" aCol="%s" im0="folder.png" ' \
'im1="folder_open.png" im2="folder.png">'%(item.name, 'im1="folder_open.png" im2="folder.png">'%(item.name,
item.full_path, itemColor,) + os.linesep) item.full_path, itemColor,) + os.linesep
for it in item.sub_dirs: for it in item.sub_dirs:
ident += 1 ident += 1
output = self._treeToXML(item.getDir(it.full_path), output, ident, output = self._treeToXML(item.getDir(it.name), output, ident,
first) first)
ident -= 1 ident -= 1
for i in range(ident) : for i in range(ident) :
output.write('\t') output += '\t'
output.write('</item>' + os.linesep) output += '</item>' + os.linesep
else : else :
for i in range(ident) : for i in range(ident) :
output.write('\t') output += '\t'
output.write('<item text="%s" id="%s" aCol="%s" im0="document.png" ' \ output += '<item text="%s" id="%s" aCol="%s" im0="document.png"/>'\
'im1="document.png" im2="document.png"/>'%(item.name, %(item.name, item.full_path, itemColor,) + os.linesep
item.full_path, itemColor,) + os.linesep)
return output return output
InitializeClass(SubversionTool) InitializeClass(SubversionTool)
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