Skip to content

Commit

Permalink
Merge pull request #335 from rafaelpezzuto/add-package-name
Browse files Browse the repository at this point in the history
Adiciona modelo para obter nome oficial de pacote
  • Loading branch information
rafaelpezzuto authored Oct 26, 2022
2 parents 45a4d44 + 55a33d4 commit 397d7f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packtools/sps/models/front_articlemeta_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</article>
"""
from packtools.sps.models.dates import ArticleDates
from packtools.sps.models.article_ids import ArticleIds


def _extract_number_and_supplment_from_issue_element(issue):
Expand Down Expand Up @@ -136,3 +137,10 @@ def fpage_seq(self):
@property
def lpage(self):
return self.xmltree.findtext(".//front/article-meta/lpage")

@property
def order(self):
_order = self.xmltree.findtext('.//article-id[@pub-id-type="other"]')
if _order is None:
_order = ArticleIds(self.xmltree).v2
return int(_order)
31 changes: 31 additions & 0 deletions packtools/sps/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from packtools.sps.utils.xml_utils import get_xml_tree
from packtools.sps.validation import erratum
from packtools.sps.models.article_and_subarticles import ArticleAndSubArticles
from packtools.sps.models.article_doi_with_lang import DoiWithLang
from packtools.sps.models.front_articlemeta_issue import ArticleMetaIssue
from packtools.sps.models.front_journal_meta import ISSN, Acronym


class PackageErratumHasUnexpectedQuantityOfXMLFilesError(Exception):
Expand Down Expand Up @@ -70,3 +73,31 @@ def discover_article_xml(self):

x_file_content = get_file_content_from_zip(xmls.pop(), self.zip_path)
self.xmltree_article = get_xml_tree(x_file_content)


class PackageName:
def __init__(self, xmltree):
self.xmltree = xmltree

@property
def name(self):
dwl = DoiWithLang(self.xmltree)
_doi = dwl.main_doi and dwl.main_doi.split("/")[-1]

ami = ArticleMetaIssue(self.xmltree)
_fpage = ami.fpage
if ami.fpage_seq:
_fpage += ami.fpage_seq
last_item = str(_fpage or ami.elocation_id or ami.order or _doi).zfill(5)

issn = ISSN(self.xmltree)
acron = Acronym(self.xmltree)
data = (
issn.epub or issn.ppub,
acron.text,
ami.volume,
ami.number,
ami.suppl and f"s{ami.suppl}",
last_item,
)
return "-".join([str(item).zfill(2) for item in data if item])
2 changes: 1 addition & 1 deletion packtools/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Single source to the version across setup.py and the whole project.
"""
from __future__ import unicode_literals
__version__ = '2.14'
__version__ = '2.15'

0 comments on commit 397d7f7

Please sign in to comment.