# Generated by Django 2.0.8 on 2021-02-09 13:16

from django.conf import settings
from django.db import migrations, models


def modify_job_templates(apps, schema_editor):

    if not settings.MIGRATE_INITIAL_DATA:
        return

    JobTemplate = apps.get_model('dashboard', 'JobTemplate')

    JobTemplate.objects.filter(job_template_type="pulltrans").update(
        job_template_desc='Download translations from CI platform and submit back.'
    )

    JobTemplate.objects.filter(job_template_type="pushtrans").update(
        job_template_json_str='{"job":{"ci_pipeline":"%PIPELINE_UUID%","exception":"raise","execution":"sequential",'
                              '"name":"push translations","package":"%PACKAGE_NAME%","return_type":"json",'
                              '"tasks":[{"clone":[{"name":"git repo"},{"type":"%REPO_TYPE%"},'
                              '{"branch":"%REPO_BRANCH%"},{"recursive":false}]},{"filter":[{"name":"files"},'
                              '{"domain":"%PACKAGE_NAME%"},{"ext":"PO"},{"dir":""}]},{"upload":[{"name":"Push files"},'
                              '{"target_langs":"%TARGET_LANGS%"},{"prehook":"skip"},{"posthook":"skip"},'
                              '{"import_settings":"project"},{"update":false}]}],"type":"pushtrans"}}'
    )

    JobTemplate.objects.filter(job_template_type="syncupstream").update(
        job_template_json_str='{"job":{"exception":"raise","execution":"sequential","name":"upstream stats",'
                              '"package":"%PACKAGE_NAME%","return_type":"json","tasks":[{"clone":[{"name":"git repo"},'
                              '{"type":"%REPO_TYPE%"},{"branch":"%REPO_BRANCH%"},{"recursive":false}]},'
                              '{"filter":[{"name":"files"},{"domain":"%PACKAGE_NAME%"},{"ext":"PO"},{"dir":""}]},'
                              '{"calculate":"Stats"}],"type":"syncupstream"}}'
    )

    JobTemplate.objects.filter(job_template_type="syncdownstream").update(
        job_template_json_str='{"job":{"name":"downstream stats","type":"syncdownstream","buildsys":"%BUILD_SYSTEM%",'
                              '"exception":"raise","execution":"sequential","package":"%PACKAGE_NAME%",'
                              '"return_type":"json","tags":["%BUILD_TAG%"],"tasks":[{"get":"latest build info"},'
                              '{"download":"SRPM"},{"unpack":"SRPM"},{"load":"Spec file"},{"unpack":"tarball"},'
                              '{"apply":"patch"},{"filter":[{"name":"files"},{"domain":"%PACKAGE_NAME%"},'
                              '{"ext":"PO"},{"dir":""}]},{"calculate":"Stats"}]}}'
    )

    job_templates = [
        JobTemplate(job_template_type="dpushtrans", job_template_name="Download and Push Translations",
                    job_template_desc="Download translations and upload to the CI platform.",
                    job_template_params="{package_name,repo_type,repo_branch,pipeline_uuid,target_langs}",
                    job_template_json_str='{"job":{"ci_pipeline":"%PIPELINE_UUID%","exception":"raise",'
                                          '"execution":"sequential","name":"pull translations",'
                                          '"package":"%PACKAGE_NAME%","return_type":"json",'
                                          '"tasks":[{"download":[{"name":"Translation files"},'
                                          '{"target_langs":"%TARGET_LANGS%"},{"type":"%REPO_TYPE%"},'
                                          '{"branch":"%REPO_BRANCH%"}]},{"upload":[{"name":"Push files"},'
                                          '{"target_langs":"%TARGET_LANGS%"},{"prehook":"skip"},'
                                          '{"posthook":"skip"},{"import_settings":"project"},'
                                          '{"update":false}]}],"type":"dpushtrans"}}'
                    ),
    ]
    JobTemplate.objects.bulk_create(job_templates)


class Migration(migrations.Migration):

    dependencies = [
        ('dashboard', '0010_auto_20210201_0845'),
    ]

    operations = [
        migrations.AlterField(
            model_name='cipipeline',
            name='ci_pipeline_visibility',
            field=models.BooleanField(default=True, verbose_name='CI Pipeline Visibility'),
        ),
        migrations.AlterField(
            model_name='package',
            name='upstream_l10n_url',
            field=models.URLField(blank=True, max_length=2000, null=True, verbose_name='Upstream Localization URL'),
        ),
        migrations.RunPython(modify_job_templates, reverse_code=migrations.RunPython.noop),
    ]

