fix logging statements
[mygpo.git] / mygpo / maintenance / management / commands / merge-duplicates.py
blob02f312e5cb283e30b7aad3c3304d95f9eac7a874
1 import sys
2 from optparse import make_option
4 from django.core.management.base import BaseCommand
6 from mygpo.maintenance import merge
8 class Command(BaseCommand):
10 option_list = BaseCommand.option_list + (
11 make_option('--dry-run', action='store_true', dest='dry_run', default=False, help="Perform a dry-run without actually changing anything"),
12 make_option('--podcasts', action='store_true', dest='podcasts', default=False, help="Perform merging for Podcasts "),
13 make_option('--podcast-states', action='store_true', dest='podcast_states', default=False, help="Perform merging for Podcast states"),
14 make_option('--episodes', action='store_true', dest='episodes', default=False, help="Perform merging for Episodes"),
15 make_option('--episode_states', action='store_true', dest='episode_states', default=False, help="Perform merging for Episode states"),
16 make_option('--all', action='store_true', dest='all', default=False, help="Perform all merges"),
19 def handle(self, *args, **options):
21 dry_run = options.get('dry_run') or options.get('all')
22 podcasts = options.get('podcasts') or options.get('all')
23 podcast_states = options.get('podcast_states') or options.get('all')
24 episodes = options.get('episodes') or options.get('all')
25 episode_states = options.get('episode_states') or options.get('all')
27 if not any([podcasts, podcast_states, episodes, episode_states]):
28 print >> sys.stderr, 'Usage: ./manage.py merge-duplicates [--dry-run] ( --podcasts | --podcast-states | --episodes | --episode-states )+'
29 return
31 merge.merge_objects(podcasts=podcasts, podcast_states=podcast_states,
32 episodes=episodes, episode_states=episode_states, dry_run=dry_run)