123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #
- # Copyright (c) Contributors to the Open 3D Engine Project.
- # For complete copyright and license terms please see the LICENSE at the root of this distribution.
- #
- # SPDX-License-Identifier: Apache-2.0 OR MIT
- #
- import os
- from config_data import ConfigData
- from threaded_lambda import ThreadedLambda
- from subprocess_runner import SubprocessRunner
- class KeystoreGenerator(ThreadedLambda):
- """
- This class knows how to use the keytool JAVA command to create
- a new keystore. It also uses o3de.bat/o3de.sh to store configuration
- data for the current project.
- """
- def __init__(self, config: ConfigData):
- def _job_func():
- self._run_commands()
- super().__init__("Keystore Generator", _job_func)
- ks = config.keystore_settings
- o3de_cmd = config.get_o3de_cmd()
- self._keystoreFileConfigureCmd = SubprocessRunner(
- [
- o3de_cmd,
- "android-configure",
- "--set-value",
- f"signconfig.store.file={ks.keystore_file}",
- "--project",
- config.project_path,
- ],
- timeOutSeconds=10,
- )
- self._keystoreKeyAliasConfigureCmd = SubprocessRunner(
- [
- o3de_cmd,
- "android-configure",
- "--set-value",
- f"signconfig.key.alias={ks.key_alias}",
- "--project",
- config.project_path,
- ],
- timeOutSeconds=10,
- )
- self._keystoreStorePasswordConfigureCmd = SubprocessRunner(
- [
- o3de_cmd,
- "android-configure",
- "--set-value",
- f"signconfig.store.password={ks.keystore_password}",
- "--project",
- config.project_path,
- ],
- timeOutSeconds=10,
- )
- self._keystoreKeyPasswordConfigureCmd = SubprocessRunner(
- [
- o3de_cmd,
- "android-configure",
- "--set-value",
- f"signconfig.key.password={ks.key_password}",
- "--project",
- config.project_path,
- ],
- timeOutSeconds=10,
- )
- self._keystoreCreateCmd = SubprocessRunner(
- [
- "keytool",
- "-genkey",
- "-keystore",
- ks.keystore_file,
- "-storepass",
- ks.keystore_password,
- "-alias",
- ks.key_alias,
- "-keypass",
- ks.key_password,
- "-keyalg",
- "RSA",
- "-keysize",
- ks.key_size,
- "-validity",
- ks.validity_days,
- "-dname",
- ks.get_distinguished_name(),
- ],
- timeOutSeconds=10,
- )
- def _run_commands(self):
- """
- This is a "protected" function. It is invoked when super().start() is called.
- """
- if self._is_cancelled:
- self._is_finished = True
- self._is_success = False
- return
- commands = [
- self._keystoreFileConfigureCmd,
- self._keystoreKeyAliasConfigureCmd,
- self._keystoreStorePasswordConfigureCmd,
- self._keystoreKeyPasswordConfigureCmd,
- self._keystoreCreateCmd,
- ]
- for command in commands:
- if self._is_cancelled:
- self._is_finished = True
- self._is_success = False
- return
- if not command.run():
- self._record_command_error(command)
- return
- else:
- self._record_command_results(command)
- self._is_finished = True
- self._is_success = True
- self._report_msg += f"Next Steps:\nYou can now generate the android project by pushing the `Generate Project` button.\n"
- def _record_command_error(self, command: SubprocessRunner):
- self._is_finished = True
- self._is_success = False
- self._record_command_results(command)
- def _record_command_results(self, command: SubprocessRunner):
- self._report_msg += f"Command:\n{command.get_command_str()}\nCompleted with status code {command.get_error_code()}.\n"
- self._report_msg += command.get_stdall()
- # class KeystoreGenerator END
- ######################################################
|