# Generated by Django 2.0.8 on 2021-02-09 13:16

from django.conf import settings
from django.db import migrations, models


def modify_job_templates(apps, schema_editor):

    if not settings.MIGRATE_INITIAL_DATA:
        return

    JobTemplate = apps.get_model('dashboard', 'JobTemplate')

    JobTemplate.objects.filter(job_template_type="pulltrans").update(
        job_template_desc='Download translations from CI platform and submit back.'
    )

    JobTemplate.objects.filter(job_template_type="pushtrans").update(
        job_template_json_str='{"job":{"ci_pipeline":"%PIPELINE_UUID%","exception":"raise","execution":"sequential",'
                              '"name":"push translations","package":"%PACKAGE_NAME%","return_type":"json",'
                              '"tasks":[{"clone":[{"name":"git repo"},{"type":"%REPO_TYPE%"},'
                              '{"branch":"%REPO_BRANCH%"},{"recursive":false}]},{"filter":[{"name":"files"},'
                              '{"domain":"%PACKAGE_NAME%"},{"ext":"PO"},{"dir":""}]},{"upload":[{"name":"Push files"},'
                              '{"target_langs":"%TARGET_LANGS%"},{"prehook":"skip"},{"posthook":"skip"},'
                              '{"import_settings":"project"},{"update":false}]}],"type":"pushtrans"}}'
    )

    JobTemplate.objects.filter(job_template_type="syncupstream").update(
        job_template_json_str='{"job":{"exception":"raise","execution":"sequential","name":"upstream stats",'
                              '"package":"%PACKAGE_NAME%","return_type":"json","tasks":[{"clone":[{"name":"git repo"},'
                              '{"type":"%REPO_TYPE%"},{"branch":"%REPO_BRANCH%"},{"recursive":false}]},'
                              '{"filter":[{"name":"files"},{"domain":"%PACKAGE_NAME%"},{"ext":"PO"},{"dir":""}]},'
                              '{"calculate":"Stats"}],"type":"syncupstream"}}'
    )

    JobTemplate.objects.filter(job_template_type="syncdownstream").update(
        job_template_json_str='{"job":{"name":"downstream stats","type":"syncdownstream","buildsys":"%BUILD_SYSTEM%",'
                              '"exception":"raise","execution":"sequential","package":"%PACKAGE_NAME%",'
                              '"return_type":"json","tags":["%BUILD_TAG%"],"tasks":[{"get":"latest build info"},'
                              '{"download":"SRPM"},{"unpack":"SRPM"},{"load":"Spec file"},{"unpack":"tarball"},'
                              '{"apply":"patch"},{"filter":[{"name":"files"},{"domain":"%PACKAGE_NAME%"},'
                              '{"ext":"PO"},{"dir":""}]},{"calculate":"Stats"}]}}'
    )

    job_templates = [
        JobTemplate(job_template_type="dpushtrans", job_template_name="Download and Push Translations",
                    job_template_desc="Download translations and upload to the CI platform.",
                    job_template_params="{package_name,repo_type,repo_branch,pipeline_uuid,target_langs}",
                    job_template_json_str='{"job":{"ci_pipeline":"%PIPELINE_UUID%","exception":"raise",'
                                          '"execution":"sequential","name":"pull translations",'
                                          '"package":"%PACKAGE_NAME%","return_type":"json",'
                                          '"tasks":[{"download":[{"name":"Translation files"},'
                                          '{"target_langs":"%TARGET_LANGS%"},{"type":"%REPO_TYPE%"},'
                                          '{"branch":"%REPO_BRANCH%"}]},{"upload":[{"name":"Push files"},'
                                          '{"target_langs":"%TARGET_LANGS%"},{"prehook":"skip"},'
                                          '{"posthook":"skip"},{"import_settings":"project"},'
                                          '{"update":false}]}],"type":"dpushtrans"}}'
                    ),
    ]
    JobTemplate.objects.bulk_create(job_templates)


class Migration(migrations.Migration):

    dependencies = [
        ('dashboard', '0010_auto_20210201_0845'),
    ]

    operations = [
        migrations.AlterField(
            model_name='cipipeline',
            name='ci_pipeline_visibility',
            field=models.BooleanField(default=True, verbose_name='CI Pipeline Visibility'),
        ),
        migrations.AlterField(
            model_name='package',
            name='upstream_l10n_url',
            field=models.URLField(blank=True, max_length=2000, null=True, verbose_name='Upstream Localization URL'),
        ),
        migrations.RunPython(modify_job_templates, reverse_code=migrations.RunPython.noop),
    ]

# Generated by Django 2.0.8 on 2021-02-09 13:16