diff options
author | Hsin-Yi Chen <hsinyichen@google.com> | 2024-04-26 12:24:12 +0800 |
---|---|---|
committer | Hsin-Yi Chen <hsinyichen@google.com> | 2024-04-26 12:40:46 +0800 |
commit | 70f910c8ec844daccc7c0c8dad7e04dcd1a751c0 (patch) | |
tree | 1acd0b22f3e315c1d47a7f4730ecd393a3deb27a | |
parent | cafb3198b94be4bd3149b276d142742e953ef197 (diff) | |
download | acloud-main.tar.gz |
Bug: 336459249
Test: python3.7 ./acloud-dev --version
Change-Id: I48f1c7843d7baecf1dbf34cc83fae09e069c0e22
-rwxr-xr-x | public/config.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/public/config.py b/public/config.py index aba16555..3548b7ca 100755 --- a/public/config.py +++ b/public/config.py @@ -62,14 +62,17 @@ logger = logging.getLogger(__name__) _DEFAULT_CONFIG_FILE = "acloud.config" _DEFAULT_HW_PROPERTY = "cpu:4,resolution:720x1280,dpi:320,memory:4g" -# VERSION +# Resources +_INTERNAL_CONFIG_FILE = "default.config" _VERSION_FILE = "VERSION" _UNKNOWN = "UNKNOWN" _NUM_INSTANCES_ARG = "-num_instances" -def _Resources(): - return importlib.resources.files("acloud.public.data") +def _OpenTextResource(resource): + # Acloud binary does not have the embedded launcher, and it should be + # compatible with python3.7 installed on the test servers. + return importlib.resources.open_text("acloud.public.data", resource) def GetVersion(): @@ -82,7 +85,7 @@ def GetVersion(): String of the acloud version. """ try: - with _Resources().joinpath(_VERSION_FILE).open("r") as version_file: + with _OpenTextResource(_VERSION_FILE) as version_file: return version_file.read() except FileNotFoundError: return _UNKNOWN @@ -378,7 +381,7 @@ class AcloudConfigManager(): internal_cfg = None usr_cfg = None try: - with _Resources().joinpath("default.config").open('r') as cfg_file: + with _OpenTextResource(_INTERNAL_CONFIG_FILE) as cfg_file: internal_cfg = self.LoadConfigFromProtocolBuffer( cfg_file, internal_config_pb2.InternalConfig) except OSError as e: |