<s> from __future__ import print_function <EOL> import argparse <EOL> import atexit <EOL> import os <EOL> import shutil <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import traceback <EOL> from bloom . config import DEFAULT_TEMPLATE <EOL> from bloom . config import get_tracks_dict_raw <EOL> from bloom . config import template_str <EOL> from bloom . config import verify_track <EOL> from bloom . config import write_tracks_dict_raw <EOL> from bloom . git import ensure_clean_working_env <EOL> from bloom . git import ensure_git_root <EOL> from bloom . git import get_current_branch <EOL> from bloom . git import get_root <EOL> from bloom . git import GitClone <EOL> from bloom . logging import debug <EOL> from bloom . logging import error <EOL> from bloom . logging import fmt <EOL> from bloom . logging import get_error_prefix <EOL> from bloom . logging import info <EOL> from bloom . logging import sanitize <EOL> from bloom . logging import warning <EOL> from bloom . packages import get_package_data <EOL> import bloom . util <EOL> from bloom . util import add_global_arguments <EOL> from bloom . util import change_directory <EOL> from bloom . util import code <EOL> from bloom . util import disable_git_clone <EOL> from bloom . util import handle_global_arguments <EOL> from bloom . util import maybe_continue <EOL> from bloom . util import quiet_git_clone_warning <EOL> from bloom . util import safe_input <EOL> try : <EOL> from vcstools . vcs_abstraction import get_vcs_client <EOL> except ImportError : <EOL> debug ( traceback . format_exc ( ) ) <EOL> error ( "<STR_LIT>" , file = sys . stderr , <EOL> exit = True ) <EOL> upstream_repos = { } <EOL> _error = get_error_prefix ( ) <EOL> def get_upstream_repo ( uri , vcs_type ) : <EOL> global upstream_repos <EOL> if uri not in upstream_repos : <EOL> temp_dir = tempfile . mkdtemp ( ) <EOL> upstream_dir = os . path . join ( temp_dir , '<STR_LIT>' ) <EOL> upstream_repos [ uri ] = ( temp_dir , get_vcs_client ( vcs_type , upstream_dir ) ) <EOL> return upstream_repos [ uri ] [ <NUM_LIT:1> ] <EOL> @ atexit . register <EOL> def clean_up_repositories ( ) : <EOL> global upstream_repos <EOL> for uri in upstream_repos : <EOL> path = upstream_repos [ uri ] [ <NUM_LIT:0> ] <EOL> if os . path . exists ( path ) : <EOL> shutil . rmtree ( path ) <EOL> def get_upstream_meta ( upstream_dir , ros_distro ) : <EOL> meta = None <EOL> directory = os . getcwd ( ) <EOL> with change_directory ( upstream_dir ) : <EOL> if get_root ( ) is not None : <EOL> current_branch = get_current_branch ( ) <EOL> else : <EOL> current_branch = None <EOL> name , version , packages = get_package_data ( current_branch , quiet = False , release_directory = directory ) <EOL> meta = { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:version>' : version , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> return meta <EOL> def find_version_from_upstream ( vcs_uri , vcs_type , devel_branch = None , ros_distro = '<STR_LIT>' ) : <EOL> info ( "<STR_LIT>" ) <EOL> upstream_repo = get_upstream_repo ( vcs_uri , vcs_type ) <EOL> if not upstream_repo . checkout ( vcs_uri , devel_branch or '<STR_LIT>' ) : <EOL> error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( devel_branch or '<STR_LIT>' , vcs_uri ) , exit = True ) <EOL> meta = get_upstream_meta ( upstream_repo . get_path ( ) , ros_distro ) <EOL> if not meta : <EOL> error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( devel_branch or '<STR_LIT>' , vcs_uri ) ) <EOL> info ( "<STR_LIT>" <EOL> . format ( meta [ '<STR_LIT:version>' ] , meta [ '<STR_LIT:name>' ] ) ) <EOL> return meta [ '<STR_LIT:version>' ] , upstream_repo <EOL> def process_track_settings ( track_dict , release_inc_override ) : <EOL> settings = { } <EOL> settings [ '<STR_LIT:name>' ] = track_dict [ '<STR_LIT:name>' ] <EOL> vcs_uri = track_dict [ '<STR_LIT>' ] <EOL> if vcs_uri is None or vcs_uri . lower ( ) == '<STR_LIT>' : <EOL> error ( "<STR_LIT>" <EOL> . format ( DEFAULT_TEMPLATE [ '<STR_LIT>' ] . name ) , <EOL> exit = True ) <EOL> vcs_type = track_dict [ '<STR_LIT>' ] <EOL> vcs_type_prompt = DEFAULT_TEMPLATE [ '<STR_LIT>' ] <EOL> if vcs_type is None or vcs_type . lower ( ) not in vcs_type_prompt . values : <EOL> error ( "<STR_LIT>" <EOL> . format ( vcs_type_prompt . name , vcs_type , vcs_type_prompt . values ) , <EOL> exit = True ) <EOL> settings [ '<STR_LIT>' ] = vcs_type <EOL> version = track_dict [ '<STR_LIT:version>' ] <EOL> track_dict [ '<STR_LIT>' ] = str ( track_dict [ '<STR_LIT>' ] . lower ( ) ) <EOL> repo = None <EOL> if version . lower ( ) == '<STR_LIT>' : <EOL> if vcs_type not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> error ( "<STR_LIT>" <EOL> . format ( vcs_type ) , exit = True ) <EOL> devel_branch = track_dict [ '<STR_LIT>' ] <EOL> try : <EOL> string_types = [ str , unicode ] <EOL> except NameError : <EOL> string_types = [ str ] <EOL> if type ( devel_branch ) in string_types and devel_branch . lower ( ) == '<STR_LIT>' : <EOL> devel_branch = None <EOL> version , repo = find_version_from_upstream ( vcs_uri , <EOL> vcs_type , <EOL> devel_branch , <EOL> track_dict [ '<STR_LIT>' ] ) <EOL> if version is None : <EOL> warning ( "<STR_LIT>" ) <EOL> if version is None or version == '<STR_LIT>' : <EOL> ret = safe_input ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if not ret : <EOL> error ( "<STR_LIT>" , exit = True ) <EOL> version = ret <EOL> settings [ '<STR_LIT:version>' ] = version <EOL> vcs_uri = vcs_uri . replace ( '<STR_LIT>' , version ) <EOL> settings [ '<STR_LIT>' ] = repo . get_path ( ) if repo else vcs_uri <EOL> if '<STR_LIT>' in vcs_uri : <EOL> vcs_uri = vcs_uri . replace ( '<STR_LIT>' , version ) <EOL> settings [ '<STR_LIT>' ] = vcs_uri <EOL> release_tag = track_dict [ '<STR_LIT>' ] <EOL> release_tag_prompt = DEFAULT_TEMPLATE [ '<STR_LIT>' ] <EOL> if release_tag is not None and release_tag == '<STR_LIT>' : <EOL> ret = safe_input ( '<STR_LIT>' ) <EOL> if not ret : <EOL> error ( "<STR_LIT>" , exit = True ) <EOL> release_tag = ret <EOL> elif release_tag is None or release_tag . lower ( ) == '<STR_LIT>' : <EOL> if vcs_type not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> error ( "<STR_LIT>" <EOL> . format ( release_tag_prompt . name , vcs_type_prompt . name ) ) <EOL> release_tag = '<STR_LIT>' <EOL> else : <EOL> release_tag = release_tag . replace ( '<STR_LIT>' , version ) <EOL> settings [ '<STR_LIT>' ] = release_tag <EOL> settings [ '<STR_LIT>' ] = track_dict [ '<STR_LIT>' ] <EOL> settings [ '<STR_LIT>' ] = track_dict [ '<STR_LIT>' ] or '<STR_LIT>' <EOL> settings [ '<STR_LIT>' ] = track_dict [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in track_dict and track_dict [ '<STR_LIT>' ] != version : <EOL> next_release_inc = str ( <NUM_LIT:0> ) <EOL> else : <EOL> next_release_inc = str ( int ( track_dict [ '<STR_LIT>' ] ) + <NUM_LIT:1> ) <EOL> settings [ '<STR_LIT>' ] = release_inc_override or next_release_inc <EOL> return settings <EOL> def find_full_path ( cmd ) : <EOL> for path in os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( os . pathsep ) : <EOL> full_path = os . path . join ( path , cmd ) <EOL> if os . path . isfile ( full_path ) : <EOL> return full_path <EOL> raise OSError ( "<STR_LIT>" ) <EOL> def execute_track ( track , track_dict , release_inc , pretend = True , debug = False , fast = False ) : <EOL> info ( "<STR_LIT>" . format ( track ) ) <EOL> settings = process_track_settings ( track_dict , release_inc ) <EOL> archive_dir_path = tempfile . mkdtemp ( ) <EOL> settings [ '<STR_LIT>' ] = archive_dir_path <EOL> if settings [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> archive_file = '<STR_LIT>' . format ( ** settings ) <EOL> else : <EOL> archive_file = '<STR_LIT>' . format ( ** settings ) <EOL> settings [ '<STR_LIT>' ] = os . path . join ( archive_dir_path , archive_file ) <EOL> info ( "<STR_LIT>" , use_prefix = False ) <EOL> info ( "<STR_LIT>" . format ( track ) ) <EOL> for action in track_dict [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in action and settings [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> warning ( "<STR_LIT>" ) <EOL> settings [ '<STR_LIT>' ] = settings [ '<STR_LIT>' ] <EOL> continue <EOL> templated_action = template_str ( action , settings ) <EOL> info ( fmt ( "<STR_LIT>" + sanitize ( str ( templated_action ) ) ) ) <EOL> if pretend : <EOL> continue <EOL> stdout = None <EOL> stderr = None <EOL> if bloom . util . _quiet : <EOL> stdout = subprocess . PIPE <EOL> stderr = subprocess . STDOUT <EOL> if debug and '<STR_LIT>' not in os . environ : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> if fast and '<STR_LIT>' not in os . environ : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> templated_action = templated_action . split ( ) <EOL> templated_action [ <NUM_LIT:0> ] = find_full_path ( templated_action [ <NUM_LIT:0> ] ) <EOL> p = subprocess . Popen ( templated_action , stdout = stdout , stderr = stderr , <EOL> shell = False , env = os . environ . copy ( ) ) <EOL> out , err = p . communicate ( ) <EOL> if bloom . util . _quiet : <EOL> info ( out , use_prefix = False ) <EOL> ret = p . returncode <EOL> if ret > <NUM_LIT:0> : <EOL> if '<STR_LIT>' in templated_action [ <NUM_LIT:0> ] and ret == code . GENERATOR_NO_ROSDEP_KEY_FOR_DISTRO : <EOL> error ( fmt ( _error + "<STR_LIT>" ) ) <EOL> error ( fmt ( "<STR_LIT>" ) ) <EOL> error ( fmt ( "<STR_LIT>" ) . format ( templated_action ) ) <EOL> info ( '<STR_LIT>' , use_prefix = False ) <EOL> error ( fmt ( "<STR_LIT>" ) ) <EOL> error ( fmt ( "<STR_LIT>" ) ) <EOL> if maybe_continue ( '<STR_LIT:n>' , '<STR_LIT>' ) : <EOL> info ( "<STR_LIT>" ) <EOL> continue <EOL> info ( '<STR_LIT>' , use_prefix = False ) <EOL> error ( fmt ( _error + "<STR_LIT>" ) <EOL> . format ( templated_action ) , exit = True ) <EOL> info ( '<STR_LIT>' , use_prefix = False ) <EOL> if not pretend : <EOL> tracks_dict = get_tracks_dict_raw ( ) <EOL> tracks_dict [ '<STR_LIT>' ] [ track ] [ '<STR_LIT>' ] = settings [ '<STR_LIT>' ] <EOL> tracks_dict [ '<STR_LIT>' ] [ track ] [ '<STR_LIT>' ] = settings [ '<STR_LIT:version>' ] <EOL> write_tracks_dict_raw ( tracks_dict , <EOL> '<STR_LIT>' + str ( settings [ '<STR_LIT>' ] ) ) <EOL> def get_argument_parser ( tracks ) : <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> add = parser . add_argument <EOL> add ( '<STR_LIT>' , choices = tracks , <EOL> help = "<STR_LIT>" ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> add ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def main ( sysargs = None ) : <EOL> from bloom . config import upconvert_bloom_to_config_branch <EOL> upconvert_bloom_to_config_branch ( ) <EOL> ensure_clean_working_env ( ) <EOL> ensure_git_root ( ) <EOL> tracks_dict = get_tracks_dict_raw ( ) <EOL> if not tracks_dict [ '<STR_LIT>' ] : <EOL> error ( "<STR_LIT>" <EOL> "<STR_LIT>" , exit = True ) <EOL> parser = get_argument_parser ( [ str ( t ) for t in tracks_dict [ '<STR_LIT>' ] ] ) <EOL> parser = add_global_arguments ( parser ) <EOL> args = parser . parse_args ( sysargs ) <EOL> handle_global_arguments ( args ) <EOL> os . environ [ '<STR_LIT>' ] = args . track <EOL> verify_track ( args . track , tracks_dict [ '<STR_LIT>' ] [ args . track ] ) <EOL> git_clone = GitClone ( ) <EOL> with git_clone : <EOL> quiet_git_clone_warning ( True ) <EOL> disable_git_clone ( True ) <EOL> execute_track ( args . track , tracks_dict [ '<STR_LIT>' ] [ args . track ] , <EOL> args . release_increment , args . pretend , args . debug , <EOL> args . unsafe ) <EOL> disable_git_clone ( False ) <EOL> quiet_git_clone_warning ( False ) <EOL> git_clone . commit ( ) <EOL> info ( '<STR_LIT>' , use_prefix = False ) <EOL> warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> info ( fmt ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> info ( fmt ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) </s>
