[BuildMonitor] fix to get the right bm_img_path when there are various img file formats 16/116616/1
authorSungHun Hwang <sh0924.hwang@samsung.com>
Mon, 27 Feb 2017 07:59:03 +0000 (16:59 +0900)
committerSungHun Hwang <sh0924.hwang@samsung.com>
Mon, 27 Feb 2017 07:59:03 +0000 (16:59 +0900)
fix to get the right bm_img_path from 'manifest.json' file
when there are various img file formats

mic support various image file formats (*.tar.gz, *.bz2, etc)
some images in common profile are created by *.bz2

Change-Id: Id9506867062b418a61591e6b0556b361821fd2ac
Signed-off-by: SungHun Hwang <sh0924.hwang@samsung.com>
job_imager.py

index 63570a7..c1481cb 100755 (executable)
@@ -340,10 +340,27 @@ def main():
 
         if buildmonitor_enabled:
             bm_img_url = os.path.join(sync_src, fields['images_path'])
-            bm_img_path = bm_img_url + '/' + build_id + '_' + fields['name'] + '.tar.gz'
-            bm_img_size = os.path.getsize(bm_img_path)
-            #print '[%s] bm_img_path(%s), bm_img_size(%s)\n' \
-            #      % (__file__, bm_img_path, bm_img_size)
+
+            # get bm_img_name from 'manifest.json' file
+            search_name = 'image_files'
+            manifest_name = 'manifest.json'
+            bm_manifest_path = os.path.join(bm_img_url, manifest_name)
+            with open(bm_manifest_path,'r') as f:
+                bm_dict = eval(f.read())
+                for key, val in bm_dict.iteritems():
+                    if isinstance(val, dict) and val.has_key(search_name):
+                        bm_img_name = val.get(search_name)[0]
+
+            bm_img_path = os.path.join(bm_img_url, bm_img_name)
+            print '[%s] bm_img_path(%s))\n' % (__file__, bm_img_path)
+
+            if os.path.isfile(bm_img_path):
+                bm_img_size = os.path.getsize(bm_img_path)
+                #print '[%s] bm_img_path(%s), bm_img_size(%s)\n' \
+                #      % (__file__, bm_img_path, bm_img_size)
+            else:
+                print '[%s] %s does not exist!!\n' % (__file__, bm_img_path)
+                bm_img_size = 0
 
             bm_end_datetime = datetime.datetime.now()
             bm_stage = 'Image'