Skip to content

Commit

Permalink
merge: branch '109-add-commands-to-init-single-instance' into 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmnldwg committed Nov 28, 2023
2 parents b21c0c7 + d8e6d2c commit 6254f6a
Show file tree
Hide file tree
Showing 13 changed files with 528 additions and 337 deletions.
16 changes: 8 additions & 8 deletions gunicorn@.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ User = www-data
Group = www-data
WorkingDirectory = /srv/www/%i
EnvironmentFile = /srv/www/%i/.env
TimeoutSec = 600
TimeoutSec = 1200

ExecStartPre = /srv/www/%i/.venv/bin/manage.py migrate --noinput
ExecStartPre = /srv/www/%i/.venv/bin/manage.py collectstatic --noinput
ExecStartPre = /srv/www/%i/.venv/bin/manage.py init_institutions
ExecStartPre = /srv/www/%i/.venv/bin/manage.py init_users
ExecStartPre = /srv/www/%i/.venv/bin/manage.py init_datasets
ExecStartPre = /srv/www/%i/.venv/bin/manage.py init_riskmodels
ExecStart = /srv/www/%i/.venv/bin/python -m gunicorn -c /srv/www/%i/gunicorn.conf.py
ExecStartPre = .venv/bin/manage.py migrate --noinput
ExecStartPre = .venv/bin/manage.py collectstatic --noinput
ExecStartPre = .venv/bin/manage.py add_institutions --from-file initial/add_institutions
ExecStartPre = .venv/bin/manage.py add_users --from-file initial/add_users
ExecStartPre = .venv/bin/manage.py add_datasets --from-file initial/add_datasets
ExecStartPre = .venv/bin/manage.py add_riskmodels --from-file initial/add_riskmodels
ExecStart = .venv/bin/python -m gunicorn -c gunicorn.conf.py

