summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/mic/creator.py176
1 files changed, 6 insertions, 170 deletions
diff --git a/scripts/lib/mic/creator.py b/scripts/lib/mic/creator.py
index 267928f877..7c9ca6f9dc 100644
--- a/scripts/lib/mic/creator.py
+++ b/scripts/lib/mic/creator.py
@@ -44,7 +44,7 @@ class Creator(cmdln.Cmdln):
44 # mix-in do_subcmd interface 44 # mix-in do_subcmd interface
45 for subcmd, klass in pluginmgr.get_plugins('imager').iteritems(): 45 for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
46 if not hasattr(klass, 'do_create'): 46 if not hasattr(klass, 'do_create'):
47 msger.warning("Unsurpport subcmd: %s" % subcmd) 47 msger.warning("Unsupported subcmd: %s" % subcmd)
48 continue 48 continue
49 49
50 func = getattr(klass, 'do_create') 50 func = getattr(klass, 'do_create')
@@ -65,59 +65,12 @@ class Creator(cmdln.Cmdln):
65 optparser.add_option('-c', '--config', type='string', dest='config', 65 optparser.add_option('-c', '--config', type='string', dest='config',
66 default=None, 66 default=None,
67 help='Specify config file for mic') 67 help='Specify config file for mic')
68 optparser.add_option('-k', '--cachedir', type='string', action='store',
69 dest='cachedir', default=None,
70 help='Cache directory to store the downloaded')
71 optparser.add_option('-o', '--outdir', type='string', action='store', 68 optparser.add_option('-o', '--outdir', type='string', action='store',
72 dest='outdir', default=None, 69 dest='outdir', default=None,
73 help='Output directory') 70 help='Output directory')
74 optparser.add_option('-A', '--arch', type='string', dest='arch',
75 default=None,
76 help='Specify repo architecture')
77 optparser.add_option('', '--release', type='string', dest='release',
78 default=None, metavar='RID',
79 help='Generate a release of RID with all necessary'
80 ' files, when @BUILD_ID@ is contained in '
81 'kickstart file, it will be replaced by RID')
82 optparser.add_option("", "--record-pkgs", type="string",
83 dest="record_pkgs", default=None,
84 help='Record the info of installed packages, '
85 'multiple values can be specified which '
86 'joined by ",", valid values: "name", '
87 '"content", "license", "vcs"')
88 optparser.add_option('', '--pkgmgr', type='string', dest='pkgmgr',
89 default=None,
90 help='Specify backend package manager')
91 optparser.add_option('', '--local-pkgs-path', type='string',
92 dest='local_pkgs_path', default=None,
93 help='Path for local pkgs(rpms) to be installed')
94 optparser.add_option('', '--runtime', type='string',
95 dest='runtime', default=None,
96 help='Specify runtime mode, avaiable: bootstrap, native')
97 # --taring-to is alias to --pack-to
98 optparser.add_option('', '--taring-to', type='string',
99 dest='pack_to', default=None,
100 help=SUPPRESS_HELP)
101 optparser.add_option('', '--pack-to', type='string',
102 dest='pack_to', default=None,
103 help='Pack the images together into the specified'
104 ' achive, extension supported: .zip, .tar, '
105 '.tar.gz, .tar.bz2, etc. by default, .tar '
106 'will be used')
107 optparser.add_option('', '--copy-kernel', action='store_true',
108 dest='copy_kernel',
109 help='Copy kernel files from image /boot directory'
110 ' to the image output directory.')
111 optparser.add_option('', '--install-pkgs', type='string', action='store',
112 dest='install_pkgs', default=None,
113 help='Specify what type of packages to be installed,'
114 ' valid: source, debuginfo, debugsource')
115 optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs', 71 optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs',
116 help='Setup tmpdir as tmpfs to accelerate, experimental' 72 help='Setup tmpdir as tmpfs to accelerate, experimental'
117 ' feature, use it if you have more than 4G memory') 73 ' feature, use it if you have more than 4G memory')
118 optparser.add_option('', '--repourl', action='append',
119 dest='repourl', default=[],
120 help=SUPPRESS_HELP)
121 return optparser 74 return optparser
122 75
123 def preoptparse(self, argv): 76 def preoptparse(self, argv):
@@ -183,78 +136,16 @@ class Creator(cmdln.Cmdln):
183 136
184 if self.options.outdir is not None: 137 if self.options.outdir is not None:
185 configmgr.create['outdir'] = abspath(self.options.outdir) 138 configmgr.create['outdir'] = abspath(self.options.outdir)
186 if self.options.cachedir is not None:
187 configmgr.create['cachedir'] = abspath(self.options.cachedir)
188 os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']
189
190 for cdir in ('outdir', 'cachedir'):
191 if os.path.exists(configmgr.create[cdir]) \
192 and not os.path.isdir(configmgr.create[cdir]):
193 msger.error('Invalid directory specified: %s' \
194 % configmgr.create[cdir])
195
196 if self.options.local_pkgs_path is not None:
197 if not os.path.exists(self.options.local_pkgs_path):
198 msger.error('Local pkgs directory: \'%s\' not exist' \
199 % self.options.local_pkgs_path)
200 configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path
201
202 if self.options.release:
203 configmgr.create['release'] = self.options.release.rstrip('/')
204
205 if self.options.record_pkgs:
206 configmgr.create['record_pkgs'] = []
207 for infotype in self.options.record_pkgs.split(','):
208 if infotype not in ('name', 'content', 'license', 'vcs'):
209 raise errors.Usage('Invalid pkg recording: %s, valid ones:'
210 ' "name", "content", "license", "vcs"' \
211 % infotype)
212
213 configmgr.create['record_pkgs'].append(infotype)
214
215 if self.options.arch is not None:
216 supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
217 if self.options.arch in supported_arch:
218 configmgr.create['arch'] = self.options.arch
219 else:
220 raise errors.Usage('Invalid architecture: "%s".\n'
221 ' Supported architectures are: \n'
222 ' %s' % (self.options.arch,
223 ', '.join(supported_arch)))
224
225 if self.options.pkgmgr is not None:
226 configmgr.create['pkgmgr'] = self.options.pkgmgr
227 139
228 if self.options.runtime: 140 cdir = 'outdir'
229 configmgr.set_runtime(self.options.runtime) 141 if os.path.exists(configmgr.create[cdir]) \
230 142 and not os.path.isdir(configmgr.create[cdir]):
231 if self.options.pack_to is not None: 143 msger.error('Invalid directory specified: %s' \
232 configmgr.create['pack_to'] = self.options.pack_to 144 % configmgr.create[cdir])
233
234 if self.options.copy_kernel:
235 configmgr.create['copy_kernel'] = self.options.copy_kernel
236
237 if self.options.install_pkgs:
238 configmgr.create['install_pkgs'] = []
239 for pkgtype in self.options.install_pkgs.split(','):
240 if pkgtype not in ('source', 'debuginfo', 'debugsource'):
241 raise errors.Usage('Invalid parameter specified: "%s", '
242 'valid values: source, debuginfo, '
243 'debusource' % pkgtype)
244
245 configmgr.create['install_pkgs'].append(pkgtype)
246 145
247 if self.options.enabletmpfs: 146 if self.options.enabletmpfs:
248 configmgr.create['enabletmpfs'] = self.options.enabletmpfs 147 configmgr.create['enabletmpfs'] = self.options.enabletmpfs
249 148
250 if self.options.repourl:
251 for item in self.options.repourl:
252 try:
253 key, val = item.split('=')
254 except:
255 continue
256 configmgr.create['repourl'][key] = val
257
258 def main(self, argv=None): 149 def main(self, argv=None):
259 if argv is None: 150 if argv is None:
260 argv = sys.argv 151 argv = sys.argv
@@ -294,58 +185,3 @@ class Creator(cmdln.Cmdln):
294 return ['help', argv[0]] 185 return ['help', argv[0]]
295 186
296 return argv 187 return argv
297
298 def do_auto(self, subcmd, opts, *args):
299 """${cmd_name}: auto detect image type from magic header
300
301 Usage:
302 ${name} ${cmd_name} <ksfile>
303
304 ${cmd_option_list}
305 """
306 def parse_magic_line(re_str, pstr, ptype='mic'):
307 ptn = re.compile(re_str)
308 m = ptn.match(pstr)
309 if not m or not m.groups():
310 return None
311
312 inline_argv = m.group(1).strip()
313 if ptype == 'mic':
314 m2 = re.search('(?P<format>\w+)', inline_argv)
315 elif ptype == 'mic2':
316 m2 = re.search('(-f|--format(=)?)\s*(?P<format>\w+)',
317 inline_argv)
318 else:
319 return None
320
321 if m2:
322 cmdname = m2.group('format')
323 inline_argv = inline_argv.replace(m2.group(0), '')
324 return (cmdname, inline_argv)
325
326 return None
327
328 if len(args) != 1:
329 raise errors.Usage("Extra arguments given")
330
331 if not os.path.exists(args[0]):
332 raise errors.CreatorError("Can't find the file: %s" % args[0])
333
334 with open(args[0], 'r') as rf:
335 first_line = rf.readline()
336
337 mic_re = '^#\s*-\*-mic-options-\*-\s+(.*)\s+-\*-mic-options-\*-'
338 mic2_re = '^#\s*-\*-mic2-options-\*-\s+(.*)\s+-\*-mic2-options-\*-'
339
340 result = parse_magic_line(mic_re, first_line, 'mic') \
341 or parse_magic_line(mic2_re, first_line, 'mic2')
342 if not result:
343 raise errors.KsError("Invalid magic line in file: %s" % args[0])
344
345 if result[0] not in self._subcmds:
346 raise errors.KsError("Unsupport format '%s' in %s"
347 % (result[0], args[0]))
348
349 argv = ' '.join(result + args).split()
350 self.main(argv)
351