diff --git a/odyseescraper/management/commands/odyseetag.py b/odyseescraper/management/commands/odyseetag.py index b1f33c0..759de1d 100644 --- a/odyseescraper/management/commands/odyseetag.py +++ b/odyseescraper/management/commands/odyseetag.py @@ -7,8 +7,14 @@ from django.db import models class Command(BaseCommand): help = "Runs tagging rules against every release in the database" + def add_arguments(self, parser): + parser.add_argument("--dry-run", action="store_true", help="Preview changes instead of actually committing them") + def handle(self, *args, **options): - self.stdout.write('Tagging releases...') + if options['dry_run']: + self.stdout.write('Dry-running tagging rules...') + else: + self.stdout.write('Tagging releases...') updates = 0 ignores = 0 failures = [] @@ -25,11 +31,14 @@ class Command(BaseCommand): continue if taggingrule.required_tag and not taggingrule.required_tag in release.tags.all(): continue + if taggingrule.channel_regex and not re.match(taggingrule.channel_regex, release.channel.handle): + continue if taggingrule.tag in release.tags.all(): ignores += 1 continue self.stdout.write(f'Release "{str(release)}" matched rule "{str(taggingrule)}" for tag "{str(taggingrule.tag)}"') - release.tags.add(taggingrule.tag) + if not options['dry_run']: + release.tags.add(taggingrule.tag) updates += 1 except Exception as e: self.stdout.write(self.style.WARNING(f'Failed to apply rule {str(taggingrule.name)}: {e}'))