Add new option of --run_script. 14/151514/2
authoryangyuhuan <yuhuan.yang@samsung.com>
Thu, 21 Sep 2017 14:41:37 +0000 (22:41 +0800)
committeryangyuhuan <yuhuan.yang@samsung.com>
Thu, 21 Sep 2017 14:45:59 +0000 (22:45 +0800)
Change-Id: I16ccc176477f1087d0f6aff0b2e29c3616297dd7

mic/cmd_create.py
mic/conf.py
plugins/imager/fs_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/qcow_plugin.py
plugins/imager/raw_plugin.py
tools/mic

index 54fdbde..291e8d1 100755 (executable)
@@ -189,7 +189,9 @@ def main(parser, args, argv):
 \r
     if args.ignore_ksrepo:\r
         configmgr.create['ignore_ksrepo'] = args.ignore_ksrepo\r
-        \r
+    if args.run_script:\r
+        configmgr.create['run_script'] = args.run_script\r
+\r
     creater = createrClass()\r
     creater.do_create(args)\r
 \r
index d844c65..a45b05e 100755 (executable)
@@ -75,6 +75,7 @@ class ConfigMgr(object):
                     "extrarepos": {},
                     "ignore_ksrepo": False,
                     "strict_mode": False,
+                    "run_script": None,
                 },
                 'chroot': {
                     "saveto": None,
index 86b1849..a6b5cf8 100755 (executable)
@@ -15,6 +15,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc., 59
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+import subprocess
 from mic import chroot, msger, rt_util
 from mic.utils import misc, errors, fs_related
 from mic.imager import fs
@@ -114,6 +115,17 @@ class FsPlugin(ImagerPlugin):
         finally:
             creator.cleanup()
 
+        #Run script of --run_script after image created
+        if creatoropts['run_script']:
+            cmd = creatoropts['run_script']
+            msger.info("Running command in parameter run_script: "+"".join(cmd))
+            try:
+                p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+                p.communicate()
+            except OSError,err:
+                msger.warning(str(err))
+
+
         msger.info("Finished.")
         return 0
 
index 755d8d5..c3fa67b 100755 (executable)
@@ -16,6 +16,7 @@
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import subprocess
 import shutil
 import tempfile
 
@@ -119,6 +120,16 @@ class LoopPlugin(ImagerPlugin):
         finally:
             creator.cleanup()
 
+        #Run script of --run_script after image created
+        if creatoropts['run_script']:
+            cmd = creatoropts['run_script']
+            msger.info("Running command in parameter run_script: "+"".join(cmd))
+            try:
+                p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+                p.communicate()
+            except OSError,err:
+                msger.warning(str(err))
+
         msger.info("Finished.")
         return 0
 
index 09bc790..27a712b 100755 (executable)
@@ -15,6 +15,7 @@
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import subprocess
 import shutil
 
 from mic import msger, rt_util
@@ -150,6 +151,17 @@ class QcowPlugin(ImagerPlugin):
         finally:
             creator.cleanup()
 
+        #Run script of --run_script after image created
+        if creatoropts['run_script']:
+            cmd = creatoropts['run_script']
+            msger.info("Running command in parameter run_script: "+"".join(cmd))
+            try:
+                p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+                p.communicate()
+            except OSError,err:
+                msger.warning(str(err))
+
+
         msger.info("Finished.")
         return 0
 
index 09a9714..554eac7 100755 (executable)
@@ -16,6 +16,7 @@
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import subprocess
 import shutil
 import re
 import tempfile
@@ -113,6 +114,17 @@ class RawPlugin(ImagerPlugin):
         finally:
             creator.cleanup()
 
+        #Run script of --run_script after image created
+        if creatoropts['run_script']:
+            cmd = creatoropts['run_script']
+            msger.info("Running command in parameter run_script: "+"".join(cmd))
+            try:
+                p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+                p.communicate()
+            except OSError,err:
+                msger.warning(str(err))
+
+
         msger.info("Finished.")
         return 0
 
index 7aa8b35..6bc2770 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -124,7 +124,7 @@ def create_parser(parser):
                                dest='strict_mode', default=False,
                                help='Abort creation of image, if there are some errors'
                                     ' during rpm installation. ')
-     
+
     parent_parser.add_argument('-d', '--debug', action='store_true',
                                help='debug output')
     parent_parser.add_argument('-v', '--verbose', action='store_true',
@@ -132,6 +132,8 @@ def create_parser(parser):
     parent_parser.add_argument('-i', '--interactive', action='store_true',
                                 dest='interactive', default=True,
                                help='interactive output')
+    parent_parser.add_argument('--run_script', action='store', dest='run_script',
+                                                   default=None, help='Run script on local PC after image created')
 
     parser.set_defaults(alias="cr")