Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Migration: add nailgun compat fix to fits cmd
Browse files Browse the repository at this point in the history
Make sure that the command works when Nailgun's binary is called `ng`
and `nailgun-ng`.
  • Loading branch information
sevein committed Oct 2, 2018
1 parent 3c91cc7 commit 4b00092
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions fpr/migrations/0026_fits_nailgun_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

from django.db import migrations


OLD_FITS_CMD_UUID = '0b0d301f-b586-45d5-ba35-d76da57ce32a'
NEW_FITS_CMD_UUID = '1a0394dc-528b-4a03-8c2b-1c158f1fb313'
OLD_FITS_RULE_UUID = '296a131d-ce70-45ae-b800-6c71b3ea46f0'
NEW_FITS_RULE_UUID = 'c3b06895-ef9d-401e-8c51-ac585f955655'


def data_migration_up(apps, schema_editor):
"""Replace the FITS command with one that is compatible with environments
where the Nailgun binary is called either `ng` or `nailgun-ng`.
"""
FPCommand = apps.get_model('fpr', 'FPCommand')
FPRule = apps.get_model('fpr', 'FPRule')

fits_tool_uuid = 'c5465b07-8dc7-475e-a5c9-ccb2ba2ed083'
xml_format_uuid = 'd60e5243-692e-4af7-90cd-40c53cb8dc7d'
unknown_format_uuid = '0ab4cd40-90e7-4d75-b294-498177b3897d'

FPCommand.objects\
.filter(uuid=OLD_FITS_CMD_UUID)\
.update(enabled=False)

new_cmd = (
'set -euo pipefail\n'
'IFS=$\'\\n\\t\'\n'
'tempdir=$(mktemp -d %tmpDirectory%fits.XXXXXX)\n'
'if type ng-nailgun 1>/dev/null 2>/dev/null\n'
' then function ng { ng-nailgun "$@"; }\n'
' else function ng { ng "$@"; }\n'
'fi\n'
'ng edu.harvard.hul.ois.fits.Fits'
' -i "%relativeLocation%"'
' -o "$tempdir/fits.xml" >/dev/null\n'
'cat "$tempdir/fits.xml"\n'
'rm -r "$tempdir"')

FPCommand.objects.create(
uuid=NEW_FITS_CMD_UUID,
tool_id=fits_tool_uuid,
replaces_id=OLD_FITS_CMD_UUID,
command_usage='characterization',
command=new_cmd,
script_type='bashScript',
output_format_id=xml_format_uuid,
description='FITS')

FPRule.objects\
.filter(uuid=OLD_FITS_RULE_UUID)\
.update(enabled=False)

FPRule.objects.create(
uuid=NEW_FITS_RULE_UUID,
replaces_id=OLD_FITS_RULE_UUID,
format_id=unknown_format_uuid,
command_id=NEW_FITS_CMD_UUID,
purpose='default_characterization')


def data_mgiration_down(apps, schema_editor):
FPCommand = apps.get_model('fpr', 'FPCommand')
FPRule = apps.get_model('fpr', 'FPRule')

FPRule.objects.filter(uuid=NEW_FITS_RULE_UUID).delete()
FPRule.objects.filter(uuid=OLD_FITS_RULE_UUID).update(enabled=True)
FPCommand.objects.filter(uuid=NEW_FITS_CMD_UUID).delete()
FPCommand.objects.filter(uuid=OLD_FITS_CMD_UUID).update(enabled=True)


class Migration(migrations.Migration):

dependencies = [
('fpr', '0025_update_fido_1312'),
]

operations = [
migrations.RunPython(data_migration_up, data_mgiration_down),
]

0 comments on commit 4b00092

Please sign in to comment.