Skip to content

Commit

Permalink
Merge pull request #6 from robertatakenaka/0.1.1
Browse files Browse the repository at this point in the history
Ajustes para uso em scms-upload (migration)
  • Loading branch information
robertatakenaka authored Sep 25, 2022
2 parents 0eb9db5 + 9b2613c commit 3ba064e
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 36 deletions.
43 changes: 43 additions & 0 deletions scielo_classic_website/classic_ws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from scielo_classic_website import controller, config
from scielo_classic_website.models.issue_files import IssueFiles

# Para Journal, Issue, Document devem ficar disponíveis neste módulo
from scielo_classic_website.models.journal import Journal
from scielo_classic_website.models.issue import Issue
from scielo_classic_website.models.document import Document


def get_bases_work_acron_path(cisis_path, bases_work_acron_file_path, issue_folder=None):
if issue_folder:
return controller.isis_cmd.get_documents_by_issue_folder(
cisis_path, bases_work_acron_file_path, issue_folder)
else:
return bases_work_acron_file_path


def get_document_pids(from_date, to_date):
return controller.isis_cmd.get_document_pids(from_date, to_date)


def get_paragraphs_records(pid):
id_file_path = config.get_paragraphs_id_file_path(pid)
return controller.pids_and_their_records(id_file_path, "artigo")


def get_records_by_pid(pid):
source_path = controller.isis_cmd.get_document_isis_db(pid)
return controller.pids_and_their_records(source_path, "artigo")


def get_records_by_acron(acron, id_folder_path=None):
source_path = controller.get_acron_db_path(acron, id_folder_path)
return controller.pids_and_their_records(source_path, "artigo")


def get_records_by_source_path(db_type, source_path):
return controller.pids_and_their_records(source_path, db_type)


def get_issue_files(acron, issue_folder, config):
issue_files = IssueFiles(acron, issue_folder, config)
return issue_files.files
4 changes: 2 additions & 2 deletions scielo_classic_website/cli/models_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, class_name, data_dictionary):
def create_base_module(self, class_file_path):
with open(class_file_path, "w") as fp:
fp.write("# generated by ModelBuilder\n")
fp.write("from scielo_migration.isisdb.meta_record import MetaRecord\n\n\n")
fp.write("from scielo_classic_website.isisdb.meta_record import MetaRecord\n\n\n")
fp.write(f"{_attributes_var(self.get_attributes())}\n\n\n")

def get_attributes(self):
Expand All @@ -108,7 +108,7 @@ def create_main_module(self, class_file_path, base_module_name):
class_code = _class_init_builder(f"{self._class_name}", f"{base_class_name}")
content = (
"# generated by ModelBuilder",
f"from scielo_migration.isisdb.{base_module_name} import {base_class_name}\n",
f"from scielo_classic_website.isisdb.{base_module_name} import {base_class_name}\n",
"",
f"{class_code}",
)
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from scielo_classic_website.iid2json import id2json3

from scielo_classic_website import isis_cmd
from scielo_classic_website.isisdb import isis_cmd


def pids_and_their_records(source_file_path, db_type):
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/isisdb/base_h_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.meta_record import MetaRecord
from scielo_classic_website.isisdb.meta_record import MetaRecord


