'Generate the metadata for a tool dependencies package defined for a repository.  The
value of package_name must match the value of the "package" type in the tool config\'s
<requirements> tag set.'

def generate_package_dependency_metadata(self, elem, valid_tool_dependencies_dict, invalid_tool_dependencies_dict):

    repository_dependency_is_valid = True
    repository_dependency_tup = []
    requirements_dict = {}
    error_message = ''
    package_name = elem.get('name', None)
    package_version = elem.get('version', None)
    if (package_name and package_version):
        requirements_dict['name'] = package_name
        requirements_dict['version'] = package_version
        requirements_dict['type'] = 'package'
        for sub_elem in elem:
            if (sub_elem.tag == 'readme'):
                requirements_dict['readme'] = sub_elem.text
            elif (sub_elem.tag == 'repository'):
                (repository_dependency_tup, repository_dependency_is_valid, error_message) = self.handle_repository_elem(repository_elem=sub_elem, only_if_compiling_contained_td=False)
            elif (sub_elem.tag == 'install'):
                package_install_version = sub_elem.get('version', '1.0')
                if (package_install_version == '1.0'):
                    actions_elem_tuples = tool_dependency_util.parse_package_elem(sub_elem, platform_info_dict=None, include_after_install_actions=False)
                    if actions_elem_tuples:
                        actions_elem_tuple = actions_elem_tuples[0]
                        (in_actions_group, actions_elem) = actions_elem_tuple
                        if in_actions_group:
                            for action_elem in actions_elem:
                                if (action_elem.tag == 'package'):
                                    ae_package_name = action_elem.get('name', None)
                                    ae_package_version = action_elem.get('version', None)
                                    if (ae_package_name and ae_package_version):
                                        for sub_action_elem in action_elem:
                                            if (sub_action_elem.tag == 'repository'):
                                                (repository_dependency_tup, repository_dependency_is_valid, error_message) = self.handle_repository_elem(repository_elem=sub_action_elem, only_if_compiling_contained_td=True)
                                elif (action_elem.tag == 'action'):
                                    for sub_action_elem in action_elem:
                                        if (sub_action_elem.tag == 'repository'):
                                            (repository_dependency_tup, repository_dependency_is_valid, error_message) = self.handle_repository_elem(repository_elem=sub_action_elem, only_if_compiling_contained_td=True)
    if requirements_dict:
        dependency_key = ('%s/%s' % (package_name, package_version))
        if repository_dependency_is_valid:
            valid_tool_dependencies_dict[dependency_key] = requirements_dict
        else:
            requirements_dict['error'] = error_message
            invalid_tool_dependencies_dict[dependency_key] = requirements_dict
    return (valid_tool_dependencies_dict, invalid_tool_dependencies_dict, repository_dependency_tup, repository_dependency_is_valid, error_message)
