<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from optparse import make_option <EOL> import logging <EOL> import sys <EOL> from django . core . management . base import BaseCommand <EOL> from zerver . lib import utils <EOL> from zerver . models import UserMessage , get_user_profile_by_email <EOL> from django . db import models <EOL> class Command ( BaseCommand ) : <EOL> help = """<STR_LIT>""" <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> help = "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> help = "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> help = "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT:email>' , <EOL> type = '<STR_LIT:string>' , <EOL> help = "<STR_LIT>" ) , <EOL> ) <EOL> def handle ( self , * args , ** options ) : <EOL> if not options [ "<STR_LIT>" ] or not options [ "<STR_LIT>" ] or not options [ "<STR_LIT:email>" ] : <EOL> print ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> op = options [ '<STR_LIT>' ] <EOL> flag = getattr ( UserMessage . flags , options [ '<STR_LIT>' ] ) <EOL> all_until = options [ '<STR_LIT>' ] <EOL> email = options [ '<STR_LIT:email>' ] <EOL> user_profile = get_user_profile_by_email ( email ) <EOL> if all_until : <EOL> filt = models . Q ( id__lte = all_until ) <EOL> else : <EOL> filt = models . Q ( message__id__in = [ mid . strip ( ) for mid in sys . stdin . read ( ) . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> mids = [ m . id for m in <EOL> UserMessage . objects . filter ( filt , user_profile = user_profile ) . order_by ( '<STR_LIT>' ) ] <EOL> if options [ "<STR_LIT>" ] : <EOL> sys . stdin . close ( ) <EOL> sys . stdout . close ( ) <EOL> sys . stderr . close ( ) <EOL> def do_update ( batch ) : <EOL> msgs = UserMessage . objects . filter ( id__in = batch ) <EOL> if op == '<STR_LIT>' : <EOL> msgs . update ( flags = models . F ( '<STR_LIT>' ) . bitor ( flag ) ) <EOL> elif op == '<STR_LIT>' : <EOL> msgs . update ( flags = models . F ( '<STR_LIT>' ) . bitand ( ~ flag ) ) <EOL> if not options [ "<STR_LIT>" ] : <EOL> logging . info ( "<STR_LIT>" % ( mids , op , flag ) ) <EOL> logging . info ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> utils . run_in_batches ( mids , <NUM_LIT> , do_update , sleep_time = <NUM_LIT:3> ) <EOL> exit ( <NUM_LIT:0> ) </s>
