blob: 56ebe665cd05266bc30502321fd973ffdb6f755c [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
Saqib Khan41723472017-09-22 10:21:30 -05005def do_get_version(d):
6 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')
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
23def 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