SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
64a63d17
Commit
64a63d17
authored
5 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
Add management command to correct issue path
parent
296acb9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
journals/management/commands/repair_issue_path.py
+97
-0
97 additions, 0 deletions
journals/management/commands/repair_issue_path.py
with
97 additions
and
0 deletions
journals/management/commands/repair_issue_path.py
0 → 100644
+
97
−
0
View file @
64a63d17
__copyright__
=
"
Copyright © Stichting SciPost (SciPost Foundation)
"
__license__
=
"
AGPL v3
"
import
os
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
from
journals.models
import
Issue
class
Command
(
BaseCommand
):
"""
Verify path of issue publications and deposits; if wrong, repair.
This command was written to repair the incorrect folder structure of SciPostPhys
volume 5 issue 6, volume 6 issues 1, 2 and 3 (2019-08-08).
"""
help
=
'
Repairs the paths of an issue, including its publications and deposits
'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
--issue_doi_label
'
,
choices
=
[
issue
.
doi_label
for
issue
in
Issue
.
objects
.
all
()],
action
=
'
store
'
,
dest
=
'
issue_doi_label
'
,
help
=
'
doi label of the issue to repair
'
)
def
handle
(
self
,
*
args
,
**
kwargs
):
issue
=
Issue
.
objects
.
get
(
doi_label
=
kwargs
[
'
issue_doi_label
'
])
print
(
'
media root: %s
'
%
settings
.
MEDIA_ROOT
)
print
(
'
issue path: %s
'
%
issue
.
path
)
if
(
'
/%s/%s
'
%
(
issue
.
in_volume
.
number
,
issue
.
number
))
not
in
issue
.
path
:
print
(
'
WARNING: /%s/%s not in issue path %s
'
%
(
issue
.
in_volume
.
number
,
issue
.
number
,
issue
.
path
))
# repair the issue path
old_issue_path
=
issue
.
path
issue_path
=
'
SCIPOST_JOURNALS/{name}/{volnr}/{issuenr}
'
.
format
(
name
=
issue
.
in_volume
.
in_journal
.
name
,
volnr
=
issue
.
in_volume
.
number
,
issuenr
=
issue
.
number
)
issue
.
path
=
issue_path
issue
.
save
()
print
(
'
New issue path: %s
'
%
issue
.
path
)
for
pub
in
issue
.
publications
.
all
():
print
(
'
\t
%s
'
%
pub
.
doi_label
)
old_dir
=
old_issue_path
+
'
/{paper_nr}
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
())
new_dir
=
issue_path
+
'
/{paper_nr}
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
())
os
.
makedirs
(
settings
.
MEDIA_ROOT
+
new_dir
,
exist_ok
=
True
)
new_pub_path
=
new_dir
+
'
/{doi}.pdf
'
.
format
(
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
))
os
.
rename
(
pub
.
pdf_file
.
path
,
settings
.
MEDIA_ROOT
+
new_pub_path
)
pub
.
pdf_file
.
name
=
new_pub_path
pub
.
save
()
print
(
'
\t
%s
'
%
pub
.
pdf_file
.
path
)
# Move the timestamped files
for
deposit
in
pub
.
deposit_set
.
all
():
new_dep_path
=
new_dir
+
'
/{doi}_Crossref_{timestamp}.xml
'
.
format
(
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
),
timestamp
=
deposit
.
timestamp
)
os
.
rename
(
deposit
.
metadata_xml_file
.
path
,
settings
.
MEDIA_ROOT
+
new_dep_path
)
deposit
.
metadata_xml_file
.
name
=
new_dep_path
deposit
.
save
()
print
(
'
\t\t
%s
'
%
deposit
.
metadata_xml_file
.
path
)
# Now move the latest (non-timestamped) one
old_dep_path
=
old_dir
+
'
/{doi}_Crossref.xml
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
))
new_dep_path
=
new_dir
+
'
/{doi}_Crossref.xml
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
))
os
.
rename
(
settings
.
MEDIA_ROOT
+
old_dep_path
,
settings
.
MEDIA_ROOT
+
new_dep_path
)
for
deposit
in
pub
.
doajdeposit_set
.
all
():
new_dep_path
=
new_dir
+
'
/{doi}_DOAJ_{timestamp}.json
'
.
format
(
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
),
timestamp
=
deposit
.
timestamp
)
os
.
rename
(
deposit
.
metadata_DOAJ_file
.
path
,
settings
.
MEDIA_ROOT
+
new_dep_path
)
deposit
.
metadata_DOAJ_file
.
name
=
new_dep_path
deposit
.
save
()
print
(
'
\t\t
%s
'
%
deposit
.
metadata_DOAJ_file
.
path
)
old_dep_path
=
old_dir
+
'
/{doi}_DOAJ.json
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
))
new_dep_path
=
new_dir
+
'
/{doi}_DOAJ.json
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
))
os
.
rename
(
settings
.
MEDIA_ROOT
+
old_dep_path
,
settings
.
MEDIA_ROOT
+
new_dep_path
)
# Remove unneeded directories
os
.
rmdir
(
settings
.
MEDIA_ROOT
+
old_dir
+
'
/{doi}_Crossref
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
)))
os
.
rmdir
(
settings
.
MEDIA_ROOT
+
old_dir
+
'
/{doi}_DOAJ
'
.
format
(
paper_nr
=
pub
.
get_paper_nr
(),
doi
=
pub
.
doi_label
.
replace
(
'
.
'
,
'
_
'
)))
os
.
rmdir
(
settings
.
MEDIA_ROOT
+
old_dir
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment