Skip to content
Snippets Groups Projects
Commit 4a64906a authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add stoponfail option for protein import

parent 02e9cd45
No related branches found
No related tags found
No related merge requests found
from django.core.management import BaseCommand
from django.core.management import BaseCommand, CommandError
import mysql.connector
from ippidb.models import Bibliography, Protein, Taxonomy
......@@ -22,6 +22,14 @@ class Command(BaseCommand):
default=False,
help='Flush and migrate proteins',
)
parser.add_argument(
'--stoponfail',
action='store_true',
dest='stoponfail',
default=False,
help='Stop on fail',
)
def handle(self, *args, **options):
conn = mysql.connector.connect(host="localhost",user="root",password="ippidb", database="ippidb")
......@@ -57,7 +65,12 @@ class Command(BaseCommand):
p.uniprot_id = row[1]
p.save()
except Exception as e:
self.stdout.write(self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
if options['stoponfail']:
import traceback
self.stderr.write(traceback.format_exc())
raise CommandError('Failed inserting {} {}'.format(row[1], row[2]))
else:
self.stdout.write(self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
else:
self.stdout.write(self.style.SUCCESS('Successfully inserted {} {}'.format(row[1], row[2])))
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment