<s> from __future__ import print_function <EOL> import os <EOL> import sys <EOL> from blessings import Terminal <EOL> from werckercli . git import get_priority <EOL> from werckercli import prompt <EOL> terminal_file_handle = sys . stdout <EOL> INFO = "<STR_LIT>" <EOL> DEBUG = "<STR_LIT>" <EOL> def get_term ( ) : <EOL> return Terminal ( stream = terminal_file_handle ) <EOL> def puts ( content , level = INFO ) : <EOL> if level == INFO : <EOL> terminal_file_handle . write ( <EOL> content . encode ( "<STR_LIT:utf-8>" ) + '<STR_LIT:\n>' <EOL> ) <EOL> elif level == DEBUG : <EOL> from werckercli import config <EOL> if config . get_value ( config . VALUE_DISPLAY_DEBUG ) : <EOL> terminal_file_handle . write ( <EOL> "<STR_LIT>" + content . encode ( "<STR_LIT:utf-8>" ) + '<STR_LIT:\n>' <EOL> ) <EOL> def get_intro ( ) : <EOL> term = get_term ( ) <EOL> intro = <NUM_LIT> * u"<STR_LIT:->" <EOL> intro += u"<STR_LIT:\n>" <EOL> intro += u'<STR_LIT>' + term . green ( '<STR_LIT>' ) <EOL> intro += u"<STR_LIT:\n>" <EOL> intro += <NUM_LIT> * u"<STR_LIT:->" <EOL> intro += u"<STR_LIT:\n>" <EOL> return intro <EOL> def handle_commands ( args ) : <EOL> """<STR_LIT>""" <EOL> from werckercli . commands . create import create as command_create <EOL> from werckercli . commands . project import project_list as command_project_list <EOL> from werckercli . commands . project import project_link as command_project_link <EOL> from werckercli . commands . project import project_build as command_project_build <EOL> from werckercli . commands . build import build_list as command_builds_list <EOL> from werckercli . commands . build import build_deploy as command_builds_deploy <EOL> from werckercli . commands . target import add as command_add <EOL> from werckercli . commands . target import list_by_project as command_list_by_project <EOL> from werckercli . commands . target import link_to_deploy_target as command_target_details <EOL> from werckercli . commands . clearsettings import clear_settings as command_clear_settings <EOL> from werckercli . commands . login import login as command_login <EOL> from werckercli . commands . project import project_list_queue as command_list_jobs <EOL> from werckercli . commands . project import project_open as command_project_open <EOL> from werckercli . commands . services import search_services as command_search_services <EOL> from werckercli . commands . services import info_service as command_info_service <EOL> from werckercli . commands . services import list_services as command_list_services <EOL> from werckercli . commands . update import update as command_update <EOL> from werckercli . commands . validate import validate as command_validate <EOL> from werckercli . commands . services import add_service as command_add_service <EOL> from werckercli . commands . services import remove_service as command_remove_service <EOL> try : <EOL> if args . get ( '<STR_LIT>' ) and args . get ( '<STR_LIT>' ) : <EOL> command_create ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_create ( ) <EOL> elif args . get ( '<STR_LIT:status>' ) : <EOL> command_builds_list ( limit = <NUM_LIT:1> ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_builds_deploy ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> if args . get ( '<STR_LIT>' ) : <EOL> command_project_build ( ) <EOL> else : <EOL> command_project_list ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_project_link ( ) <EOL> elif args . get ( "<STR_LIT>" ) : <EOL> command_builds_list ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> if args . get ( '<STR_LIT>' ) : <EOL> command_add ( ) <EOL> elif args . get ( '<STR_LIT:list>' ) : <EOL> command_list_by_project ( ) <EOL> elif args . get ( '<STR_LIT>' ) or args . get ( '<STR_LIT>' ) : <EOL> command_target_details ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_project_open ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_validate ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_login ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_clear_settings ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> if args . get ( '<STR_LIT>' ) : <EOL> command_search_services ( args . get ( '<STR_LIT>' ) ) <EOL> elif args . get ( '<STR_LIT:info>' ) : <EOL> version = args . get ( '<STR_LIT>' ) <EOL> if version is None : <EOL> version = <NUM_LIT:0> <EOL> command_info_service ( <EOL> args . get ( '<STR_LIT>' ) , <EOL> version = version <EOL> ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> version = args . get ( '<STR_LIT>' ) <EOL> if version is None : <EOL> version = <NUM_LIT:0> <EOL> command_add_service ( <EOL> args . get ( '<STR_LIT>' ) , <EOL> version = version <EOL> ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_remove_service ( <EOL> args . get ( '<STR_LIT>' ) , <EOL> ) <EOL> else : <EOL> command_list_services ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_list_jobs ( ) <EOL> elif args . get ( '<STR_LIT>' ) : <EOL> command_update ( ) <EOL> except KeyboardInterrupt : <EOL> puts ( "<STR_LIT>" ) <EOL> def enter_url ( loop = True ) : <EOL> """<STR_LIT>""" <EOL> term = get_term ( ) <EOL> while True : <EOL> url = raw_input ( "<STR_LIT>" ) <EOL> if url != "<STR_LIT>" : <EOL> if get_priority ( url , "<STR_LIT>" ) == <NUM_LIT:0> : <EOL> puts ( <EOL> term . yellow ( "<STR_LIT>" ) + <EOL> "<STR_LIT>" <EOL> ) <EOL> sure = prompt . yn ( <EOL> "<STR_LIT>" , <EOL> default = "<STR_LIT:n>" <EOL> ) <EOL> if not sure : <EOL> url = "<STR_LIT>" <EOL> else : <EOL> return url <EOL> else : <EOL> return url <EOL> if not loop : <EOL> return <EOL> def pick_url ( options , allow_custom_input = False ) : <EOL> """<STR_LIT>""" <EOL> term = get_term ( ) <EOL> puts ( <EOL> "<STR_LIT>" ) <EOL> index = <NUM_LIT:1> <EOL> enter_custom_choice = <NUM_LIT:1> <EOL> default_choice = <NUM_LIT:1> <EOL> for option in options : <EOL> if ( option . priority < <NUM_LIT:1> ) : <EOL> puts ( '<STR_LIT>' % ( index , term . red ( option . url ) ) ) <EOL> if ( default_choice == index ) : <EOL> default_choice += <NUM_LIT:1> <EOL> else : <EOL> to_print = '<STR_LIT>' % ( index , option . url ) <EOL> if ( index == default_choice ) : <EOL> to_print = term . green ( to_print ) <EOL> puts ( to_print ) <EOL> index += <NUM_LIT:1> <EOL> enter_custom_choice = len ( options ) + <NUM_LIT:1> <EOL> if allow_custom_input : <EOL> puts ( '<STR_LIT>' % index ) <EOL> def option_to_str ( i ) : <EOL> if not i == default_choice : <EOL> return str ( i ) <EOL> else : <EOL> return str ( i ) + "<STR_LIT>" <EOL> if allow_custom_input : <EOL> choices = map ( <EOL> option_to_str , <EOL> range ( <NUM_LIT:1> , index + <NUM_LIT:1> ) <EOL> ) <EOL> else : <EOL> choices = map ( <EOL> option_to_str , <EOL> range ( <NUM_LIT:1> , index ) <EOL> ) <EOL> while True : <EOL> url = None <EOL> choice = raw_input ( <EOL> "<STR_LIT>" % ( <EOL> "<STR_LIT:U+002C>" . join ( choices ) , <EOL> ) <EOL> ) <EOL> selected = None <EOL> if choice == "<STR_LIT>" : <EOL> selected = default_choice <EOL> elif choice in choices : <EOL> selected = choice <EOL> try : <EOL> selected = int ( choice ) <EOL> except ValueError : <EOL> selected = None <EOL> elif choice == str ( default_choice ) : <EOL> selected = default_choice <EOL> if selected : <EOL> if allow_custom_input and selected == enter_custom_choice : <EOL> url = enter_url ( ) <EOL> else : <EOL> url = options [ selected - <NUM_LIT:1> ] . url <EOL> if url : <EOL> return url <EOL> def pick_project_name ( url ) : <EOL> project = os . path . basename ( url ) . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> puts ( "<STR_LIT>" ) <EOL> return prompt . get_value_with_default ( "<STR_LIT>" , project ) </s>
