summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/creator.py
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-03 22:26:06 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-05 09:22:17 +0000
commit71ce8d09e0f5912544936b0364990250c1381fed (patch)
treea26734dc16a71142d4a0130817e8e288ea9bfce1 /scripts/lib/wic/creator.py
parent3e052dd58c30a6e3e3af45c8369a693628a23eea (diff)
downloadpoky-71ce8d09e0f5912544936b0364990250c1381fed.tar.gz
wic: flatten imager class hierarchy
wic code is hard to follow due to deep and twiggy class inheritance tree. Flatten imager tree: wic -> wic_create -> Creator -> DirectPlugin -> DirectImageCreator to wic -> wic_create -> DirectPlugin by removing Creator class and creator module merging DirectImageCreator into DirectPlugin Changed APIs to use the same parameters names. Passed parsed command line options as an object down the stack. (From OE-Core rev: 1e28d512341ce470c7afb256a01e597ab87170ca) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/creator.py')
-rw-r--r--scripts/lib/wic/creator.py106
1 files changed, 0 insertions, 106 deletions
diff --git a/scripts/lib/wic/creator.py b/scripts/lib/wic/creator.py
deleted file mode 100644
index 74db83cd30..0000000000
--- a/scripts/lib/wic/creator.py
+++ /dev/null
@@ -1,106 +0,0 @@
1#!/usr/bin/env python -tt
2#
3# Copyright (c) 2011 Intel, Inc.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the Free
7# Software Foundation; version 2 of the License
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12# for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18import os, sys
19from optparse import OptionParser, SUPPRESS_HELP
20
21from wic import msger
22from wic.utils import errors
23from wic.plugin import pluginmgr
24
25class Creator():
26 """${name}: create an image
27
28 Usage:
29 ${name} SUBCOMMAND <ksfile> [OPTS]
30
31 ${command_list}
32 ${option_list}
33 """
34
35 name = 'wic create(cr)'
36
37 def __init__(self, *args, **kwargs):
38 self._subcmds = {}
39
40 # get cmds from pluginmgr
41 # mix-in do_subcmd interface
42 for subcmd, klass in pluginmgr.get_plugins('imager').items():
43 if not hasattr(klass, 'do_create'):
44 msger.warning("Unsupported subcmd: %s" % subcmd)
45 continue
46
47 func = getattr(klass, 'do_create')
48 self._subcmds[subcmd] = func
49
50 def get_optparser(self):
51 optparser = OptionParser()
52 optparser.add_option('-d', '--debug', action='store_true',
53 dest='debug',
54 help=SUPPRESS_HELP)
55 optparser.add_option('-v', '--verbose', action='store_true',
56 dest='verbose',
57 help=SUPPRESS_HELP)
58 optparser.add_option('', '--logfile', type='string', dest='logfile',
59 default=None,
60 help='Path of logfile')
61 optparser.add_option('-c', '--config', type='string', dest='config',
62 default=None,
63 help='Specify config file for wic')
64 optparser.add_option('-o', '--outdir', type='string', action='store',
65 dest='outdir', default=None,
66 help='Output directory')
67 optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs',
68 help='Setup tmpdir as tmpfs to accelerate, experimental'
69 ' feature, use it if you have more than 4G memory')
70 optparser.add_option('', '--bmap', action='store_true', help='generate .bmap')
71 return optparser
72
73 def postoptparse(self, options):
74 abspath = lambda pth: os.path.abspath(os.path.expanduser(pth))
75
76 if options.verbose:
77 msger.set_loglevel('verbose')
78 if options.debug:
79 msger.set_loglevel('debug')
80
81 if options.logfile:
82 logfile_abs_path = abspath(options.logfile)
83 if os.path.isdir(logfile_abs_path):
84 raise errors.Usage("logfile's path %s should be file"
85 % options.logfile)
86 if not os.path.exists(os.path.dirname(logfile_abs_path)):
87 os.makedirs(os.path.dirname(logfile_abs_path))
88 msger.set_interactive(False)
89 msger.set_logfile(logfile_abs_path)
90
91 def main(self, argv=None):
92 if argv is None:
93 argv = sys.argv
94 else:
95 argv = argv[:] # don't modify caller's list
96
97 pname = argv[0]
98 if pname not in self._subcmds:
99 msger.error('Unknown plugin: %s' % pname)
100
101 optparser = self.get_optparser()
102 options, args = optparser.parse_args(argv)
103
104 self.postoptparse(options)
105
106 return self._subcmds[pname](options, *args[1:])