Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 1 | # Base image version class extension |
| 2 | |
| 3 | def 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 | |
| 21 | def 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 |