def export_olx(self, tarball, root_path):
def append_asset_to_soup_and_export(asset_):<EOL><INDENT>if isinstance(asset_, Item):<EOL><INDENT>try:<EOL><INDENT>unique_url = asset_.export_olx(tarball, root_path)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>unique_name = get_file_name_without_extension(unique_url)<EOL>asset_type = asset_.genus_type.identifier<EOL>asset_tag = my_soup.new_tag(asset_type)<EOL>asset_tag['<STR_LIT>'] = unique_name<EOL>getattr(my_soup, my_tag).append(asset_tag)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>unique_urls = asset_.export_olx(tarball, root_path)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>for index, ac in enumerate(asset_.get_asset_contents()):<EOL><INDENT>asset_type = ac.genus_type.identifier<EOL>unique_url = unique_urls[index]<EOL>unique_name = get_file_name_without_extension(unique_url)<EOL>asset_tag = my_soup.new_tag(asset_type)<EOL>asset_tag['<STR_LIT>'] = unique_name<EOL>getattr(my_soup, my_tag).append(asset_tag)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>def get_file_name_without_extension(filepath):<EOL><INDENT>return filepath.split('<STR_LIT:/>')[-<NUM_LIT:1>].replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>my_path = None<EOL>if self.my_osid_object.is_sequestered():<EOL><INDENT>for asset in self.assets:<EOL><INDENT>try:<EOL><INDENT>asset.export_olx(tarball, root_path)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>my_tag = self.my_osid_object.genus_type.identifier<EOL>expected_name = self.get_unique_name(tarball, self.url, my_tag, root_path)<EOL>my_path = '<STR_LIT>'.format(root_path,<EOL>my_tag,<EOL>expected_name)<EOL>my_soup = BeautifulSoup('<STR_LIT:<>' + my_tag + '<STR_LIT>', '<STR_LIT>')<EOL>getattr(my_soup, my_tag)['<STR_LIT>'] = self.my_osid_object.display_name.text<EOL>if my_tag == '<STR_LIT>':<EOL><INDENT>getattr(my_soup, my_tag)['<STR_LIT>'] = self.my_osid_object.group_id_to_child<EOL>getattr(my_soup, my_tag)['<STR_LIT>'] = self.my_osid_object.user_partition_id.text<EOL><DEDENT>rm = self.my_osid_object._get_provider_manager('<STR_LIT>')<EOL>if self.my_osid_object._proxy is None:<EOL><INDENT>cls = rm.get_composition_lookup_session()<EOL><DEDENT>else:<EOL><INDENT>cls = rm.get_composition_lookup_session(proxy=self.my_osid_object._proxy)<EOL><DEDENT>cls.use_federated_repository_view()<EOL>cls.use_unsequestered_composition_view()<EOL>for child_id in self.my_osid_object.get_child_ids():<EOL><INDENT>child = cls.get_composition(child_id)<EOL>if child.is_sequestered():<EOL><INDENT>for asset in child.assets:<EOL><INDENT>append_asset_to_soup_and_export(asset)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>child_type = child.genus_type.identifier<EOL>child_tag = my_soup.new_tag(child_type)<EOL>child_path = child.export_olx(tarball, root_path)<EOL>if child_path is not None:<EOL><INDENT>child_tag['<STR_LIT>'] = get_file_name_without_extension(child_path)<EOL><DEDENT>getattr(my_soup, my_tag).append(child_tag)<EOL><DEDENT><DEDENT>for asset in self.assets:<EOL><INDENT>append_asset_to_soup_and_export(asset)<EOL><DEDENT>self.write_to_tarfile(tarball, my_path, my_soup)<EOL><DEDENT>return my_path<EOL>
if sequestered, only export the assets