diff --git a/roles/pdc/frontend/files/exportbranches.py b/roles/pdc/frontend/files/exportbranches.py index 97c2b7f496..0b5b9e596b 100644 --- a/roles/pdc/frontend/files/exportbranches.py +++ b/roles/pdc/frontend/files/exportbranches.py @@ -1,15 +1,24 @@ +""" Export component branches. + +This is used to drive the pagure-sync-bugzilla script. +""" + +import collections import json from django.core.management.base import BaseCommand from pdc.apps.componentbranch.models import ComponentBranch from pdc.apps.componentbranch.serializers import is_branch_active + class Command(BaseCommand): help = 'Export a JSON file with information about all component branches' def handle(self, *args, **options): all_entries = ComponentBranch.objects.all() - exported = [e.export() for e in all_entries] - for i, entry in enumerate(all_entries): - exported[i]['active'] = is_branch_active(entry) - self.stdout.write(json.dumps(exported, indent=2)) + output = collections.defaultdict(lambda: collections.defaultdict(list)) + for entry in all_entries: + if not is_branch_active(entry): + continue + output[entry.type.name][entry.global_component.name].append(entry.name) + self.stdout.write(json.dumps(output))