Commit 1e2afbe9 authored by Kevin Deldycke's avatar Kevin Deldycke

Properties exported to an XML file are now sorted for easy diff.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3920 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 61c5987e
...@@ -356,7 +356,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -356,7 +356,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# This is to record the maximum value of uids. Because this uses the class Length # This is to record the maximum value of uids. Because this uses the class Length
# in BTrees.Length, this does not generate conflict errors. # in BTrees.Length, this does not generate conflict errors.
_max_uid = None _max_uid = None
# These are class variable on memory, so shared only by threads in the same Zope instance. # These are class variable on memory, so shared only by threads in the same Zope instance.
# This is set to the time when reserved uids are cleared in this Zope instance. # This is set to the time when reserved uids are cleared in this Zope instance.
_local_clear_reserved_time = None _local_clear_reserved_time = None
...@@ -385,40 +385,50 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -385,40 +385,50 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
""" """
f = StringIO() f = StringIO()
f.write('<?xml version="1.0"?>\n<SQLCatalogData>\n') f.write('<?xml version="1.0"?>\n<SQLCatalogData>\n')
id_list = self.propertyIds() property_id_list = self.propertyIds()
for id in id_list: # Get properties and values
value = self.getProperty(id) property_list = []
for property_id in property_id_list:
if value is None: value = self.getProperty(property_id)
# What is this? Not used? if value is not None:
continue property_list.append((property_id, value))
# Sort for easy diff
property_list.sort(lambda x, y: cmp(x[0], y[0]))
for property in property_list:
property_id = property[0]
value = property[1]
if type(value) == type(""): if type(value) == type(""):
f.write(' <property id=%s type="str">%s</property>\n' % (quoteattr(id), escape(value))) f.write(' <property id=%s type="str">%s</property>\n' % (quoteattr(property_id), escape(value)))
elif type(value) in (type(()), type([])): elif type(value) in (type(()), type([])):
f.write(' <property id=%s type="tuple">\n' % quoteattr(id)) f.write(' <property id=%s type="tuple">\n' % quoteattr(property_id))
# Sort for easy diff
item_list = []
for item in value: for item in value:
if type(item) in (type(""), type(u"")): if type(item) in (type(""), type(u"")):
f.write(' <item type="str">%s</item>\n' % escape(str(item))) item_list.append(item)
else: item_list.sort()
# Ignore the other types at the moment. for item in item_list:
pass f.write(' <item type="str">%s</item>\n' % escape(str(item)))
f.write(' </property>\n') f.write(' </property>\n')
else:
# Ignore the other types at the moment.
pass
# XXX Although filters are not properties, output filters here. # XXX Although filters are not properties, output filters here.
# XXX Ideally, filters should be properties in Z SQL Methods, shouldn't they? # XXX Ideally, filters should be properties in Z SQL Methods, shouldn't they?
if hasattr(self, 'filter_dict'): if hasattr(self, 'filter_dict'):
for id in self.filter_dict.keys(): filter_list = []
filt = self.filter_dict[id] for filter_id in self.filter_dict.keys():
if not filt['filtered']: filter_definition = self.filter_dict[id]
filter_list.append((filter_id, filter_definition))
# Sort for easy diff
filter_list.sort(lambda x, y: cmp(x[0], y[0]))
for filter_item in filter_list:
filter_id = filter_item[0]
filter_def = filter_item[1]
if not filter_def['filtered']:
# If a filter is not activated, no need to output it. # If a filter is not activated, no need to output it.
continue continue
if not filt['expression']: if not filter_def['expression']:
# If the expression is not specified, meaningless to specify it. # If the expression is not specified, meaningless to specify it.
continue continue
f.write(' <filter id=%s expression=%s />\n' % (quoteattr(id), quoteattr(filt['expression']))) f.write(' <filter id=%s expression=%s />\n' % (quoteattr(filter_id), quoteattr(filter_def['expression'])))
# For now, portal types are not exported, because portal types are too specific to each site. # For now, portal types are not exported, because portal types are too specific to each site.
f.write('</SQLCatalogData>\n') f.write('</SQLCatalogData>\n')
...@@ -463,7 +473,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -463,7 +473,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
value = tuple(value) value = tuple(value)
setattr(self, id, value) setattr(self, id, value)
if not hasattr(self, 'filter_dict'): if not hasattr(self, 'filter_dict'):
self.filter_dict = PersistentMapping() self.filter_dict = PersistentMapping()
for filt in root.getElementsByTagName("filter"): for filt in root.getElementsByTagName("filter"):
...@@ -529,18 +539,18 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -529,18 +539,18 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Reserved uids have been removed. # Reserved uids have been removed.
self.clearReserved() self.clearReserved()
# Add a dummy item so that SQLCatalog will not use existing uids again. # Add a dummy item so that SQLCatalog will not use existing uids again.
if self._max_uid is not None and self._max_uid() != 0: if self._max_uid is not None and self._max_uid() != 0:
method_id = self.sql_catalog_reserve_uid method_id = self.sql_catalog_reserve_uid
method = getattr(self, method_id) method = getattr(self, method_id)
self._max_uid.change(1) self._max_uid.change(1)
method(uid = self._max_uid()) method(uid = self._max_uid())
# Remove the cache of catalog schema. # Remove the cache of catalog schema.
if hasattr(self, '_v_catalog_schema_dict') : if hasattr(self, '_v_catalog_schema_dict') :
del self._v_catalog_schema_dict del self._v_catalog_schema_dict
self._clearSecurityCache() self._clearSecurityCache()
def clearReserved(self): def clearReserved(self):
...@@ -602,7 +612,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -602,7 +612,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
def _getCatalogSchema(self, table=None): def _getCatalogSchema(self, table=None):
catalog_schema_dict = getattr(aq_base(self), '_v_catalog_schema_dict', {}) catalog_schema_dict = getattr(aq_base(self), '_v_catalog_schema_dict', {})
if table not in catalog_schema_dict: if table not in catalog_schema_dict:
result_list = [] result_list = []
try: try:
...@@ -619,9 +629,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -619,9 +629,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
pass pass
catalog_schema_dict[table] = tuple(result_list) catalog_schema_dict[table] = tuple(result_list)
self._v_catalog_schema_dict= catalog_schema_dict self._v_catalog_schema_dict= catalog_schema_dict
return catalog_schema_dict[table] return catalog_schema_dict[table]
def getColumnIds(self): def getColumnIds(self):
""" """
Calls the show column method and returns dictionnary of Calls the show column method and returns dictionnary of
...@@ -880,7 +890,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -880,7 +890,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
XXX: For now newUid is used to allocated UIDs. Is this good? Is it better to INSERT then SELECT? XXX: For now newUid is used to allocated UIDs. Is this good? Is it better to INSERT then SELECT?
""" """
LOG('catalogObjectList', 0, 'called with %d objects' % len(object_list)) LOG('catalogObjectList', 0, 'called with %d objects' % len(object_list))
if withCMF: if withCMF:
zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
else: else:
...@@ -1018,7 +1028,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1018,7 +1028,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
except: except:
LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list)) LOG("SQLCatalog Warning: could not catalog objects with method %s" % method_name,100, str(object_list))
raise raise
if psyco is not None: psyco.bind(catalogObjectList) if psyco is not None: psyco.bind(catalogObjectList)
def uncatalogObject(self, path): def uncatalogObject(self, path):
...@@ -1276,7 +1286,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1276,7 +1286,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
elif type(sort_index) is not type(()) and type(sort_index) is not type([]): elif type(sort_index) is not type(()) and type(sort_index) is not type([]):
sort_index = None sort_index = None
# If sort_index is a dictionnary # If sort_index is a dictionnary
# then parse it and change it # then parse it and change it
sort_on = None sort_on = None
...@@ -1302,7 +1312,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1302,7 +1312,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
if not related_methods.has_key((table_list,method_id)): if not related_methods.has_key((table_list,method_id)):
related_methods[(table_list,method_id)] = 1 related_methods[(table_list,method_id)] = 1
# Prepend renamed table name # Prepend renamed table name
key = "%s.%s" % (related_table_map[(table_list,method_id)][-1][-1], related_column[key]) key = "%s.%s" % (related_table_map[(table_list,method_id)][-1][-1], related_column[key])
elif key_is_acceptable: elif key_is_acceptable:
if key.find('.') < 0: if key.find('.') < 0:
# if the key is only used by one table, just append its name # if the key is only used by one table, just append its name
...@@ -1362,7 +1372,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1362,7 +1372,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
if not related_methods.has_key((table_list,method_id)): if not related_methods.has_key((table_list,method_id)):
related_methods[(table_list,method_id)] = 1 related_methods[(table_list,method_id)] = 1
# Prepend renamed table name # Prepend renamed table name
key = "%s.%s" % (related_table_map[(table_list,method_id)][-1][-1], related_column[key]) key = "%s.%s" % (related_table_map[(table_list,method_id)][-1][-1], related_column[key])
elif key_is_acceptable: elif key_is_acceptable:
if key.find('.') < 0: if key.find('.') < 0:
# if the key is only used by one table, just append its name # if the key is only used by one table, just append its name
...@@ -1434,7 +1444,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1434,7 +1444,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
query_value = [query_value] query_value = [query_value]
operator_value = value.get('operator', 'or') operator_value = value.get('operator', 'or')
range_value = value.get('range') range_value = value.get('range')
if range_value : if range_value :
query_min = min(query_value) query_min = min(query_value)
query_max = max(query_value) query_max = max(query_value)
...@@ -1501,7 +1511,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1501,7 +1511,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression = "(%s) AND (%s)" % (kw['where_expression'], join(where_expression, ' AND ') ) where_expression = "(%s) AND (%s)" % (kw['where_expression'], join(where_expression, ' AND ') )
else: else:
where_expression = join(where_expression, ' AND ') where_expression = join(where_expression, ' AND ')
limit_expression = kw.get('limit', None) limit_expression = kw.get('limit', None)
if type(limit_expression) in (type(()), type([])): if type(limit_expression) in (type(()), type([])):
limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1]) limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1])
...@@ -1532,7 +1542,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1532,7 +1542,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
def searchResults(self, REQUEST=None, used=None, **kw): def searchResults(self, REQUEST=None, used=None, **kw):
""" Builds a complex SQL where_expression to simulate ZCalatog behaviour """ """ Builds a complex SQL where_expression to simulate ZCalatog behaviour """
""" Returns a list of brains from a set of constraints on variables """ """ Returns a list of brains from a set of constraints on variables """
# The used argument is deprecated and is ignored # The used argument is deprecated and is ignored
try: try:
# Get the search method # Get the search method
method = getattr(self, self.sql_search_results) method = getattr(self, self.sql_search_results)
...@@ -1603,12 +1613,12 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1603,12 +1613,12 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
""" """
if withCMF: if withCMF:
method_id_list = [zsql_method.id for zsql_method in self.getFilterableMethodList()] method_id_list = [zsql_method.id for zsql_method in self.getFilterableMethodList()]
# Remove unused filters. # Remove unused filters.
for id in self.filter_dict.keys(): for id in self.filter_dict.keys():
if id not in method_id_list: if id not in method_id_list:
del self.filter_dict[id] del self.filter_dict[id]
for id in method_id_list: for id in method_id_list:
# We will first look if the filter is activated # We will first look if the filter is activated
if not self.filter_dict.has_key(id): if not self.filter_dict.has_key(id):
......
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