def get_document_sps_package(current_version): """ Dada a versão atual do documento registrado no Kernel, retorna um objeto de SPS_Package Args: current_version (str): a versão atual do documento registrado no Kernel Returns: SPS_Package Raises: GetSPSPackageFromDocManifestException """ response = requests.get(current_version["data"]) try: xml_str = response.text.encode("utf-8") xml_tree = etree.fromstring(xml_str) return SPS_Package(xml_tree, '') except ( AttributeError, etree.XMLSyntaxError, etree.Error, ) as e: raise GetSPSPackageFromDocManifestException( "Unable to get SPS Package of %s: %s" % (current_version["data"], e) )
def get_sps_package(self, issue): xml_text = f""" <article><article-meta> <issue>{issue}</issue> </article-meta></article> """ xmltree = etree.fromstring(xml_text) return SPS_Package(xmltree, "sps_package")
def is_document_to_delete(zipfile, sps_xml_file): parser = etree.XMLParser(remove_blank_text=True, no_network=True) try: metadata = SPS_Package(etree.XML(zipfile.read(sps_xml_file), parser), sps_xml_file) except (etree.XMLSyntaxError, TypeError, KeyError) as exc: raise DocumentToDeleteException(str(exc)) from None else: return metadata.is_document_deletion, metadata.scielo_pid_v3
def get_xml_data(xml_content, xml_package_name): """ - Obter scielo ID - Obter infos de periódico e fascículo - Obter nomes dos arquivos ativos digitais - Obter nomes dos arquivos PDF - Obter idiomas (original e traduções) """ parser = etree.XMLParser(remove_blank_text=True, no_network=True) try: metadata = SPS_Package(etree.XML(xml_content, parser), xml_package_name) except (etree.XMLSyntaxError, TypeError) as exc: raise PutXMLInObjectStoreException( 'Could not get xml data from "{}" : {}'.format( xml_package_name, str(exc))) from None else: pdfs = [{ "lang": metadata.original_language, "filename": "{}.pdf".format(xml_package_name), "mimetype": "application/pdf", }] for lang in metadata.translation_languages: pdfs.append({ "lang": lang, "filename": "{}-{}.pdf".format(xml_package_name, lang), "mimetype": "application/pdf", }) _xml_data = { "scielo_id": metadata.scielo_id, "issn": metadata.issn, "year": metadata.year, "order": metadata.order, "xml_package_name": xml_package_name, "assets": [{ "asset_id": asset_name } for asset_name in metadata.assets_names], "pdfs": pdfs, } for attr in ["volume", "number", "supplement"]: if getattr(metadata, attr) is not None: _xml_data[attr] = getattr(metadata, attr) return _xml_data
def _get_related_articles(xml): """ Obtém a lista de documentos relacionados do XML e atualiza os documentos dessa realação. Tag no XML que representa essa relação: <related-article ext-link-type="doi" id="ra1" related-article-type="corrected-article" xlink:href="10.1590/S0103-50532006000200015"/> """ try: etree_xml = et.XML(xml) except ValueError as ex: logging.error("Erro ao tentar analisar(parser) do XML, erro: %s", ex) else: sps_package = SPS_Package(etree_xml) for related_dict in sps_package.related_articles: _update_related_articles(article, related_dict)