<s> import csv <EOL> from optparse import make_option <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . utils . translation import ugettext_lazy <EOL> from onadata . apps . logger . models . xform import XForm , DuplicateUUIDError <EOL> from onadata . libs . utils . model_tools import update_xform_uuid <EOL> class Command ( BaseCommand ) : <EOL> help = ugettext_lazy ( <EOL> "<STR_LIT>" <EOL> ) <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = ugettext_lazy ( "<STR_LIT>" ) ) , ) <EOL> def handle ( self , * args , ** kwargs ) : <EOL> if not kwargs . get ( '<STR_LIT:file>' ) : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> try : <EOL> with open ( kwargs . get ( '<STR_LIT:file>' ) , "<STR_LIT:r>" ) as f : <EOL> lines = csv . reader ( f ) <EOL> i = <NUM_LIT:0> <EOL> for line in lines : <EOL> try : <EOL> username = line [ <NUM_LIT:0> ] <EOL> id_string = line [ <NUM_LIT:1> ] <EOL> uuid = line [ <NUM_LIT:2> ] <EOL> update_xform_uuid ( username , id_string , uuid ) <EOL> except IndexError : <EOL> print "<STR_LIT>" % ( i + <NUM_LIT:1> ) <EOL> except XForm . DoesNotExist : <EOL> print "<STR_LIT>" "<STR_LIT>" % ( username , id_string , uuid ) <EOL> except DuplicateUUIDError : <EOL> print "<STR_LIT>" % uuid <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> print "<STR_LIT>" % i <EOL> except IOError : <EOL> raise CommandError ( <EOL> "<STR_LIT>" % kwargs . get ( '<STR_LIT:file>' ) ) </s>