ExecReload = kill -s HUP $MAINPID
ExecStop = kill -s TERM $MAINPID
Expand Down
32 changes: 32 additions & 0 deletions initial/datasets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"git_repo_url": "https://github.com/rmnldwg/lydata",
"revision": "main",
"data_path": "2021-usz-oropharynx/data.csv"
},
{
"git_repo_url": "https://github.com/rmnldwg/lydata",
"revision": "main",
"data_path": "2021-clb-oropharynx/data.csv"
},
{
"git_repo_url": "https://github.com/rmnldwg/lydata",
"revision": "main",
"data_path": "2023-isb-multisite/data.csv"
},
{
"git_repo_url": "https://github.com/rmnldwg/lydata",
"revision": "main",
"data_path": "2023-clb-multisite/data.csv"
},
{
"git_repo_url": "https://github.com/rmnldwg/lydata.private",
"revision": "2023-usz-hypopharynx-larynx",
"data_path": "2023-usz-hypopharynx-larynx/data.csv"
},
{
"git_repo_url": "https://github.com/rmnldwg/lydata.private",
"revision": "2023-hvh-oropharynx",
"data_path": "2023-hvh-oropharynx/data.csv"
}
]
38 changes: 38 additions & 0 deletions initial/institutions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "University Hospital Zurich",
"shortname": "USZ",
"street": "Rämistrasse 100",
"city": "Zürich",
"country": "CH",
"phone": "+41442553566",
"logo": "logos/usz.png"
},
{
"name": "Centre Léon Bérard",
"shortname": "CLB",
"street": "28 Rue Laennec",
"city": "Lyon",
"country": "FR",
"phone": "+33478782828",
"logo": "logos/clb.png"
},
{
"name": "Inselspital Bern",
"shortname": "ISB",
"street": "Freiburgstrasse 15",
"city": "Bern",
"country": "CH",
"phone": "+41316322111",
"logo": "logos/isb.png"
},
{
"name": "Vall d'Hebron Barcelona Hospital",
"shortname": "HVH",
"street": "Passeig de la Vall d'Hebron, 119-129",
"city": "Barcelona",
"country": "ES",
"phone": "+34934893000",
"logo": "logos/hvh.png"
}
]
23 changes: 23 additions & 0 deletions initial/riskmodels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"git_repo_owner": "rmnldwg",
"git_repo_name": "lynference",
"revision": "win-graph-v1",
"params_path": "params.yaml",
"num_samples": 100
},
{
"git_repo_owner": "rmnldwg",
"git_repo_name": "lynference",
"revision": "complete-part1-v1",
"params_path": "params.yaml",
"num_samples": 100
},
{
"git_repo_owner": "rmnldwg",
"git_repo_name": "lynference",
"revision": "add-I-to-II-and-IV-to-V",
"params_path": "params.yaml",
"num_samples": 100
}
]
83 changes: 83 additions & 0 deletions initial/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"email": "roman.ludwig@usz.ch",
"first_name": "Roman",
"last_name": "Ludwig",
"institution": "USZ",
"is_active": true,
"is_staff": true,
"is_superuser": true
},
{
"email": "jan.unkelbach@usz.ch",
"first_name": "Jan",
"last_name": "Unkelbach",
"institution": "USZ",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "vincent.gregoire@lyon.unicancer.fr",
"first_name": "Vincent",
"last_name": "Grégoire",
"institution": "CLB",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "roland.giger@insel.ch",
"first_name": "Roland",
"last_name": "Giger",
"institution": "ISB",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "lars.widmer@usz.ch",
"first_name": "Lars",
"last_name": "Widmer",
"institution": "USZ",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "esmee.looman@usz.ch",
"first_name": "Esmee",
"last_name": "Looman",
"institution": "USZ",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "yoel.perezhaas@usz.ch",
"first_name": "Yoel",
"last_name": "Perez Haas",
"institution": "USZ",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "julian.broennimann@uzh.ch",
"first_name": "Julian",
"last_name": "Brönnimann",
"institution": "USZ",
"is_active": true,
"is_staff": false,
"is_superuser": false
},
{
"email": "sergi.benavente@vallhebron.cat",
"first_name": "Sergio",
"last_name": "Benavente Norza",
"institution": "HVH",
"is_active": true,
"is_staff": false,
"is_superuser": false
}
]
87 changes: 87 additions & 0 deletions lyprox/accounts/management/commands/add_institutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
Management command to add institutions from a file or the command line.
"""
import json
from pathlib import Path
from django.core.management import base
from django.core.management.base import CommandParser
from django.db.utils import IntegrityError

from lyprox.accounts.models import Institution


class Command(base.BaseCommand):
"""Command to add institutions from a file or the command line."""
help = __doc__

def add_arguments(self, parser: CommandParser) -> None:
"""Add arguments to command."""
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
"--from-file",
type=Path,
help="Path to JSON file with list of institutions.",
)
group.add_argument(
"--from-stdin",
action="store_true",
help="Use command line arguments to create a single institution.",
)
parser.add_argument(
"--name", type=str, help="Name of institution.",
)
parser.add_argument(
"--shortname", type=str, help="Abbreviation of institution.",
)
parser.add_argument(
"--street", type=str, help="Street and house number of institution.",
)
parser.add_argument(
"--city", type=str, help="City of institution.",
)
parser.add_argument(
"--country", type=str, help="Country of institution.",
)
parser.add_argument(
"--phone", type=str, help="Phone number of institution.",
)
parser.add_argument(
"--logo", type=str, help="Path of insitution's logo within media.",
)

def handle(self, *args, **options):
"""Execute command."""
if not options["from_stdin"]:
with open(options["from_file"], "r", encoding="utf-8") as json_file:
institution_configurations = json.load(json_file)
else:
institution_configurations = [{
"name": options["name"],
"shortname": options["shortname"],
"street": options["street"],
"city": options["city"],
"country": options["country"],
"phone": options["phone"],
"logo": options["logo"],
}]

for config in institution_configurations:
try:
Institution.objects.create(**config)
self.stdout.write(
self.style.SUCCESS(
f"Institution '{config['name']}' created."
)
)
except IntegrityError:
self.stdout.write(
self.style.WARNING(
f"Institution '{config['name']}' already exists. Skipping."
)
)
except Exception as exc:
self.stdout.write(
self.style.ERROR(
f"Could not create institution '{config['name']}': {exc}"
)
)
Loading

0 comments on commit 6254f6a

Please sign in to comment.