2017-12-12 19:35:41 +00:00
|
|
|
""" Export component branches.
|
|
|
|
|
|
|
|
This is used to drive the pagure-sync-bugzilla script.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import collections
|
2017-11-17 13:52:23 +00:00
|
|
|
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
|
|
|
|
|
2017-12-12 19:35:41 +00:00
|
|
|
|
2017-11-17 13:52:23 +00:00
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Export a JSON file with information about all component branches'
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
all_entries = ComponentBranch.objects.all()
|
2017-12-12 19:35:41 +00:00
|
|
|
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))
|