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

computer = state_change[\'object\']\n
portal = computer.getPortalObject()\n
# Get required arguments\n
kwargs = state_change.kwargs\n
\n
# Required args\n
# Raise TypeError if all parameters are not provided\n
try:\n
  software_release_url = kwargs[\'software_release_url\']\n
  state = kwargs["state"]\n
except KeyError:\n
  raise TypeError("Computer_requestSoftwareReleaseChange takes exactly 2 arguments")\n
\n
tag = "%s_%s_inProgress" % (computer.getUid(), \n
                               software_release_url)\n
\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
  # The software instance is already under creation but can not be fetched from catalog\n
  # As it is not possible to fetch informations, it is better to raise an error\n
  raise NotImplementedError(tag)\n
\n
software_installation_portal_type = \'Software Installation\'\n
# Check if it already exists\n
software_installation_list = portal.portal_catalog(\n
  portal_type=software_installation_portal_type,\n
  url_string={\'query\': software_release_url, \'key\': \'ExactMatch\'},\n
  validation_state="validated",\n
  default_aggregate_uid=computer.getUid(),\n
  limit=2,\n
  )\n
\n
if len(software_installation_list) > 1:\n
  raise NotImplementedError("Too many Software Installation %s found %s" % (software_release_url, [x.path for x in software_installation_list]))\n
elif len(software_installation_list) == 1:\n
  software_installation = software_installation_list[0].getObject()\n
  if (software_installation.getUrlString() != software_release_url) or \\\n
     (software_installation.getValidationState() != "validated") or \\\n
     (software_installation.getAggregate() != computer.getRelativeUrl()):\n
    raise NotImplementedError("The system was not able to get the expected Software Installation")\n
else:\n
  if (state == "destroyed"):\n
    # No need to create destroyed subscription.\n
    return\n
  software_installation_reference = "SOFTINSTALL-%s" % context.getPortalObject().portal_ids\\\n
      .generateNewId(id_group=\'slap_software_installation_reference\', id_generator=\'uid\')\n
  software_installation = portal.getDefaultModule(portal_type=software_installation_portal_type).newContent(\n
    portal_type=software_installation_portal_type,\n
    reference=software_installation_reference,\n
    url_string=software_release_url,\n
    aggregate=computer.getRelativeUrl(),\n
    activate_kw={\'tag\': tag},\n
    destination_section=computer.getSourceAdministration()\n
  )\n
\n
# Change desired state\n
if (state == "available"):\n
  software_installation.requestStart()\n
elif (state == "destroyed"):\n
  software_installation.requestDestroy(activate_kw={\'tag\': tag})\n
else:\n
  raise ValueError("state should be available or destroyed, but is %s" % state)\n
\n
# Change the state at the end to allow to execute updateLocalRoles only once in the transaction\n
validation_state = software_installation.getValidationState()\n
slap_state = software_installation.getSlapState()\n
if validation_state == \'draft\':\n
  portal.portal_workflow.doActionFor(software_installation,\n
                                           \'validate_action\')\n
\n
context.REQUEST.set(\'software_installation_url\', software_installation.getRelativeUrl())\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>Computer_requestSoftwareReleaseChange</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