ATTRIBUTES = (
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/isisdb/base_issue_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.meta_record import MetaRecord
from scielo_classic_website.isisdb.meta_record import MetaRecord


ATTRIBUTES = (
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/isisdb/base_p_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.meta_record import MetaRecord
from scielo_classic_website.isisdb.meta_record import MetaRecord


ATTRIBUTES = (
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/isisdb/h_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.base_h_record import BaseDocumentRecord
from scielo_classic_website.isisdb.base_h_record import BaseDocumentRecord


# generated by ModelBuilder
Expand Down
28 changes: 25 additions & 3 deletions scielo_classic_website/isisdb/isis_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

def get_document_isis_db(pid):
"""
Consulta a base de dados ISIS artigo e retorna os pids atualizados
em um intervalo de datas (data de processamento do converter)
Consulta a base de dados ISIS artigo e retorna os registros do pid
"""
BASES_ARTIGO_PATH = config.get_bases_artigo_path()
name = date_now_as_folder_name()
Expand Down Expand Up @@ -179,3 +177,27 @@ def get_document_pids(from_date=None, to_date=None):
# 1|OAITS=20210917=2675-54752021000300700
parts = row.strip().split("=")
yield {"updated": parts[1], "pid": "S" + parts[-1]}


def get_documents_by_issue_folder(cisis_path, bases_work_acron_file_path, issue_folder):
"""
Consulta a base de dados ISIS bases-work/acron/acron e filtra por issue_folder
"""
name = date_now_as_folder_name()
finished_file_path = create_temp_file(f"{name}_{issue_folder}_finished.out")
output_file_path = create_temp_file(f"{name}_{issue_folder}_output")

cmds = []
cmds.append(
f'''{cisis_path}/mx {bases_work_acron_file_path} btell=0 '''
f'''"bool={issue_folder}" '''
f'''append={output_file_path} now -all'''
)
cmds.append(
f"echo finished > {finished_file_path}"
)
os.system(";".join(cmds))
while "finished" not in read_file(finished_file_path):
pass
return output_file_path
13 changes: 10 additions & 3 deletions scielo_classic_website/isisdb/issue_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.base_issue_record import BaseIssueRecord
from scielo_classic_website.isisdb.base_issue_record import BaseIssueRecord


# generated by ModelBuilder
Expand All @@ -11,13 +11,20 @@ def __init__(
super().__init__(
record, multi_val_tags, data_dictionary)

@property
def bibliographic_strip_months(self):
for item in self.bibliographic_strip:
yield {"lang": item['language'], "text": item.get('months')}

@property
def start_month_text(self):
return (self.bibliographic_strip.get("month") or '').split("/")[0]
for item in self.bibliographic_strip_months:
return (item.get("text") or '').split("/")[0]

@property
def end_month_text(self):
return (self.bibliographic_strip.get("month") or '').split("/")[-1]
for item in self.bibliographic_strip_months:
return (item.get("text") or '').split("/")[-1]

@property
def start_month(self):
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/isisdb/p_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by ModelBuilder
from scielo_migration.isisdb.base_p_record import BaseParagraphRecord
from scielo_classic_website.isisdb.base_p_record import BaseParagraphRecord


# generated by ModelBuilder
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/models/html_body.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dsm.utils.files_utils import read_file
from scielo_classic_website.utils.files_utils import read_file


class BodyFromISIS:
Expand Down
28 changes: 27 additions & 1 deletion scielo_classic_website/models/issue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from scielo_classic_website.isisdb.issue_record import IssueRecord


Expand All @@ -11,12 +13,16 @@ def __getattr__(self, name):
# fica menos acoplado
if hasattr(self.issue_record, name):
return getattr(self.issue_record, name)
raise AttributeError(name)
raise AttributeError(f"classic_website.Issue has no attribute {name}")

@property
def record(self):
return self._record

@property
def publication_year(self):
return self.issue_record.publication_date[:4]

@property
def supplement(self):
return self.supplement_volume or self.supplement_number
Expand All @@ -33,3 +39,23 @@ def order(self):
def pid(self):
# 0001-371419980003
return self.journal + self.order

@property
def isis_created_date(self):
return self.issue_record.creation_date

@property
def isis_updated_date(self):
return self.issue_record.update_date

@property
def issue_label(self):
pr = self.is_press_release or ''
if self.number in ("ahead", "review"):
return self.publication_year + "n" + self.number + pr
return "".join([
k + v
for k, v in zip(("v", "n", "s", ""), (self.volume, self.number, self.suppl, pr))
if v
])

19 changes: 11 additions & 8 deletions scielo_classic_website/models/issue_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

class IssueFiles:

def __init__(self, acron, issue_folder):
def __init__(self, acron, issue_folder, config):
self.acron = acron
self.issue_folder = issue_folder
self._subdir_acron_issue = os.path.join(acron, issue_folder)
self._htdocs_img_revistas_files = None
self._bases_translation_files = None
self._bases_pdf_files = None
self._bases_xml_files = None
self._config = config

@property
def files(self):
Expand Down Expand Up @@ -51,7 +52,7 @@ def bases_translation_files(self):

paths = glob.glob(
os.path.join(
config.BASES_TRANSLATION_PATH,
self._config["BASES_TRANSLATION_PATH"],
self._subdir_acron_issue, "*")
)
files = []
Expand Down Expand Up @@ -93,7 +94,7 @@ def bases_pdf_files(self):

paths = glob.glob(
os.path.join(
config.BASES_PDF_PATH,
self._config["BASES_PDF_PATH"],
self._subdir_acron_issue, "*")
)
files = []
Expand Down Expand Up @@ -137,7 +138,7 @@ def htdocs_img_revistas_files(self):
if self._htdocs_img_revistas_files is None:
paths = glob.glob(
os.path.join(
config.HTDOCS_IMG_REVISTAS_PATH,
self._config["HTDOCS_IMG_REVISTAS_PATH"],
self._subdir_acron_issue,
"*"
)
Expand All @@ -163,10 +164,12 @@ def htdocs_img_revistas_files(self):
@property
def bases_xml_files(self):
if self._bases_xml_files is None:
paths = os.path.join(
config.BASES_XML_PATH,
self._subdir_acron_issue,
"*.xml"
paths = glob.glob(
os.path.join(
self._config["BASES_XML_PATH"],
self._subdir_acron_issue,
"*.xml"
)
)
files = []
for path in paths:
Expand Down
13 changes: 4 additions & 9 deletions scielo_classic_website/models/journal.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from scielo_classic_website.isisdb.meta_record import MetaRecord
from scielo_classic_website.isisdb.journal_record import JournalRecord


class Journal:
def __init__(self, journal_record):
self.journal_record = journal_record
self.journal_record = JournalRecord(journal_record)

def __getattr__(self, name):
# desta forma Journal não precisa herdar de JournalRecord
# fica menos acoplado
if hasattr(self.journal_record, name):
return getattr(self.journal_record, name)
raise AttributeError(name)
raise AttributeError(
f"classic_website.Journal has no attribute {name}")

@property
def record(self):
Expand Down Expand Up @@ -57,13 +59,6 @@ def online_submission_url(self):
def publication_status(self):
return self.journal_record.current_status

@property
def mission(self):
return {
m['l']: m['_']
for m in self.journal_record.mission
}

@property
def index_at(self):
return self.journal_record.index_coverage
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/spsxml/sps_xml_article_meta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import plumber
from lxml import etree as ET

from scielo_migration.spsxml.sps_xml_attributes import (
from scielo_classic_website.spsxml.sps_xml_attributes import (
CONTRIB_ROLES,
get_attribute_value,
)
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/spsxml/sps_xml_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ATTRIBUTES_PATH,
)

from scielo_migration.attr_values import AttrValues
from scielo_classic_website.attr_values import AttrValues


def _read_csv_file(file_path):
Expand Down
2 changes: 1 addition & 1 deletion scielo_classic_website/spsxml/sps_xml_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
COUNTRY_ITEMS,
)

from scielo_migration.spsxml.sps_xml_article_meta import (
from scielo_classic_website.spsxml.sps_xml_article_meta import (
XMLArticleMetaSciELOArticleIdPipe,
XMLArticleMetaArticleIdDOIPipe,
XMLArticleMetaArticleCategoriesPipe,
Expand Down

0 comments on commit 3ba064e

Please sign in to comment.