Adjust format of PDC branch cache script.

This commit is contained in:
Ralph Bean 2017-12-12 19:35:41 +00:00
parent b1c34e40a6
commit e9d85a10b7

View file

@ -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))