def _unlock_keychain(self): password_file = join(self.buildozer.buildozer_dir, '.ioscodesign') password = None if self.buildozer.file_exists(password_file): with open(password_file) as fd: password = fd.read() if not password: # no password available, try to unlock anyway... error = self.buildozer.cmd('security unlock-keychain -u', break_on_error=False)[2] if not error: return else: # password available, try to unlock error = self.buildozer.cmd( 'security unlock-keychain -p {}'.format(password), break_on_error=False, sensible=True)[2] if not error: return # we need the password to unlock. correct = False attempt = 3 while attempt: attempt -= 1 password = getpass('Password to unlock the default keychain:') error = self.buildozer.cmd( 'security unlock-keychain -p "{}"'.format(password), break_on_error=False, sensible=True)[2] if not error: correct = True break self.buildozer.error('Invalid keychain password') if not correct: self.buildozer.error('Unable to unlock the keychain, exiting.') raise BuildozerCommandException() # maybe user want to save it for further reuse? print('The keychain password can be saved in the build directory\n' 'As soon as the build directory will be cleaned, ' 'the password will be erased.') save = None while save is None: q = input('Do you want to save the password (Y/n): ') if q in ('', 'Y'): save = True elif q == 'n': save = False else: print('Invalid answer!') if save: with open(password_file, 'wb') as fd: fd.write(password.encode())
def test_exit_code(self): """ Makes sure the CLI exits with error code on BuildozerCommandException, refs #674. """ with mock.patch('buildozer.Buildozer.run_command') as m_run_command: m_run_command.side_effect = BuildozerCommandException() with self.assertRaises(SystemExit) as context: client.main() assert context.exception.code == 1