blob: 5462323471af4d9ae39db11c7b3903c3f78ed544 [file] [log] [blame]
Saqib Khan41723472017-09-22 10:21:30 -05001# Base image version class extension
2
Patrick Williams12fc9392021-08-06 09:16:53 -05003DEPENDS:append = " os-release"
Brad Bishopd1ba4e52018-02-08 20:26:58 -05004
Adriana Kobylak4e4b63a2022-08-04 09:13:06 -05005def do_get_os_release_value(d, key):
Saqib Khan41723472017-09-22 10:21:30 -05006 import configparser
7 import io
Brad Bishopd1ba4e52018-02-08 20:26:58 -05008 path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True)
Saqib Khan41723472017-09-22 10:21:30 -05009 path = os.path.join(path, 'os-release')
Patrick Williamsd44abb32021-10-14 21:28:20 -050010 parser = configparser.ConfigParser(strict=False)
Saqib Khan41723472017-09-22 10:21:30 -050011 parser.optionxform = str
Adriana Kobylak4e4b63a2022-08-04 09:13:06 -050012 value = ''
Saqib Khan41723472017-09-22 10:21:30 -050013 try:
14 with open(path, 'r') as fd:
15 buf = '[root]\n' + fd.read()
16 fd = io.StringIO(buf)
Patrick Williams161a8ff2023-03-09 16:20:57 -060017 parser.read_file(fd)
Adriana Kobylak4e4b63a2022-08-04 09:13:06 -050018 value = parser['root'][key]
Saqib Khan41723472017-09-22 10:21:30 -050019 except:
20 pass
Adriana Kobylak4e4b63a2022-08-04 09:13:06 -050021 return value
22
23def do_get_version(d):
24 version = do_get_os_release_value(d, 'VERSION_ID')
Saqib Khan41723472017-09-22 10:21:30 -050025 return version
26
27def do_get_versionID(d):
28 import hashlib
29 version = do_get_version(d)
30 version = version.strip('"')
31 version_id = (hashlib.sha512(version.encode('utf-8')).hexdigest())[:8]
32 return version_id
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +000033
34def do_get_buildID(d):
Adriana Kobylak4e4b63a2022-08-04 09:13:06 -050035 build_id = do_get_os_release_value(d, 'BUILD_ID')
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +000036 return build_id
Adriana Kobylakbde7dbe2022-08-04 09:13:26 -050037
38def do_get_extended_version(d):
39 extended_version = do_get_os_release_value(d, 'EXTENDED_VERSION')
40 return extended_version