<?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[

from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery\n
\n
software_instance = state_change[\'object\']\n
portal = software_instance.getPortalObject()\n
\n
# avoid conflicting with "in progress" update tasks\n
tag_list = ["%s_destroyInProgress" % software_instance.getUid(), "%s_startInProgress" % software_instance.getUid()]\n
for tag in tag_list:\n
  if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
    # do nothing if something is progress\n
    return\n
portal_preferences = portal.portal_preferences\n
\n
update_resource_relative_url = portal.restrictedTraverse(portal_preferences.getPreferredInstanceUpdateResource()).getUid()\n
setup_resource_uid = portal.restrictedTraverse(portal_preferences.getPreferredInstanceSetupResource()).getUid()\n
hosting_resource_uid = portal.restrictedTraverse(portal_preferences.getPreferredInstanceHostingResource()).getUid()\n
\n
service_uid_state_mapping = {\n
  setup_resource_uid: [\'stopped\'],\n
  hosting_resource_uid: [\'started\', \'delivered\']\n
}\n
previous_packing_list_line = context.SoftwareInstance_getInstancePackingListLine(state_change)\n
\n
if previous_packing_list_line.getResourceUid() == hosting_resource_uid:\n
  if previous_packing_list_line.getSimulationState() not in service_uid_state_mapping[hosting_resource_uid]:\n
    return\n
elif previous_packing_list_line.getResourceUid() == setup_resource_uid:\n
  if previous_packing_list_line.getSimulationState() not in service_uid_state_mapping[setup_resource_uid]:\n
    return\n
else:\n
  # not "supported" resource, eg. cleanup\n
  return\n
\n
# time to create packing list\n
context.SoftwareInstance_createSalePackingList(state_change, portal_preferences.getPreferredInstanceUpdateResource()).confirm()\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>SoftwareInstance_requestUpdate</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
