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 | |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 5 | def do_get_version(d): |
| 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') |
| 10 | parser = configparser.SafeConfigParser(strict=False) |
| 11 | parser.optionxform = str |
| 12 | version = '' |
| 13 | try: |
| 14 | with open(path, 'r') as fd: |
| 15 | buf = '[root]\n' + fd.read() |
| 16 | fd = io.StringIO(buf) |
| 17 | parser.readfp(fd) |
| 18 | version = parser['root']['VERSION_ID'] |
| 19 | except: |
| 20 | pass |
| 21 | return version |
| 22 | |
| 23 | def do_get_versionID(d): |
| 24 | import hashlib |
| 25 | version = do_get_version(d) |
| 26 | version = version.strip('"') |
| 27 | version_id = (hashlib.sha512(version.encode('utf-8')).hexdigest())[:8] |
| 28 | return version_id |