-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dc3ded
commit 871bfa5
Showing
5 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,17 @@ | ||
#!/usr/bin/env sh | ||
|
||
repo=$1 | ||
|
||
cd $repo/ | ||
chmod +x yaml-to-latex.py | ||
# ./yaml-to-latex.py -i metadata.yaml -o metadata.tex | ||
make clean | ||
make > out.log | ||
|
||
## git | ||
# cd .. | ||
# git add $repo | ||
# git commit -m "Add paper $repo" | ||
# git push -u origin 2022_${repo} | ||
# gh pr create --title "[2022] Paper $repo" --body-file ../.github/PULL_REQUEST_TEMPLATE.md | ||
# git checkout main |
This file contains 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,34 @@ | ||
#!/usr/bin/env sh | ||
|
||
repo=$1 | ||
|
||
cd $repo/ | ||
|
||
## Remove template files | ||
rm Makefile | ||
rm article.py | ||
rm header.tex | ||
rm rescience.cls | ||
rm -rf roboto | ||
rm -rf source-code-pro | ||
rm -rf source-sans-pro | ||
rm -rf source-serif-pro | ||
rm yaml-to-latex.py | ||
rm yaml-to-markdown.py | ||
rm yaml-to-bibtex.py | ||
|
||
## Make the symbolic links | ||
ln -s ../template/Makefile . | ||
ln -s ../template/article.py . | ||
ln -s ../template/header.tex . | ||
ln -s ../template/rescience.cls . | ||
ln -s ../template/roboto . | ||
ln -s ../template/source-code-pro . | ||
ln -s ../template/source-sans-pro . | ||
ln -s ../template/source-serif-pro . | ||
ln -s ../template/yaml-to-latex.py . | ||
ln -s ../template/yaml-to-bibtex.py . | ||
ln -s ../template/yaml-to-markdown.py . | ||
|
||
## Git | ||
# git checkout -b 2022_$repo |
This file contains 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,15 @@ | ||
#!/usr/bin/env sh | ||
|
||
repo=$1 | ||
|
||
python update_metadata.py --folder_name $repo | ||
|
||
cd $repo/ | ||
|
||
## Build | ||
chmod +x yaml-to-latex.py | ||
# ./yaml-to-latex.py -i metadata.yaml -o metadata.tex | ||
make clean | ||
make > out.log | ||
|
||
cd .. |
This file contains 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,37 @@ | ||
#!/usr/bin/env sh | ||
|
||
COMMENT="update article metadata" | ||
|
||
for repo in {1..9} | ||
do | ||
echo $repo | ||
git checkout 2022_$repo | ||
./update.sh $repo | ||
git add $repo | ||
git commit -m "$COMMENT $repo" | ||
git push -u origin 2022_${repo} | ||
git checkout main | ||
|
||
done | ||
|
||
for repo in {10..27} | ||
do | ||
echo $repo | ||
git checkout 2022_paper_$repo | ||
./update.sh $repo | ||
git add $repo | ||
git commit -m "$COMMENT $repo" | ||
git push -u origin 2022_paper_${repo} | ||
git checkout main | ||
done | ||
|
||
for repo in {28..45} | ||
do | ||
echo $repo | ||
git checkout 2022_$repo | ||
./update.sh $repo | ||
git add $repo | ||
git commit -m "$COMMENT $repo" | ||
git push -u origin 2022_${repo} | ||
git checkout main | ||
done |
This file contains 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,151 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
from fire import Fire | ||
from pathlib import Path | ||
import requests | ||
|
||
zenodo_tokens = { | ||
"sandbox": os.environ.get("ZENODO_SANDBOX_TOKEN", ""), | ||
"production": os.environ.get("ZENODO_TOKEN", ""), | ||
} | ||
zenodo_url = {"sandbox": "sandbox.zenodo.org", "production": "zenodo.org"} | ||
|
||
|
||
def reserve_doi(server, token): | ||
"""Reserve a new DOI on Zenodo""" | ||
|
||
headers = {"Content-Type": "application/json"} | ||
url = f"https://{server}/api/deposit/depositions" | ||
response = requests.post( | ||
url, params={"access_token": token}, json={}, headers=headers | ||
) | ||
if response.status_code != 201: | ||
raise IOError("%s: " % response.status_code + str(response)) | ||
data = response.json() | ||
return data["id"], data["metadata"]["prereserve_doi"]["doi"] | ||
|
||
|
||
def reserve_zenodo_info(server="sandbox"): | ||
server_url = zenodo_url[server] | ||
token = zenodo_tokens[server] | ||
article_id, article_doi = reserve_doi(server_url, token) | ||
article_url = f"https://{server_url}/record/{article_id}/files/article.pdf" | ||
return article_id, article_doi, article_url | ||
|
||
|
||
def load_metadata(folder_name): | ||
mfile = Path(str(folder_name)) / "metadata.yaml" | ||
lines = [] | ||
with open(mfile) as fp: | ||
for line in fp: | ||
lines.append(line) | ||
return lines | ||
|
||
|
||
def save_metadata(mlines, folder_name): | ||
mfile = Path(str(folder_name)) / "metadata.yaml" | ||
with open(mfile, "w") as fp: | ||
for line in mlines: | ||
fp.write(line) | ||
|
||
|
||
def update_line(lines, search, dest): | ||
dt_line = [i for i, line in enumerate(lines) if search in line] | ||
assert len(dt_line) == 1, f"Found {len(dt_line)} matches" | ||
lines[dt_line[0]] = dest | ||
return lines | ||
|
||
|
||
def update_article(lines, doi="", url=""): | ||
article_start = [i for i, line in enumerate(lines) if line.startswith("article:")] | ||
article_end = [i for i, line in enumerate(lines) if line.startswith("journal:")] | ||
assert len(article_start) == 1 | ||
assert len(article_end) == 1 | ||
article_start = article_start[0] | ||
article_end = article_end[0] - 2 | ||
doi_line = [ | ||
i | ||
for i, line in enumerate(lines) | ||
if (i > article_start and i < article_end and "doi:" in line) | ||
] | ||
assert len(doi_line) == 1 | ||
doi_line = doi_line[0] | ||
url_line = [ | ||
i | ||
for i, line in enumerate(lines) | ||
if (i > article_start and i < article_end and "url:" in line) | ||
] | ||
assert len(url_line) == 1 | ||
url_line = url_line[0] | ||
|
||
lines[doi_line] = f" - doi: {doi}\n" | ||
lines[url_line] = f" - url: {url}\n" | ||
return lines | ||
|
||
|
||
CONT_LINES = [ | ||
" - name:", | ||
" orcid:\n", | ||
" role: editor\n", | ||
" - name:\n", | ||
" orcid:\n", | ||
" role: reviewer\n", | ||
" - name:\n", | ||
" orcid:\n", | ||
" role: reviewer\n", | ||
] | ||
|
||
EDITOR_LIST = ["Koustuv Sinha", "Maurits Bleeker", "Samarth Bhargav"] | ||
|
||
|
||
def update_contributors(lines, delim=",\\\\ "): | ||
contributors_start = [ | ||
i for i, line in enumerate(lines) if line.startswith("contributors:") | ||
] | ||
assert len(contributors_start) == 1 | ||
contributors_start = contributors_start[0] + 1 | ||
contributors_end = contributors_start + len(CONT_LINES) | ||
lines[contributors_start:contributors_end] = CONT_LINES | ||
editors_names = delim.join(EDITOR_LIST) | ||
lines[contributors_start] = f" - name: {editors_names}\n" | ||
return lines | ||
|
||
|
||
def run( | ||
folder_name="", | ||
received_date="February 4, 2023", | ||
accepted_date="April 19, 2023", | ||
published_date="July 20, 2023", | ||
article_number=0, | ||
volume=9, | ||
issue=2, | ||
zenodo=False, | ||
zenodo_server="sandbox", | ||
): | ||
mlines = load_metadata(folder_name) | ||
if folder_name != "editorial": | ||
mlines = update_line(mlines, "received:", f" - received: {received_date}\n") | ||
mlines = update_line(mlines, "accepted:", f" - accepted: {accepted_date}\n") | ||
mlines = update_line(mlines, "number:", f" - number: {folder_name}\n") | ||
else: | ||
mlines = update_line(mlines, "number:", f" - number: {article_number}\n") | ||
mlines = update_line(mlines, "published:", f" - published: {published_date}\n") | ||
mlines = update_line(mlines, "volume:", f" - volume: {volume}\n") | ||
mlines = update_line(mlines, "issue:", f" - issue: {issue}\n") | ||
|
||
mlines = update_contributors(mlines) | ||
|
||
if zenodo: | ||
# Update DOI | ||
## fetch from Zenodo | ||
|
||
article_id, article_doi, article_url = reserve_zenodo_info(zenodo_server) | ||
mlines = update_article(mlines, doi=article_doi, url=article_url) | ||
|
||
# update file | ||
save_metadata(mlines, folder_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
Fire(run) |