Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippidb-web
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
iPPIDB
ippidb-web
Commits
d31a21c6
Commit
d31a21c6
authored
8 years ago
by
Hervé MENAGER
Browse files
Options
Downloads
Patches
Plain Diff
migrate proteins and choose migrated models with arguments
# Please enter the commit message for your changes. Lines starting
parent
16ed6a33
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
ippisite/ippidb/management/commands/import_v1_data.py
+50
-17
50 additions, 17 deletions
ippisite/ippidb/management/commands/import_v1_data.py
with
50 additions
and
17 deletions
ippisite/ippidb/management/commands/import_v1_data.py
+
50
−
17
View file @
d31a21c6
from
django.core.management
import
BaseCommand
import
mysql.connector
from
ippidb.models
import
Bibliography
from
ippidb.models
import
Bibliography
,
Protein
class
Command
(
BaseCommand
):
help
=
"
Import data from the local v1 database
"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
--bibliographies
'
,
action
=
'
store_true
'
,
dest
=
'
bibliographies
'
,
default
=
False
,
help
=
'
Flush and migrate bibliographies
'
,
)
parser
.
add_argument
(
'
--proteins
'
,
action
=
'
store_true
'
,
dest
=
'
proteins
'
,
default
=
False
,
help
=
'
Flush and migrate proteins
'
,
)
def
handle
(
self
,
*
args
,
**
options
):
conn
=
mysql
.
connector
.
connect
(
host
=
"
localhost
"
,
user
=
"
root
"
,
password
=
"
ippidb
"
,
database
=
"
ippidb
"
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"""
SELECT * FROM biblio
"""
)
rows
=
cursor
.
fetchall
()
Bibliography
.
objects
.
all
().
delete
()
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully flushed bibliography table
'
))
for
row
in
rows
:
try
:
b
=
Bibliography
()
if
row
[
1
]
==
'
article
'
:
b
.
source
=
'
PM
'
if
options
[
'
bibliographies
'
]:
cursor
.
execute
(
"""
SELECT * FROM biblio
"""
)
rows
=
cursor
.
fetchall
()
Bibliography
.
objects
.
all
().
delete
()
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully flushed bibliography table
'
))
for
row
in
rows
:
try
:
b
=
Bibliography
()
if
row
[
1
]
==
'
article
'
:
b
.
source
=
'
PM
'
else
:
b
.
source
=
'
PT
'
b
.
id_source
=
row
[
2
]
b
.
save
()
except
Exception
as
e
:
self
.
stdout
.
write
(
self
.
style
.
ERROR
(
'
Failed inserting {}
'
.
format
(
row
[
2
])))
else
:
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully inserted {}
'
.
format
(
row
[
2
])))
if
options
[
'
proteins
'
]:
cursor
.
execute
(
"""
SELECT * FROM protein
"""
)
rows
=
cursor
.
fetchall
()
Protein
.
objects
.
all
().
delete
()
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully flushed protein table
'
))
for
row
in
rows
:
try
:
p
=
Protein
()
p
.
uniprot_id
=
row
[
1
]
p
.
save
()
except
Exception
as
e
:
self
.
stdout
.
write
(
self
.
style
.
ERROR
(
'
Failed inserting {} {}
'
.
format
(
row
[
1
],
row
[
2
])))
else
:
b
.
source
=
'
PT
'
b
.
id_source
=
row
[
2
]
b
.
save
()
except
Exception
as
e
:
self
.
stdout
.
write
(
self
.
style
.
ERROR
(
'
Failed inserting {}
'
.
format
(
row
[
2
])))
else
:
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully inserted {}
'
.
format
(
row
[
2
])))
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully inserted {} {}
'
.
format
(
row
[
1
],
row
[
2
])))
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