예제 #1
0
    def invoke_cli(cls) -> NoReturn:
        os.environ['_CLI_INVOCATION'] = 'true'
        parser = cls._setup_cli_options()
        args = parser.parse_args()
        cls._setup_logging(args)

        cls._log_cli_invoke_started()
        started_at = time.time()
        status = 0
        try:
            if args.show_version:
                cls.show_version()
            elif not args.action:
                raise argparse.ArgumentError(args.action, 'the following argument is required: action')
            elif cls._action_requires_subcommand(args.action) and not args.action_subcommand:
                raise argparse.ArgumentError(args.action_subcommand, 'the following argument is required: subcommand')
            else:
                CliApp._running_app = cls._create_instance(parser, args)
                CliApp._running_app._invoke_action(args)
        except argparse.ArgumentError as argument_error:
            parser.error(str(argument_error))
            status = 2
        except cls.CLI_EXCEPTION_TYPE as cli_exception:
            status = cls._handle_cli_exception(cli_exception)
        except KeyboardInterrupt:
            logger = log.get_logger(cls)
            logger.warning(Colors.YELLOW('Terminated'))
            status = 130
        except Exception:
            status = cls._handle_generic_exception(args.action)
        finally:
            cls._log_cli_invoke_completed(args.action, started_at, status)
        sys.exit(status)
예제 #2
0
 def __init__(self,
              auth_headers_factory: Callable[[], Dict[str, str]],
              log_requests: bool = False):
     super().__init__()
     self._auth_headers_factory = auth_headers_factory
     self._logger = log.get_logger(self.__class__,
                                   log_to_stream=log_requests)
예제 #3
0
    def _handle_cli_exception(cls, cli_exception: CliAppException) -> int:
        if cli_exception.message:
            logger = log.get_logger(cls)
            logger.error(f'{Colors.RED(cli_exception.message)}')

        if cli_exception.cli_process:
            return cli_exception.cli_process.returncode
        else:
            return 1
예제 #4
0
 def __init__(self, profiles: List[ProvisioningProfile],
              keychain_certificates: List[Certificate]):
     self.profiles: Dict[str, ProvisioningProfile] = {
         profile.uuid: profile
         for profile in profiles
     }
     self._certificates = keychain_certificates
     self._matched_profiles: List[MatchedProfile] = []
     self.logger = log.get_logger(self.__class__)
예제 #5
0
 def _handle_generic_exception(cls, action_name: str) -> int:
     logger = log.get_logger(cls)
     message = (
         f'Executing {cls.__name__} action {action_name} failed unexpectedly. '
         f'Detailed logs are available at "{log.get_log_path()}". '
         f'To see more details about the error, add `--verbose` command line option.'
     )
     logger.warning(Colors.RED(message))
     file_logger = log.get_file_logger(cls)
     file_logger.exception('Exception traceback:')
     return 9
예제 #6
0
 def __init__(self, key_identifier: KeyIdentifier, issuer_id: IssuerId, private_key: str, log_requests=False):
     """
     :param key_identifier: Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
     :param issuer_id: Your issuer ID from the API Keys page in
                       App Store Connect (Ex: 57246542-96fe-1a63-e053-0824d011072a)
     :param private_key: Private key associated with the key_identifier you specified
     """
     self._key_identifier = key_identifier
     self._issuer_id = issuer_id
     self._private_key = private_key
     self._jwt: Optional[str] = None
     self._jwt_expires: datetime = datetime.now()
     self.session = AppStoreConnectApiSession(self.generate_auth_headers, log_requests=log_requests)
     self._logger = log.get_logger(self.__class__)
    def notify(self, title: str):
        logger = log.get_logger(self.__class__)
        logger.info(title)
        options = self.dict()

        for key in sorted(options.keys()):
            value = options[key]
            option = re.sub(f'([A-Z])', r' \1', key.replace('ID', 'Id')).lstrip(' ').title()
            if isinstance(value, dict):
                logger.info(Colors.BLUE(f' - {option}:'))
                for k, v in value.items():
                    logger.info(Colors.BLUE(f'     - {k}: {v}'))
            else:
                logger.info(Colors.BLUE(f' - {option}: {value}'))
예제 #8
0
 def __init__(self,
              key_identifier: Optional[KeyIdentifier] = None,
              issuer_id: Optional[IssuerId] = None,
              private_key: Optional[str] = None,
              username: Optional[str] = None,
              password: Optional[str] = None):
     # JWT authentication fields
     self._key_identifier = key_identifier
     self._issuer_id = issuer_id
     self._private_key = private_key
     # Username and password authentication fields
     self._username = username
     self._password = password  # App Specific Password
     self._validate_authentication_info()
     self.logger = log.get_logger(self.__class__)
예제 #9
0
 def __init__(self,
              xcode_workspace: Optional[pathlib.Path] = None,
              xcode_project: Optional[pathlib.Path] = None,
              target_name: Optional[str] = None,
              configuration_name: Optional[str] = None,
              scheme_name: Optional[str] = None,
              xcpretty: Optional[Xcpretty] = None):
     self.logger = log.get_logger(self.__class__)
     self.xcpretty = xcpretty
     self.workspace = xcode_workspace.expanduser() if xcode_workspace else None
     self.project = xcode_project.expanduser() if xcode_project else None
     self.scheme = scheme_name
     self.target = target_name
     self.configuration = configuration_name
     self._ensure_scheme_or_target()
     self.logs_path = self._get_logs_path()
예제 #10
0
 def __init__(self, command_args: Sequence[CommandArg],
              safe_form: Optional[ObfuscatedCommand] = None,
              print_streams: bool = True,
              dry: bool = False):
     self.logger = log.get_logger(self.__class__)
     self.duration: float = 0
     self._process: Optional[subprocess.Popen] = None
     self._command_args = command_args
     self._dry_run = dry
     self._print_streams = print_streams
     self._buffer_size = 8192
     self.safe_form = safe_form
     if safe_form is None:
         full_command = ' '.join(shlex.quote(str(arg)) for arg in command_args)
         self.safe_form = ObfuscatedCommand(full_command)
     self.stdout = ""
     self.stderr = ""
예제 #11
0
 def __init__(self, print_function: Callable[[str], None]):
     self.logger = log.get_logger(self.__class__)
     self.print = print_function
예제 #12
0
 def __init__(self, dry=False, verbose=False, **cli_options):
     self.dry_run = dry
     self.default_obfuscation = []
     self.obfuscation = 8 * '*'
     self.verbose = verbose
     self.logger = log.get_logger(self.__class__)
예제 #13
0
 def __init__(self):
     self.logger = log.get_logger(self.__class__)
     self._ignore_xcresults: Set[pathlib.Path] = set()
     self._gathered_xcresults: Set[pathlib.Path] = set()
     self._xcresult: Optional[pathlib.Path] = None
     self._xcresult_is_merged = False
예제 #14
0
 def __init__(self, xcode_project: pathlib.Path, target_name: Optional[str],
              config_name: Optional[str]):
     self.xcode_project = xcode_project.expanduser()
     self.target = target_name
     self.config = config_name
     self.logger = log.get_logger(self.__class__)
예제 #15
0
 def __init__(self, project_data: Dict[str, Any]):
     self.plist: Dict[str, Any] = project_data
     self._project = self._get_project_section()
     self.logger = log.get_logger(self.__class__)
 def __init__(self, entitlement_data: Dict[str, Any]):
     self.plist: Dict[str, Any] = entitlement_data
     self.logger = log.get_logger(self.__class__)
예제 #17
0
 def __init__(self):
     self.logger = log.get_logger(self.__class__)