Add new option of --run_script
authoryuhuan.yang <yuhuan.yang@123.com>
Fri, 14 Jul 2017 14:34:05 +0000 (22:34 +0800)
committeryuhuan.yang <yuhuan.yang@123.com>
Fri, 14 Jul 2017 14:35:40 +0000 (22:35 +0800)
Change-Id: I7c2d194ba3bcc4e8fc78073bc922f6e7eb853821

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..8dfaf8f 100755 (executable)
@@ -189,6 +189,8 @@ def main(parser, args, argv):
 \r
     if args.ignore_ksrepo:\r
         configmgr.create['ignore_ksrepo'] = args.ignore_ksrepo\r
+    if args.run_script:\r
+        configmgr.create['run_script'] = args.run_script\r
         \r
     creater = createrClass()\r
     creater.do_create(args)\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..59138fc 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -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")