<s> """<STR_LIT>""" <EOL> import utils <EOL> class RenameBranchAction ( object ) : <EOL> """<STR_LIT>""" <EOL> CHECK_BRANCHES = <NUM_LIT:0> <EOL> RENAME = <NUM_LIT:1> <EOL> FINISHED = <NUM_LIT:2> <EOL> def __init__ ( self , source_branch , target_branch ) : <EOL> """<STR_LIT>""" <EOL> self . __source_branch = source_branch <EOL> self . __target_branch = target_branch <EOL> self . state = self . CHECK_BRANCHES <EOL> self . advance ( ) <EOL> @ classmethod <EOL> def callback ( cls , args , unused_argv ) : <EOL> """<STR_LIT>""" <EOL> return cls ( * args . branches ) <EOL> def check_branches ( self ) : <EOL> """<STR_LIT>""" <EOL> rietveld_info = None <EOL> if utils . branch_exists ( self . __target_branch ) : <EOL> print '<STR_LIT>' % ( self . __target_branch , ) <EOL> self . state = self . FINISHED <EOL> elif not utils . branch_exists ( self . __source_branch ) : <EOL> print '<STR_LIT>' % ( self . __source_branch , ) <EOL> self . state = self . FINISHED <EOL> elif self . __source_branch == utils . get_current_branch ( ) : <EOL> print '<STR_LIT>' <EOL> self . state = self . FINISHED <EOL> else : <EOL> rietveld_info = utils . RietveldInfo . from_branch ( <EOL> branch_name = self . __source_branch ) <EOL> if rietveld_info is None : <EOL> print ( '<STR_LIT>' % <EOL> ( self . __source_branch , ) ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( self . __source_branch , <EOL> self . __target_branch ) <EOL> self . state = self . FINISHED <EOL> else : <EOL> self . state = self . RENAME <EOL> self . advance ( rietveld_info ) <EOL> def rename ( self , rietveld_info ) : <EOL> """<STR_LIT>""" <EOL> if rietveld_info is None : <EOL> raise utils . GitRvException ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> print utils . capture_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . __source_branch , <EOL> self . __target_branch , single_line = False ) <EOL> print '<STR_LIT>' <EOL> rietveld_info . _branch_name = self . __target_branch <EOL> rietveld_info . save ( ) <EOL> utils . RietveldInfo . remove ( branch_name = self . __source_branch ) <EOL> def advance ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . state == self . CHECK_BRANCHES : <EOL> self . check_branches ( * args , ** kwargs ) <EOL> elif self . state == self . RENAME : <EOL> self . rename ( * args , ** kwargs ) <EOL> elif self . state == self . FINISHED : <EOL> return <EOL> else : <EOL> raise utils . GitRvException ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . state , ) ) </s>
