From 6cceddb03a3cad7a09a70d0c2fdc901d9758c025 Mon Sep 17 00:00:00 2001 From: Yue Tao Date: Wed, 20 Apr 2022 14:29:27 +0800 Subject: [PATCH] Determine the SW_VERSION at run time Get the SW_VERSION via parsing the /etc/build.info file instead of tsconfig.tsconfig module at run time to break python-keyring run depends on tsconfig. Signed-off-by: Yue Tao --- keyring/util/platform_.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/keyring/util/platform_.py b/keyring/util/platform_.py index bb4d297..5eebd70 100644 --- a/keyring/util/platform_.py +++ b/keyring/util/platform_.py @@ -21,7 +21,23 @@ def _data_root_Linux(): Use freedesktop.org Base Dir Specfication to determine storage location. """ - fallback = os.path.expanduser('/opt/platform/.keyring/') + build_info = "/etc/build.info" + try: + with open(build_info, 'r') as binfo: + lines = list(line for line in (p.strip() for p in binfo) if line) + except Exception as e: + print(e, file=sys.stderr) + raise IOError + + sw_version = None + for entry in lines: + if entry.startswith('SW_VERSION='): + sw_version = entry.split("=")[1].strip('"') + break + if sw_version == None: + raise ValueError(f"No SW_VERSION found in {build_info}") + keyring_dir = os.path.join('/opt/platform/.keyring', sw_version) + fallback = os.path.expanduser(keyring_dir) root = os.environ.get('XDG_DATA_HOME', None) or fallback return os.path.join(root, 'python_keyring') -- 2.25.1