<s> from __future__ import print_function <EOL> import traceback <EOL> from bloom . generators import BloomGenerator <EOL> from bloom . git import inbranch <EOL> from bloom . git import get_current_branch <EOL> from bloom . logging import debug <EOL> from bloom . logging import error <EOL> from bloom . logging import fmt <EOL> from bloom . logging import info <EOL> from bloom . logging import warning <EOL> from bloom . packages import get_package_data <EOL> from bloom . util import execute_command <EOL> from bloom . commands . git . patch . trim_cmd import trim <EOL> try : <EOL> import catkin_pkg <EOL> from pkg_resources import parse_version <EOL> if parse_version ( catkin_pkg . __version__ ) < parse_version ( '<STR_LIT>' ) : <EOL> warning ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( catkin_pkg . __version__ ) ) <EOL> from catkin_pkg import metapackage <EOL> except ImportError as err : <EOL> debug ( traceback . format_exc ( ) ) <EOL> error ( "<STR_LIT>" , exit = True ) <EOL> class ReleaseGenerator ( BloomGenerator ) : <EOL> title = '<STR_LIT>' <EOL> description = """<STR_LIT>""" <EOL> def prepare_arguments ( self , parser ) : <EOL> add = parser . add_argument <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , default = None , dest = '<STR_LIT:src>' , <EOL> help = "<STR_LIT>" ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , default = None , dest = '<STR_LIT:name>' , <EOL> help = "<STR_LIT>" ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , default = <NUM_LIT:0> , <EOL> help = "<STR_LIT>" ) <EOL> return BloomGenerator . prepare_arguments ( self , parser ) <EOL> def handle_arguments ( self , args ) : <EOL> self . interactive = args . interactive <EOL> self . prefix = args . prefix <EOL> if args . src is None : <EOL> current_branch = get_current_branch ( ) <EOL> if current_branch is None : <EOL> error ( "<STR_LIT>" , exit = True ) <EOL> self . src = current_branch <EOL> else : <EOL> self . src = args . src <EOL> self . name = args . name <EOL> self . release_inc = args . release_increment <EOL> def summarize ( self ) : <EOL> self . branch_list = self . detect_branches ( ) <EOL> if type ( self . branch_list ) not in [ list , tuple ] : <EOL> self . exit ( self . branch_list if self . branch_list is not None else <NUM_LIT:1> ) <EOL> info ( "<STR_LIT>" + <EOL> ( '<STR_LIT>' if len ( self . branch_list ) == <NUM_LIT:1> else '<STR_LIT:s>' ) + "<STR_LIT>" + str ( self . branch_list ) ) <EOL> def get_branching_arguments ( self ) : <EOL> p , s , i = self . prefix , self . src , self . interactive <EOL> self . branch_args = [ [ '<STR_LIT:/>' . join ( [ p , b ] ) , s , i ] for b in self . branch_list ] <EOL> return self . branch_args <EOL> def pre_rebase ( self , destination , msg = None ) : <EOL> name = destination . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> msg = msg if msg is not None else ( <EOL> "<STR_LIT>" + name + "<STR_LIT>" + destination + "<STR_LIT:'>" <EOL> ) <EOL> info ( msg ) <EOL> ret = trim ( undo = True ) <EOL> return <NUM_LIT:0> if ret is None or ret < <NUM_LIT:0> else ret <EOL> def post_rebase ( self , destination ) : <EOL> name = destination . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> trim_d = [ k for k , v in self . packages . items ( ) if v . name == name ] [ <NUM_LIT:0> ] <EOL> if trim_d in [ '<STR_LIT>' , '<STR_LIT:.>' ] : <EOL> return <EOL> return trim ( trim_d ) <EOL> def post_patch ( self , destination ) : <EOL> if self . name is not None : <EOL> warning ( """<STR_LIT>""" ) <EOL> warning ( """<STR_LIT>""" ) <EOL> warning ( "<STR_LIT>" + str ( self . name ) ) <EOL> warning ( "<STR_LIT>" + str ( self . name ) + "<STR_LIT>" ) <EOL> return <EOL> with inbranch ( destination ) : <EOL> name , version , packages = get_package_data ( destination ) <EOL> release_tag = destination + '<STR_LIT:/>' + version + '<STR_LIT:->' + self . release_inc <EOL> execute_command ( '<STR_LIT>' + release_tag ) <EOL> def metapackage_check ( self , path , pkg ) : <EOL> if pkg . is_metapackage ( ) : <EOL> try : <EOL> metapackage . validate_metapackage ( path , pkg ) <EOL> except metapackage . InvalidMetapackage as e : <EOL> warning ( "<STR_LIT>" ) <EOL> warning ( "<STR_LIT>" % str ( e ) ) <EOL> error ( fmt ( "<STR_LIT>" % <EOL> ( pkg . name , metapackage . DEFINITION_URL ) ) , exit = True ) <EOL> def detect_branches ( self ) : <EOL> self . packages = None <EOL> with inbranch ( self . src ) : <EOL> if self . name is not None : <EOL> self . packages = [ self . name ] <EOL> return [ self . name ] <EOL> name , version , packages = get_package_data ( self . src ) <EOL> self . packages = packages <EOL> if isinstance ( self . packages , dict ) : <EOL> for path , pkg in self . packages . items ( ) : <EOL> self . metapackage_check ( path , pkg ) <EOL> return name if type ( name ) is list else [ name ] </s>
