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>
Mon, 11 Sep 2017 13:17:50 +0000 (21:17 +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 54fdbde18f530a065025c561199fb8635e746f0d..8dfaf8fda52831f15797319fa2b30e961e24c542 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 d844c6533a00e2faee239f386ec9539e6634a5c8..a45b05ee295ce5306b5f39c1ab9902e6a6a6bf16 100755 (executable)
@@ -75,6 +75,7 @@ class ConfigMgr(object):
                     "extrarepos": {},
                     "ignore_ksrepo": False,
                     "strict_mode": False,
+                    "run_script": None,
                 },
                 'chroot': {
                     "saveto": None,
index 86b1849b80037245360d4d40d6790a2c1f5030ae..a6b5cf8034b0f76eb5933c4a825b602a6545c970 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 755d8d5cb0600a6841c0c4aa292737c3c7b57ba1..c3fa67b755fcdda418a7a4ec96a306ba51f16ddc 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 09bc7904a7f67b58bb9fce64da841e3e5dc53d78..27a712b2cc46324e4fbb4c23ca509a3594f73cd6 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 09a9714c369ed5b9ef1f629090902c3cd928b3d4..554eac76902fa06c7e2caa2a523f48067f248685 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 7aa8b35e9a71784055bee5360db51e4ee400f586..59138fc50e9ef6e55cddd9bab4f94746279b5dfc 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")