<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import collections <EOL> import phlgitu_ref <EOL> WB_STATUS_OK = "<STR_LIT>" <EOL> WB_STATUS_PREFIX_BAD = "<STR_LIT>" <EOL> WB_STATUS_BAD_NAME = WB_STATUS_PREFIX_BAD + "<STR_LIT:name>" <EOL> WB_STATUS_BAD_PREREVIEW = WB_STATUS_PREFIX_BAD + "<STR_LIT>" <EOL> WB_STATUS_BAD_INREVIEW = WB_STATUS_PREFIX_BAD + "<STR_LIT>" <EOL> WB_STATUS_BAD_LAND = WB_STATUS_PREFIX_BAD + "<STR_LIT>" <EOL> WB_STATUS_BAD_ABANDONED = WB_STATUS_PREFIX_BAD + "<STR_LIT>" <EOL> WB_DICT_STATUS_DESC = { <EOL> WB_STATUS_OK : "<STR_LIT>" , <EOL> WB_STATUS_BAD_NAME : "<STR_LIT>" , <EOL> WB_STATUS_BAD_PREREVIEW : "<STR_LIT>" , <EOL> WB_STATUS_BAD_INREVIEW : "<STR_LIT>" , <EOL> WB_STATUS_BAD_LAND : "<STR_LIT>" , <EOL> WB_STATUS_BAD_ABANDONED : "<STR_LIT>" , <EOL> } <EOL> EXAMPLE_REVIEW_BRANCH_BASE = "<STR_LIT>" <EOL> EXAMPLE_REVIEW_BRANCH_DESCRIPTION = "<STR_LIT>" <EOL> ARCYD_BRANCH_NAMESPACE = '<STR_LIT>' <EOL> TRACKING_BRANCH_PREFIX = ARCYD_BRANCH_NAMESPACE + '<STR_LIT>' <EOL> RESERVED_BRANCH_NAME = ARCYD_BRANCH_NAMESPACE + '<STR_LIT>' <EOL> class Error ( Exception ) : <EOL> pass <EOL> def isStatusBad ( working_branch ) : <EOL> """<STR_LIT>""" <EOL> return working_branch . status . startswith ( WB_STATUS_PREFIX_BAD ) <EOL> def isStatusBadPreReview ( working_branch ) : <EOL> """<STR_LIT>""" <EOL> return working_branch . status == WB_STATUS_BAD_PREREVIEW <EOL> def isStatusBadLand ( working_branch ) : <EOL> """<STR_LIT>""" <EOL> return working_branch . status == WB_STATUS_BAD_LAND <EOL> class TrackerBranch ( object ) : <EOL> def __init__ ( <EOL> self , <EOL> naming , <EOL> branch , <EOL> review_branch , <EOL> status , <EOL> description , <EOL> base , <EOL> rev_id , <EOL> remote ) : <EOL> super ( TrackerBranch , self ) . __init__ ( ) <EOL> self . _naming = naming <EOL> self . _branch = branch <EOL> self . _status = status <EOL> self . _description = description <EOL> self . _base = base <EOL> self . _id = rev_id <EOL> self . _remote = remote <EOL> self . _remote_base = None <EOL> self . _remote_branch = None <EOL> self . _review_name = review_branch <EOL> self . _update_remotes ( ) <EOL> @ property <EOL> def branch ( self ) : <EOL> return self . _branch <EOL> @ property <EOL> def status ( self ) : <EOL> return self . _status <EOL> @ property <EOL> def description ( self ) : <EOL> return self . _description <EOL> @ property <EOL> def base ( self ) : <EOL> return self . _base <EOL> @ property <EOL> def id ( self ) : <EOL> return self . _id <EOL> @ property <EOL> def remote ( self ) : <EOL> return self . _remote <EOL> @ property <EOL> def remote_base ( self ) : <EOL> return self . _remote_base <EOL> @ property <EOL> def remote_branch ( self ) : <EOL> return self . _remote_branch <EOL> @ property <EOL> def review_name ( self ) : <EOL> return self . _review_name <EOL> def update_status ( self , status ) : <EOL> self . _status = status <EOL> self . _branch = self . _naming . make_tracker_branch_name ( <EOL> self . _status , self . _description , self . _base , self . _id ) <EOL> self . _update_remotes ( ) <EOL> def _update_remotes ( self ) : <EOL> self . _remote_base = phlgitu_ref . make_remote ( <EOL> self . _base , self . _remote ) <EOL> self . _remote_branch = phlgitu_ref . make_remote ( <EOL> self . _branch , self . _remote ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . branch ) <EOL> __repr__ = __str__ <EOL> class ReviewBranch ( object ) : <EOL> def __init__ ( <EOL> self , <EOL> naming , <EOL> branch , <EOL> description , <EOL> base , <EOL> remote ) : <EOL> super ( ReviewBranch , self ) . __init__ ( ) <EOL> self . _naming = naming <EOL> self . _branch = branch <EOL> self . _description = description <EOL> self . _base = base <EOL> self . _remote = remote <EOL> self . _remote_base = None <EOL> self . _remote_branch = None <EOL> self . _update_remotes ( ) <EOL> @ property <EOL> def branch ( self ) : <EOL> return self . _branch <EOL> @ property <EOL> def description ( self ) : <EOL> return self . _description <EOL> @ property <EOL> def base ( self ) : <EOL> return self . _base <EOL> @ property <EOL> def remote ( self ) : <EOL> return self . _remote <EOL> @ property <EOL> def remote_base ( self ) : <EOL> return self . _remote_base <EOL> @ property <EOL> def remote_branch ( self ) : <EOL> return self . _remote_branch <EOL> def make_tracker ( self , status , rev_id ) : <EOL> """<STR_LIT>""" <EOL> if rev_id is None : <EOL> rev_id = "<STR_LIT:none>" <EOL> else : <EOL> rev_id = str ( rev_id ) <EOL> tracking_branch_name = self . _naming . make_tracker_branch_name ( <EOL> status , self . description , self . base , rev_id ) <EOL> tracking_branch = self . _naming . make_tracker_branch_from_name ( <EOL> tracking_branch_name ) <EOL> return tracking_branch <EOL> def _update_remotes ( self ) : <EOL> self . _remote_base = phlgitu_ref . make_remote ( <EOL> self . _base , self . _remote ) <EOL> self . _remote_branch = phlgitu_ref . make_remote ( <EOL> self . _branch , self . _remote ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . branch ) <EOL> __repr__ = __str__ <EOL> BranchPair = collections . namedtuple ( <EOL> "<STR_LIT>" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> def _get_branches ( branch_list , func ) : <EOL> """<STR_LIT>""" <EOL> converted_branch_list = [ ] <EOL> for branch in branch_list : <EOL> try : <EOL> converted_branch_list . append ( <EOL> func ( branch ) ) <EOL> except Error : <EOL> pass <EOL> return converted_branch_list <EOL> def get_branch_pairs ( branch_list , naming ) : <EOL> """<STR_LIT>""" <EOL> tracker_branches = _get_branches ( <EOL> branch_list , naming . make_tracker_branch_from_name ) <EOL> review_branches = _get_branches ( <EOL> branch_list , naming . make_review_branch_from_name ) <EOL> name_to_tracked = dict ( [ ( b . review_name , b ) for b in tracker_branches ] ) <EOL> name_to_review = dict ( [ ( b . branch , b ) for b in review_branches ] ) <EOL> tracked = set ( name_to_tracked . keys ( ) ) <EOL> actual = set ( name_to_review . keys ( ) ) <EOL> abandoned_trackers = [ name_to_tracked [ b ] for b in tracked - actual ] <EOL> new_reviews = [ name_to_review [ b ] for b in actual - tracked ] <EOL> matched = actual & tracked <EOL> res = [ BranchPair ( name_to_review [ b ] , name_to_tracked [ b ] ) for b in matched ] <EOL> res += [ BranchPair ( None , b ) for b in abandoned_trackers ] <EOL> res += [ BranchPair ( b , None ) for b in new_reviews ] <EOL> return res </s>
