Commit c283984e authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_forge: add some tools in erp5_toolbox

parent 59100d94
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># It should be ran in an alarm thank to a property sheet constraint.\n
\n
if fixit:\n
return ["Cannot fix automatically, please do it manually. (Or deactivate the constraint to force upgrade.)"]\n
\n
portal = context.getPortalObject()\n
\n
black_list = getattr(context, "Base_getInstalledBusinessTemplateBlackListForModificationList", lambda: ())()\n
bt_list = [\n
x.getObject()\n
for x in portal.portal_catalog(\n
portal_type="Business Template",\n
installation_state="installed",\n
)\n
if x.getInstallationState() == "installed" and x.getTitle() not in black_list and x.getId() not in black_list\n
]\n
\n
diff_list = []\n
for bt in bt_list:\n
diff = bt.BusinessTemplate_getPrintableModificationListFromZODB()\n
if diff:\n
diff_list += ["===== %s =====" % bt.getTitle()] + diff.splitlines()\n
\n
return diff_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>fixit=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_reportInstalledBusinessTemplateModification</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,9 +50,8 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># This script comes with Base_gitDiffWithZODBAsText.\n
# It should be ran in an alarm thank to a property sheet constraint.\n
# Where does this script should be commited?\n
<value> <string># It should be ran in an alarm thank to a property sheet constraint.\n
\n
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery\n
\n
if fixit:\n
......@@ -77,18 +76,9 @@ bt_list = [\n
if bt.getInstallationState() == "installed"\n
]\n
\n
#bt_list = [\n
# x.getObject()\n
# for x in portal.portal_catalog(\n
# portal_type="Business Template",\n
# installation_state="installed",\n
# )\n
# if x.getInstallationState() == "installed"\n
#]\n
\n
diff_list = []\n
for bt in bt_list:\n
diff = bt.BusinessTemplate_getDiffWithZODBAsText()\n
diff = bt.BusinessTemplate_getPrintableModificationListFromZODB()\n
if diff:\n
diff_list += ["===== %s =====" % bt.getTitle()] + diff.splitlines()\n
\n
......
......@@ -52,9 +52,6 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
# This script comes with Base_reportUpgraderBunisessTemplateDiff.\n
# It can be ran individualy, of course.\n
# Where does this script should be commited? erp5_core?\n
# This diff script clones and builds it\'s own bt for comparision,\n
# check with other script why this is not already done. Like on\n
# TemplateTool_getDetailedDiff in erp5_core portal skin.\n
......@@ -63,11 +60,12 @@ from ZODB.POSException import ConflictError\n
\n
template_tool = context.getPortalObject().portal_templates\n
\n
assert context.getBuildingState() == "built", "%s != \'built\'" % repr(context.getBuildingState())\n
if context.getBuildingState() != "built":\n
return "AssertionError(\\"%s != \'built\'\\",)" % repr(context.getBuildingState())\n
\n
def getDiffObjectList(business_template, installed_bt_for_diff):\n
# business_template is assumed built and installed\n
modified_object_list = business_template.preinstall(check_dependencies=0, compare_to=installed_bt_for_diff)\n
modified_object_list = installed_bt_for_diff.preinstall(check_dependencies=0, compare_to=business_template)\n
keys = modified_object_list.keys()\n
#keys.sort() # XXX don\'t care ?\n
bt_id = business_template.getId()\n
......@@ -97,29 +95,25 @@ try:\n
except ConflictError:\n
raise\n
except Exception as e:\n
print(e)\n
return printed #.split("\\n")\n
print(repr(e))\n
return printed\n
\n
name = "installed_bt_for_diff"\n
try:\n
installed_bt_for_diff.setId(name)\n
installed_bt_for_diff.setId("installed_bt_for_diff")\n
installed_bt_for_diff.build()\n
for diff_object in getSortedDiffObjectList(context, installed_bt_for_diff):\n
print("%s (%s) -> %s" % (diff_object.object_state, diff_object.object_class, diff_object.object_id))\n
# Just uncomment these lines below to append diff to the text\n
#if diff_object.object_state != "Modified":\n
# continue\n
#print(context.diffObject(diff_object, compare_with=name).lstrip())\n
#print("")\n
if diff_object.object_state != "Modified":\n
continue\n
print(installed_bt_for_diff.diffObject(diff_object, compare_with=context.getId()).lstrip())\n
print("")\n
except ConflictError:\n
raise\n
except Exception as e:\n
print(e)\n
finally:\n
template_tool.manage_delObjects(ids=[installed_bt_for_diff.getId()])\n
print(repr(e))\n
template_tool.manage_delObjects(ids=[installed_bt_for_diff.getId()])\n
\n
#return "<pre>" + printed.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\\"", "&quot;") + "</pre>"\n
return printed #.split("\\n")\n
return printed\n
]]></string> </value>
......@@ -130,7 +124,7 @@ return printed #.split("\\n")\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BusinessTemplate_getDiffWithZODBAsText</string> </value>
<value> <string>BusinessTemplate_getPrintableDiffWithZODB</string> </value>
</item>
</dictionary>
</pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
# This diff script clones and builds it\'s own bt for comparision,\n
# check with other script why this is not already done. Like on\n
# TemplateTool_getDetailedDiff in erp5_core portal skin.\n
from Products.ERP5Type.Document import newTempBase\n
from ZODB.POSException import ConflictError\n
\n
template_tool = context.getPortalObject().portal_templates\n
\n
if context.getBuildingState() != "built":\n
return "AssertionError(\\"%s != \'built\'\\",)" % repr(context.getBuildingState())\n
\n
def getDiffObjectList(business_template, installed_bt_for_diff):\n
# business_template is assumed built and installed\n
modified_object_list = installed_bt_for_diff.preinstall(check_dependencies=0, compare_to=business_template)\n
keys = modified_object_list.keys()\n
bt_id = business_template.getId()\n
i = 0\n
object_list = []\n
for object_id in keys:\n
object_state, object_class = modified_object_list[object_id]\n
line = newTempBase(template_tool, \'tmp_install_%s\' % (str(i))) # template_tool or context?\n
line.edit(object_id=object_id, object_state=object_state, object_class=object_class, bt1=bt_id, bt2=bt_id)\n
line.setUid(\'new_%s\' % object_id)\n
object_list.append(line)\n
i += 1\n
return object_list\n
\n
def getSortedDiffObjectList(business_template, installed_bt_for_diff):\n
return sorted(\n
sorted(\n
getDiffObjectList(business_template, installed_bt_for_diff),\n
key=lambda x: x.object_id\n
),\n
key=lambda x: x.object_state\n
)\n
\n
\n
try:\n
installed_bt_for_diff = context.Base_createCloneDocument(clone=1, batch_mode=1)\n
except ConflictError:\n
raise\n
except Exception as e:\n
print(repr(e))\n
return printed\n
\n
try:\n
installed_bt_for_diff.setId("installed_bt_for_diff")\n
installed_bt_for_diff.build()\n
for diff_object in getSortedDiffObjectList(context, installed_bt_for_diff):\n
print("%s (%s) -> %s" % (diff_object.object_state, diff_object.object_class, diff_object.object_id))\n
except ConflictError:\n
raise\n
except Exception as e:\n
print(repr(e))\n
template_tool.manage_delObjects(ids=[installed_bt_for_diff.getId()])\n
\n
return printed\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BusinessTemplate_getPrintableModificationListFromZODB</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""Usage example:\n
\n
- in a url ``<your erp5 url>/portal_skins/Folder_resolvePath?path=**``\n
- in a script ``context.Folder_resolvePath("**")``\n
- for a business template path list ``portal.Folder_resolvePath(bt.getTemplatePathList())``\n
\n
Arguments:\n
\n
- ``path`` can be a string or a list (if ``path_list`` is not defined).\n
- ``path_list`` must be a list (if ``path`` is not defined).\n
- ``traverse`` if True, return object list instead of path list.\n
- ``globbing`` if False, handle "*" and "**" as normal id.\n
"""\n
if path is None:\n
if path_list is None:\n
raise TypeError("`path` or `path_list` argument should be defined")\n
elif isinstance(path, (list, tuple)):\n
path_list = path\n
else:\n
path_list = [path]\n
\n
context_is_portal = context.getPortalObject() == context\n
contextTraverse = context.restrictedTraverse\n
\n
resolved_list = []\n
append = resolved_list.append\n
\n
if globbing:\n
for path in path_list:\n
if path == "*" or (context_is_portal and path == "**"): # acts like _resolvePath in Products.ERP5.Document.BusinessTemplate.PathTemplateItem\n
for sub_path, sub_obj in context.ZopeFind(context, search_sub=0):\n
if traverse:\n
append(sub_obj)\n
else:\n
append(sub_path)\n
elif path == "**":\n
for sub_path, sub_obj in context.ZopeFind(context, search_sub=1):\n
if traverse:\n
append(sub_obj)\n
else:\n
append(sub_path)\n
elif path.endswith("/**"):\n
parent_path = path[:-3]\n
obj = contextTraverse(parent_path)\n
for sub_path, sub_obj in obj.ZopeFind(obj, search_sub=1):\n
if traverse:\n
append(sub_obj)\n
else:\n
append(parent_path + "/" + sub_path)\n
elif path.endswith("/*"):\n
parent_path = path[:-2]\n
obj = contextTraverse(parent_path)\n
for sub_path, sub_obj in obj.ZopeFind(obj, search_sub=0):\n
if traverse:\n
append(sub_obj)\n
else:\n
append(parent_path + "/" + sub_path)\n
else:\n
if traverse:\n
append(contextTraverse(path))\n
else:\n
append(path)\n
else:\n
for path in path_list:\n
if traverse:\n
append(contextTraverse(path))\n
else:\n
append(path)\n
return resolved_list\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>path=None, path_list=None, traverse=False, globbing=True</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Folder_resolvePath</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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