image_version: Simplify function to get os-release value

The logic to get an os-release value was duplicated. Move this logic to
a single function to remove the duplication. This can also help to avoid
further duplication if additional values need to be parsed.

Tested: Verified the contents of the MANIFEST file were the same after
this change.

Change-Id: Iacdb2c7e644103d76b73f32b15a089d352f40001
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/meta-phosphor/classes/image_version.bbclass b/meta-phosphor/classes/image_version.bbclass
index 17f324e..2a6d75a 100644
--- a/meta-phosphor/classes/image_version.bbclass
+++ b/meta-phosphor/classes/image_version.bbclass
@@ -2,22 +2,26 @@
 
 DEPENDS:append = " os-release"
 
-def do_get_version(d):
+def do_get_os_release_value(d, key):
     import configparser
     import io
     path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True)
     path = os.path.join(path, 'os-release')
     parser = configparser.ConfigParser(strict=False)
     parser.optionxform = str
-    version = ''
+    value = ''
     try:
         with open(path, 'r') as fd:
             buf = '[root]\n' + fd.read()
             fd = io.StringIO(buf)
             parser.readfp(fd)
-            version = parser['root']['VERSION_ID']
+            value = parser['root'][key]
     except:
         pass
+    return value
+
+def do_get_version(d):
+    version = do_get_os_release_value(d, 'VERSION_ID')
     return version
 
 def do_get_versionID(d):
@@ -28,19 +32,5 @@
     return version_id
 
 def do_get_buildID(d):
-    import configparser
-    import io
-    path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True)
-    path = os.path.join(path, 'os-release')
-    parser = configparser.ConfigParser(strict=False)
-    parser.optionxform = str
-    build_id = ''
-    try:
-        with open(path, 'r') as fd:
-            buf = '[root]\n' + fd.read()
-            fd = io.StringIO(buf)
-            parser.readfp(fd)
-            build_id = parser['root']['BUILD_ID']
-    except:
-        pass
+    build_id = do_get_os_release_value(d, 'BUILD_ID')
     return build_id