Commit 4678365a authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

management command to create sources

parent b1d5b335
import logging
from django.core.management.base import BaseCommand
from django.db.utils import IntegrityError
from metagenedb.apps.catalog.models import Source
logging.basicConfig(format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s')
logger = logging.getLogger()
ITEMS_TO_CREATE = [
{
'name': 'Virgo',
'url': 'https://virgo.igs.umaryland.edu/',
'doi': '10.1038/s41467-020-14677-3'
},
{
'name': 'IGC-9.9M',
'url': 'https://db.cngb.org/microbiome/genecatalog/genecatalog_human/',
'doi': '10.1038/nbt.2942'
},
]
def create_all_sources():
items_to_create = ITEMS_TO_CREATE
for item in items_to_create:
new_entry = Source(**item)
try:
new_entry.save()
except IntegrityError:
logger.info("%s already exists.", item['name'])
class Command(BaseCommand):
help = 'Create gene sources (Virgo and IGC 9.9M at the moment).'
def set_logger_level(self, verbosity):
if verbosity > 2:
logger.setLevel(logging.DEBUG)
elif verbosity > 1:
logger.setLevel(logging.INFO)
def handle(self, *args, **options):
self.set_logger_level(int(options['verbosity']))
create_all_sources()
Markdown is supported
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