-
Notifications
You must be signed in to change notification settings - Fork 21
Cria parte do utilitário para incluir DOI nos registros h e f de uma data bases #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # coding=utf-8 | ||
| import os | ||
|
|
||
|
|
||
| CISIS = "cisis/mx" | ||
|
|
||
|
|
||
| def update_command(db, mfn, count, proc): | ||
| cmd = ("{CISIS} {db} from={mfn} count={count} " | ||
| "\"proc={proc}\"" | ||
| " copy={db} now -all").format( | ||
| CISIS=CISIS, | ||
| db=db, | ||
| mfn=mfn, | ||
| count=count, | ||
| proc=proc | ||
| ) | ||
| return cmd | ||
|
|
||
|
|
||
| def execute(cmd): | ||
| # TODO usar subprocess | ||
| # TODO remover esta funcao deste modulo | ||
| os.system(cmd) | ||
|
|
||
|
|
||
| def proc_update_doi(file_path, doi, doi_items): | ||
| """ | ||
| Retorna a "proc" que atualiza | ||
| os campos v237 com DOI original e 337 todos os DOI com idioma | ||
| """ | ||
| if not file_path: | ||
| raise ValueError("Invalid value for file_path") | ||
| if not doi: | ||
| raise ValueError("Invalid value for DOI") | ||
| proc_d = "'d337d237a237~{}~'".format(doi) | ||
| proc_a337 = [ | ||
| ",'a337~^l{}^d{}~'".format(lang, _doi) | ||
| for lang, _doi in doi_items | ||
| ] | ||
| return "if 'hf':v706 and v702='{}' then {} fi".format( | ||
| file_path, | ||
| proc_d + ''.join(proc_a337) | ||
| ) | ||
|
|
||
|
|
||
| def proc_update_datetime(file_path, update_date, update_time): | ||
| """ | ||
| Retorna a "proc" que atualiza | ||
| os campos v91 (data) e v92 (hora) da atualização | ||
| """ | ||
| proc = "'d91d92a91~{}~a92~{}~'".format(update_date, update_time) | ||
| return "if v706='o' and v702='{}' then {} fi".format( | ||
| file_path, | ||
| proc | ||
| ) | ||
|
|
||
|
|
||
| def get_commands_to_update_ohf_records_of_a_doc( | ||
| db, file_path, h_mfn, doi, doi_items, update_date, update_time): | ||
| """ | ||
| Gera dois comandos para atualizar 1 documento os registros: | ||
| - h e f: os campos v237 com DOI original e 337 todos os DOI com idioma | ||
| - o: os campos v91 (data) e v92 (hora) da atualização | ||
| """ | ||
| o_mfn = str(int(h_mfn) - 1) | ||
| o_proc = proc_update_datetime(file_path, update_date, update_time) | ||
| o_cmd = update_command(db, o_mfn, 1, o_proc) | ||
| hf_proc = proc_update_doi(file_path, doi, doi_items) | ||
| hf_cmd = update_command(db, h_mfn, 2, hf_proc) | ||
| return [o_cmd, hf_cmd] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import setuptools | ||
|
|
||
|
|
||
| setuptools.setup( | ||
| name="scielo_doi", | ||
| version="0.1", | ||
| author="SciELO", | ||
| author_email="scielo-dev@googlegroups.com", | ||
| description="", | ||
| license="2-clause BSD", | ||
| packages=setuptools.find_packages( | ||
| exclude=["*.tests", "*.tests.*", "tests.*", "tests"] | ||
| ), | ||
| include_package_data=True, | ||
| test_suite="tests", | ||
| ) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| from unittest import TestCase | ||
|
|
||
|
|
||
| from app import cisis | ||
|
|
||
|
|
||
| class TestCisis(TestCase): | ||
|
|
||
| def test_update_command(self): | ||
| db = "base" | ||
| mfn = 100 | ||
| count = 5 | ||
| proc = '@a.proc' | ||
| result = cisis.update_command(db, mfn, count, proc) | ||
| self.assertEqual( | ||
| result, | ||
| "cisis/mx base from=100 count=5 \"proc=@a.proc\" copy=base now -all" | ||
| ) | ||
|
|
||
| def test_proc_update_doi(self): | ||
| file_path = "xml/abc/v1n1/a.xml" | ||
| doi = "10.1590/1809-4392201902421" | ||
| doi_items = [ | ||
| ("pt", "10.1590/1809-4392201902421.1"), | ||
| ("en", "10.1590/1809-4392201902421.2"), | ||
| ("es", "10.1590/1809-4392201902421.3"), | ||
| ] | ||
| result = cisis.proc_update_doi(file_path, doi, doi_items) | ||
| expected = ("if 'hf':v706 and v702='xml/abc/v1n1/a.xml' then " | ||
| "'d337d237a237~10.1590/1809-4392201902421~'," | ||
| "'a337~^lpt^d10.1590/1809-4392201902421.1~'," | ||
| "'a337~^len^d10.1590/1809-4392201902421.2~'," | ||
| "'a337~^les^d10.1590/1809-4392201902421.3~' fi") | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_proc_update_datetime(self): | ||
| file_path = "xml/abc/v1n1/a.xml" | ||
| result = cisis.proc_update_datetime(file_path, '20100501', '1903') | ||
| expected = ("if v706='o' and v702='xml/abc/v1n1/a.xml' then" | ||
| " 'd91d92a91~20100501~a92~1903~' fi") | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_get_commands_to_update_ohf_records_of_a_doc(self): | ||
| db = "base" | ||
| file_path = "xml/a.xml" | ||
| h_mfn = "4" | ||
| doi = "10.1590/1809-4392201902421.1" | ||
| doi_items = [ | ||
| ("pt", "10.1590/1809-4392201902421.1"), | ||
| ("en", "10.1590/1809-4392201902421.2"), | ||
| ("es", "10.1590/1809-4392201902421.3"), | ||
| ] | ||
| upd_date = '20100501' | ||
| upd_time = '1903' | ||
| result = cisis.get_commands_to_update_ohf_records_of_a_doc( | ||
| db, file_path, h_mfn, doi, doi_items, upd_date, upd_time) | ||
|
|
||
| self.assertEqual( | ||
| result[0], | ||
| ( | ||
| "cisis/mx base from=3 count=1 \"proc=" | ||
| "if v706='o' and v702='xml/a.xml' then" | ||
| " 'd91d92a91~20100501~a92~1903~' fi\" " | ||
| "copy=base now -all" | ||
| ) | ||
| ) | ||
| self.assertEqual( | ||
| result[1], | ||
| ( | ||
| "cisis/mx base from=4 count=2 \"proc=" | ||
| "if 'hf':v706 and v702='xml/a.xml' then " | ||
| "'d337d237a237~10.1590/1809-4392201902421.1~'," | ||
| "'a337~^lpt^d10.1590/1809-4392201902421.1~'," | ||
| "'a337~^len^d10.1590/1809-4392201902421.2~'," | ||
| "'a337~^les^d10.1590/1809-4392201902421.3~' fi\" " | ||
| "copy=base now -all" | ||
| ) | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.