<s> from optparse import make_option <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . db . models import Q <EOL> from celery import chord , group <EOL> from olympia import amo <EOL> from olympia . addons . models import Addon <EOL> from olympia . amo . utils import chunked <EOL> from olympia . devhub . tasks import ( <EOL> convert_purified , flag_binary , get_preview_sizes ) <EOL> from olympia . lib . crypto . tasks import sign_addons , unsign_addons <EOL> from olympia . reviews . tasks import addon_review_aggregates <EOL> tasks = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : flag_binary , <EOL> '<STR_LIT>' : [ Q ( type__in = [ amo . ADDON_EXTENSION , <EOL> amo . ADDON_DICT , <EOL> amo . ADDON_LPADDON , <EOL> amo . ADDON_PLUGIN , <EOL> amo . ADDON_API ] ) , <EOL> Q ( disabled_by_user = False ) ] , <EOL> '<STR_LIT>' : dict ( latest = False ) } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : flag_binary , '<STR_LIT>' : [ ] } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : get_preview_sizes , '<STR_LIT>' : [ ] } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : convert_purified , '<STR_LIT>' : [ ] } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : addon_review_aggregates , '<STR_LIT>' : [ ] } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : sign_addons , '<STR_LIT>' : [ ] } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : unsign_addons , '<STR_LIT>' : [ ] } , <EOL> } <EOL> class Command ( BaseCommand ) : <EOL> """<STR_LIT>""" <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , type = '<STR_LIT:string>' , <EOL> dest = '<STR_LIT>' , help = '<STR_LIT>' ) , <EOL> ) <EOL> def handle ( self , * args , ** options ) : <EOL> task = tasks . get ( options . get ( '<STR_LIT>' ) ) <EOL> if not task : <EOL> raise CommandError ( '<STR_LIT>' <EOL> % '<STR_LIT:U+002CU+0020>' . join ( tasks . keys ( ) ) ) <EOL> pks = ( Addon . objects . filter ( * task [ '<STR_LIT>' ] ) <EOL> . values_list ( '<STR_LIT>' , flat = True ) <EOL> . order_by ( '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in task : <EOL> pks = task [ '<STR_LIT>' ] ( pks ) <EOL> if pks : <EOL> kw = task . get ( '<STR_LIT>' , { } ) <EOL> grouping = [ ] <EOL> for chunk in chunked ( pks , <NUM_LIT:100> ) : <EOL> grouping . append ( <EOL> task [ '<STR_LIT>' ] . subtask ( args = [ chunk ] , kwargs = kw ) ) <EOL> post = None <EOL> if '<STR_LIT>' in task : <EOL> post = task [ '<STR_LIT>' ] . subtask ( args = [ ] , kwargs = kw , immutable = True ) <EOL> ts = chord ( grouping , post ) <EOL> else : <EOL> ts = group ( grouping ) <EOL> ts . apply_async ( ) </s>
