<s> import argparse <EOL> import codecs <EOL> import copy <EOL> import logging <EOL> import os <EOL> import subprocess <EOL> import sys <EOL> import time <EOL> import traceback <EOL> from blessings import Terminal <EOL> try : <EOL> from jira . utils import JIRAError <EOL> except ImportError : <EOL> from jira . exceptions import JIRAError <EOL> import six <EOL> from six . moves import shlex_quote <EOL> from verlib import NormalizedVersion <EOL> from . import utils <EOL> from . exceptions import ( <EOL> GitCommandError , <EOL> JiraInteractionFailed , <EOL> JirafsError , <EOL> NotTicketFolderException <EOL> ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) and sys . stdout . encoding is None : <EOL> sys . stdout = codecs . getwriter ( '<STR_LIT:utf-8>' ) ( sys . stdout ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> def main ( ) : <EOL> term = Terminal ( ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> if utils . get_git_version ( ) < NormalizedVersion ( '<STR_LIT>' ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> commands = utils . get_installed_commands ( ) <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' , <EOL> add_help = False , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = six . text_type , <EOL> choices = commands . keys ( ) <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> dest = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> default = os . getcwd ( ) <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> ) <EOL> args , extra = parser . parse_known_args ( ) <EOL> if args . log_level is not None : <EOL> logging . basicConfig ( level = logging . getLevelName ( args . log_level ) ) <EOL> command_name = args . command <EOL> cmd_class = commands [ command_name ] <EOL> if args . subtasks : <EOL> cmd_class . RUN_FOR_SUBTASKS = True <EOL> started = time . time ( ) <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> command_name , <EOL> extra <EOL> ) <EOL> jira = utils . lazy_get_jira ( ) <EOL> try : <EOL> value = cmd_class . execute_command ( <EOL> extra , jira = jira , path = args . folder , command_name = command_name <EOL> ) <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> command_name , <EOL> extra , <EOL> ( time . time ( ) - started ) <EOL> ) <EOL> if value : <EOL> value . echo ( ) <EOL> sys . exit ( value . return_code ) <EOL> except GitCommandError as e : <EOL> print ( <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( <EOL> t = term , <EOL> code = e . returncode <EOL> ) <EOL> ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( u"<STR_LIT>" . format ( t = term ) ) <EOL> print ( u"<STR_LIT>" . format ( cmd = e . command ) ) <EOL> print ( u"<STR_LIT>" . format ( t = term ) ) <EOL> print ( u"<STR_LIT>" . format ( t = term ) ) <EOL> for line in e . output . decode ( '<STR_LIT:utf8>' ) . split ( '<STR_LIT:\n>' ) : <EOL> print ( u"<STR_LIT>" % line ) <EOL> print ( u"<STR_LIT>" . format ( t = term ) ) <EOL> if args . traceback : <EOL> traceback . print_exc ( ) <EOL> sys . exit ( <NUM_LIT:10> ) <EOL> except NotTicketFolderException : <EOL> if not getattr ( cmd_class , '<STR_LIT>' , False ) : <EOL> print ( <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( <EOL> t = term , <EOL> cmd = command_name <EOL> ) <EOL> ) <EOL> sys . exit ( <NUM_LIT:20> ) <EOL> elif args . no_subfolders : <EOL> sys . exit ( <NUM_LIT:20> ) <EOL> count_runs = <NUM_LIT:0> <EOL> for folder in os . listdir ( os . getcwd ( ) ) : <EOL> full_path = os . path . join ( <EOL> os . getcwd ( ) , <EOL> folder , <EOL> ) <EOL> if not os . path . isdir ( full_path ) : <EOL> continue <EOL> try : <EOL> full_args = copy . copy ( sys . argv ) <EOL> if '<STR_LIT>' not in full_args : <EOL> full_args . append ( '<STR_LIT>' ) <EOL> result = subprocess . call ( <EOL> '<STR_LIT:U+0020>' . join ( [ shlex_quote ( a ) for a in full_args ] ) , <EOL> cwd = full_path , <EOL> shell = True <EOL> ) <EOL> if result == <NUM_LIT:0> : <EOL> count_runs += <NUM_LIT:1> <EOL> except NotTicketFolderException : <EOL> pass <EOL> if count_runs == <NUM_LIT:0> : <EOL> if args . traceback : <EOL> traceback . print_exc ( ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> except JIRAError as e : <EOL> print ( <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( <EOL> t = term , <EOL> error = str ( e ) <EOL> ) <EOL> ) <EOL> if args . traceback : <EOL> traceback . print_exc ( ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> except JiraInteractionFailed as e : <EOL> print ( <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( <EOL> t = term , <EOL> error = str ( e ) <EOL> ) <EOL> ) <EOL> if args . traceback : <EOL> traceback . print_exc ( ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> except JirafsError as e : <EOL> print ( <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( <EOL> t = term , <EOL> error = str ( e ) <EOL> ) <EOL> ) <EOL> if args . traceback : <EOL> traceback . print_exc ( ) <EOL> sys . exit ( <NUM_LIT> ) </s>
