<s> from django . core . management . base import BaseCommand , CommandError <EOL> from channels . models import Channel , Subscription <EOL> from links . models import Link <EOL> import sys <EOL> class Command ( BaseCommand ) : <EOL> args = '<STR_LIT>' <EOL> help = '<STR_LIT>' <EOL> def handle ( self , * args , ** options ) : <EOL> if not len ( args ) == <NUM_LIT:2> : <EOL> raise CommandError ( '<STR_LIT>' ) <EOL> source_channel_slug , dest_channel_slug = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] <EOL> try : <EOL> source_channel = Channel . objects . get ( slug = source_channel_slug ) <EOL> except Channel . DoesNotExist : <EOL> raise CommandError ( '<STR_LIT>' % source_channel_slug ) <EOL> try : <EOL> dest_channel = Channel . objects . get ( slug = dest_channel_slug ) <EOL> except Channel . DoesNotExist : <EOL> raise CommandError ( '<STR_LIT>' % dest_channel_slug ) <EOL> confirmed = raw_input ( "<STR_LIT>" % ( source_channel , dest_channel ) ) <EOL> if not confirmed == "<STR_LIT:y>" : <EOL> sys . exit ( ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> for link in Link . objects . filter ( channel = source_channel ) : <EOL> link . channel = dest_channel <EOL> link . save ( ) <EOL> self . stdout . write ( "<STR_LIT>" % link ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> for subscription in Subscription . objects . filter ( channel = source_channel ) : <EOL> subscribed = Subscription . objects . filter ( user = subscription . user , channel = subscription . channel ) . count ( ) <EOL> if subscribed : <EOL> subscription . delete ( ) <EOL> else : <EOL> subscription . channel = dest_channel <EOL> subscription . save ( ) <EOL> self . stdout . write ( "<STR_LIT>" % subscription . user ) <EOL> source_channel . delete ( ) </s>
