blob: f9abb5fc904d89e3d071625a04ad088b986e66cc [file] [log] [blame]
Saqib Khana8433f52017-09-22 10:21:30 -05001# Base image version class extension
2
3def do_get_version(d):
4 import configparser
5 import io
6 path = d.getVar('STAGING_DIR_HOST', True) + d.getVar('sysconfdir', True)
7 path = os.path.join(path, 'os-release')
8 parser = configparser.SafeConfigParser(strict=False)
9 parser.optionxform = str
10 version = ''
11 try:
12 with open(path, 'r') as fd:
13 buf = '[root]\n' + fd.read()
14 fd = io.StringIO(buf)
15 parser.readfp(fd)
16 version = parser['root']['VERSION_ID']
17 except:
18 pass
19 return version
20
21def do_get_versionID(d):
22 import hashlib
23 version = do_get_version(d)
24 version = version.strip('"')
25 version_id = (hashlib.sha512(version.encode('utf-8')).hexdigest())[:8]
26 return version_id