<s> """<STR_LIT>""" <EOL> from django . core . management . base import BaseCommand <EOL> from django . contrib . auth . models import User <EOL> from optparse import make_option <EOL> from dmscouch . models import CouchDocument <EOL> import core <EOL> class Command ( BaseCommand ) : <EOL> def __init__ ( self ) : <EOL> BaseCommand . __init__ ( self ) <EOL> self . option_list += ( <EOL> make_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = """<STR_LIT>""" <EOL> def handle ( self , * args , ** options ) : <EOL> quiet = options . get ( '<STR_LIT>' , False ) <EOL> codes = self . get_codes ( ) <EOL> if not quiet : <EOL> if codes : <EOL> self . stdout . write ( '<STR_LIT>' % codes ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> revisions = self . get_revisions ( ) <EOL> if not quiet : <EOL> if codes : <EOL> self . stdout . write ( "<STR_LIT>" <EOL> % [ d [ <NUM_LIT:0> ] for d in revisions ] ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> if codes or revisions : <EOL> processor = core . document_processor . DocumentProcessor ( ) <EOL> user = User . objects . filter ( is_superuser = True ) [ <NUM_LIT:0> ] <EOL> for code in codes : <EOL> processor . delete ( code , { '<STR_LIT:user>' : user } ) <EOL> if not processor . errors : <EOL> if not quiet : <EOL> self . stdout . write ( '<STR_LIT>' % code ) <EOL> else : <EOL> if not quiet : <EOL> self . stdout . write ( processor . errors ) <EOL> raise ( Exception , processor . errors ) <EOL> for rev in revisions : <EOL> processor . delete ( rev [ <NUM_LIT:0> ] , { '<STR_LIT:user>' : user , '<STR_LIT>' : rev [ <NUM_LIT:1> ] } ) <EOL> def get_codes ( self ) : <EOL> deleted_codes = CouchDocument . view ( '<STR_LIT>' ) <EOL> codes = [ doc . get_id for doc in deleted_codes ] <EOL> return codes <EOL> def get_revisions ( self ) : <EOL> """<STR_LIT>""" <EOL> deleted_revisions = CouchDocument . view ( '<STR_LIT>' ) <EOL> results = [ ( doc . get_id , doc [ '<STR_LIT>' ] ) for doc in deleted_revisions ] <EOL> return results </s>
