Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 1 | # Base image version class extension |
| 2 | |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 3 | DEPENDS:append = " os-release" |
Brad Bishop | d1ba4e5 | 2018-02-08 20:26:58 -0500 | [diff] [blame] | 4 | |
Adriana Kobylak | 4e4b63a | 2022-08-04 09:13:06 -0500 | [diff] [blame] | 5 | def do_get_os_release_value(d, key): |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 6 | import configparser |
| 7 | import io |
Brad Bishop | d1ba4e5 | 2018-02-08 20:26:58 -0500 | [diff] [blame] | 8 | path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True) |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 9 | path = os.path.join(path, 'os-release') |
Patrick Williams | d44abb3 | 2021-10-14 21:28:20 -0500 | [diff] [blame] | 10 | parser = configparser.ConfigParser(strict=False) |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 11 | parser.optionxform = str |
Adriana Kobylak | 4e4b63a | 2022-08-04 09:13:06 -0500 | [diff] [blame] | 12 | value = '' |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 13 | try: |
| 14 | with open(path, 'r') as fd: |
| 15 | buf = '[root]\n' + fd.read() |
| 16 | fd = io.StringIO(buf) |
| 17 | parser.readfp(fd) |
Adriana Kobylak | 4e4b63a | 2022-08-04 09:13:06 -0500 | [diff] [blame] | 18 | value = parser['root'][key] |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 19 | except: |
| 20 | pass |
Adriana Kobylak | 4e4b63a | 2022-08-04 09:13:06 -0500 | [diff] [blame] | 21 | return value |
| 22 | |
| 23 | def do_get_version(d): |
| 24 | version = do_get_os_release_value(d, 'VERSION_ID') |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 25 | return version |
| 26 | |
| 27 | def 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 Kobylak | cdd91ad | 2021-10-25 15:58:19 +0000 | [diff] [blame] | 33 | |
| 34 | def do_get_buildID(d): |
Adriana Kobylak | 4e4b63a | 2022-08-04 09:13:06 -0500 | [diff] [blame] | 35 | build_id = do_get_os_release_value(d, 'BUILD_ID') |
Adriana Kobylak | cdd91ad | 2021-10-25 15:58:19 +0000 | [diff] [blame] | 36 | return build_id |
Adriana Kobylak | bde7dbe | 2022-08-04 09:13:26 -0500 | [diff] [blame] | 37 | |
| 38 | def do_get_extended_version(d): |
| 39 | extended_version = do_get_os_release_value(d, 'EXTENDED_VERSION') |
| 40 | return extended_version |