Coverage for distro_tracker/vendor/debian/management/commands/tracker_import_old_subscriber_dump.py: 94%
21 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
1# Copyright 2013 The Distro Tracker Developers
2# See the COPYRIGHT file at the top-level directory of this distribution and
3# at https://deb.li/DTAuthors
4#
5# This file is part of Distro Tracker. It is subject to the license terms
6# in the LICENSE file found in the top-level directory of this
7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
8# including this file, may be copied, modified, propagated, or distributed
9# except according to the terms contained in the LICENSE file.
10"""Command to import subscribers from an old PTS dump."""
11import sys
13from django.core.management.base import BaseCommand
14from django.db import transaction
16from distro_tracker.core.models import Subscription
19class Command(BaseCommand):
20 """
21 Import the old PTS package subscriptions.
22 The expected input is the output of the ``bin/dump.pl`` file on stdin.
23 """
24 stdin = sys.stdin
26 def write(self, message):
27 if self.verbose: 27 ↛ 28line 27 didn't jump to line 28, because the condition on line 27 was never true
28 self.stdout.write(message)
30 @transaction.atomic
31 def handle(self, *args, **kwargs):
32 self.verbose = int(kwargs.get('verbosity', 1)) > 1
34 # Each packages subscriptions are output in a separate line each in the
35 # following format:
36 # <package-name> => [ <email1> <email2> ... ]
37 for line in self.stdin:
38 package_name, emails = line.split('=>', 1)
39 package_name = package_name.strip()
40 emails = emails.strip().strip('[]').strip().split()
41 emails = [email.strip() for email in emails]
42 # For each email create a subscription to the package
43 self.write(
44 "Importing subscriptions for package {}".format(package_name))
45 for email in emails:
46 Subscription.objects.create_for(package_name, email)