blob: 17f324e2e44cd5a4daf16cc89b77739e902c7cd0 [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')
Patrick Williamsd44abb32021-10-14 21:28:20 -050010 parser = configparser.ConfigParser(strict=False)
Saqib Khan41723472017-09-22 10:21:30 -050011 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
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +000029
30def do_get_buildID(d):
31 import configparser
32 import io
33 path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True)
34 path = os.path.join(path, 'os-release')
35 parser = configparser.ConfigParser(strict=False)
36 parser.optionxform = str
37 build_id = ''
38 try:
39 with open(path, 'r') as fd:
40 buf = '[root]\n' + fd.read()
41 fd = io.StringIO(buf)
42 parser.readfp(fd)
43 build_id = parser['root']['BUILD_ID']
44 except:
45 pass
46 return build_id