summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authoryyh <yyh@123.com>2016-01-26 18:21:34 +0800
committeryyh <yyh@123.com>2016-02-04 14:18:57 +0800
commita5878ae2f3aa82d6b9cc59d7434c2f80e28f7471 (patch)
tree209055077dc64bbf59146a59d7dddc3c17cb533c /plugins
parent1fd1b7a024b16dece3082bc94c760de9201dc4d7 (diff)
downloadmic-a5878ae2f3aa82d6b9cc59d7434c2f80e28f7471.tar.gz
mic-a5878ae2f3aa82d6b9cc59d7434c2f80e28f7471.tar.bz2
mic-a5878ae2f3aa82d6b9cc59d7434c2f80e28f7471.zip
Using argparse module to parse the cmd line
Conflicts: plugins/imager/loop_plugin.py
Diffstat (limited to 'plugins')
-rw-r--r--plugins/imager/fs_plugin.py19
-rw-r--r--plugins/imager/loop_plugin.py29
-rw-r--r--plugins/imager/qcow_plugin.py10
3 files changed, 22 insertions, 36 deletions
diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py
index faee633..d74530f 100644
--- a/plugins/imager/fs_plugin.py
+++ b/plugins/imager/fs_plugin.py
@@ -16,7 +16,7 @@
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from mic import chroot, msger, rt_util
-from mic.utils import cmdln, misc, errors, fs_related
+from mic.utils import misc, errors, fs_related
from mic.imager import fs
from mic.conf import configmgr
from mic.plugin import pluginmgr
@@ -26,12 +26,7 @@ class FsPlugin(ImagerPlugin):
name = 'fs'
@classmethod
- @cmdln.option("--include-src",
- dest = "include_src",
- action = "store_true",
- default = False,
- help = "Generate a image with source rpms included")
- def do_create(self, subcmd, opts, *args):
+ def do_create(self, args):
"""${cmd_name}: create fs image
Usage:
@@ -40,11 +35,11 @@ class FsPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
+ if args is None:
+ raise errors.Usage("Invalid arguments.")
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == 'bootstrap':
configmgr._ksconf = ksconf
@@ -83,7 +78,7 @@ class FsPlugin(ImagerPlugin):
','.join(backends.keys())))
creator = fs.FsImageCreator(creatoropts, pkgmgr)
- creator._include_src = opts.include_src
+ creator._include_src = args.include_src
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
@@ -98,7 +93,7 @@ class FsPlugin(ImagerPlugin):
creator.mount(None, creatoropts["cachedir"])
creator.install()
#Download the source packages ###private options
- if opts.include_src:
+ if args.include_src:
installed_pkgs = creator.get_installed_packages()
msger.info('--------------------------------------------------')
msger.info('Generating the image with source rpms included ...')
diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py
index f0f2771..1830230 100644
--- a/plugins/imager/loop_plugin.py
+++ b/plugins/imager/loop_plugin.py
@@ -20,7 +20,7 @@ import shutil
import tempfile
from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors, cmdln
+from mic.utils import misc, fs_related, errors
from mic.conf import configmgr
from mic.plugin import pluginmgr
from mic.imager.loop import LoopImageCreator, load_mountpoints
@@ -30,16 +30,7 @@ class LoopPlugin(ImagerPlugin):
name = 'loop'
@classmethod
- @cmdln.option("--compress-disk-image", dest="compress_image",
- type='choice', choices=("gz", "bz2"), default=None,
- help="Same with --compress-image")
- # alias to compress-image for compatibility
- @cmdln.option("--compress-image", dest="compress_image",
- type='choice', choices=("gz", "bz2"), default=None,
- help="Compress all loop images with 'gz' or 'bz2'")
- @cmdln.option("--shrink", action='store_true', default=False,
- help="Whether to shrink loop images to minimal size")
- def do_create(self, subcmd, opts, *args):
+ def do_create(self, args):
"""${cmd_name}: create loop image
Usage:
@@ -48,16 +39,16 @@ class LoopPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
+ if args is None:
+ raise errors.Usage("Invalid arguments")
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == "bootstrap":
configmgr._ksconf = ksconf
rt_util.bootstrap_mic()
-
+
recording_pkgs = []
if len(creatoropts['record_pkgs']) > 0:
recording_pkgs = creatoropts['record_pkgs']
@@ -92,8 +83,8 @@ class LoopPlugin(ImagerPlugin):
creator = LoopImageCreator(creatoropts,
pkgmgr,
- opts.compress_image,
- opts.shrink)
+ args.compress_image,
+ args.shrink)
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
@@ -228,8 +219,8 @@ class LoopPlugin(ImagerPlugin):
raise
try:
- if len(cmd) != 0:
- cmdline = ' '.join(cmd)
+ if cmd is not None:
+ cmdline = cmd
else:
cmdline = "/bin/bash"
envcmd = fs_related.find_binary_inchroot("env", extmnt)
diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py
index 17b707c..8acf572 100644
--- a/plugins/imager/qcow_plugin.py
+++ b/plugins/imager/qcow_plugin.py
@@ -64,7 +64,7 @@ class QcowPlugin(ImagerPlugin):
name = 'qcow'
@classmethod
- def do_create(cls, subcmd, opts, *args):
+ def do_create(cls, args):
"""${cmd_name}: create qcow image
Usage:
@@ -72,11 +72,11 @@ class QcowPlugin(ImagerPlugin):
${cmd_option_list}
"""
- if len(args) != 1:
- raise errors.Usage("Extra arguments given")
+ if args is None:
+ raise errors.Usage("Invalid arguments")
creatoropts = configmgr.create
- ksconf = args[0]
+ ksconf = args.ksfile
if creatoropts['runtime'] == "bootstrap":
configmgr._ksconf = ksconf
@@ -110,7 +110,7 @@ class QcowPlugin(ImagerPlugin):
if not pkgmgr:
raise errors.CreatorError("Can't find backend: %s, "
- "available choices: %s" %
+ "available choices: %s" %
(creatoropts['pkgmgr'],
','.join(backends.keys())))