def postoptparse(self): abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if self.options.verbose: msger.set_loglevel('VERBOSE') if self.options.debug: msger.set_loglevel('DEBUG') if self.options.logfile: logfile_abs_path = abspath(self.options.logfile) if os.path.isdir(logfile_abs_path): raise errors.Usage("logfile's path %s should be file" % self.options.logfile) configmgr.create['logfile'] = logfile_abs_path configmgr.set_logfile() if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = abspath(self.options.outdir) if self.options.cachedir is not None: configmgr.create['cachedir'] = abspath(self.options.cachedir) os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] for cdir in ('outdir', 'cachedir'): if os.path.exists(configmgr.create[cdir]) \ and not os.path.isdir(configmgr.create[cdir]): raise errors.Usage('Invalid directory specified: %s' \ % configmgr.create[cdir]) if not os.path.exists(configmgr.create[cdir]): os.makedirs(configmgr.create[cdir]) if os.getenv('SUDO_UID', '') and os.getenv('SUDO_GID', ''): os.chown(configmgr.create[cdir], int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID'))) if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): raise errors.Usage('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release.rstrip('/') if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'content', 'license', 'vcs'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license", "vcs"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.strict_mode: configmgr.create['strict_mode'] = self.options.strict_mode if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.set_runtime(self.options.runtime) if self.options.pack_to is not None: configmgr.create['pack_to'] = self.options.pack_to if self.options.copy_kernel: configmgr.create['copy_kernel'] = self.options.copy_kernel if self.options.install_pkgs: configmgr.create['install_pkgs'] = [] for pkgtype in self.options.install_pkgs.split(','): if pkgtype not in ('source', 'debuginfo', 'debugsource'): raise errors.Usage('Invalid parameter specified: "%s", ' 'valid values: source, debuginfo, ' 'debusource' % pkgtype) configmgr.create['install_pkgs'].append(pkgtype) if self.options.check_pkgs: for pkg in self.options.check_pkgs.split(','): configmgr.create['check_pkgs'].append(pkg) if self.options.enabletmpfs: configmgr.create['enabletmpfs'] = self.options.enabletmpfs if self.options.repourl: for item in self.options.repourl: try: key, val = item.split('=') except: continue configmgr.create['repourl'][key] = val if self.options.repo: for optvalue in self.options.repo: repo = {} for item in optvalue.split(';'): try: key, val = item.split('=') except: continue repo[key.strip()] = val.strip() if 'name' in repo: configmgr.create['extrarepos'][repo['name']] = repo if self.options.ignore_ksrepo: configmgr.create['ignore_ksrepo'] = self.options.ignore_ksrepo
def postoptparse(self): abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if self.options.verbose: msger.set_loglevel('verbose') if self.options.debug: msger.set_loglevel('debug') if self.options.logfile: logfile_abs_path = abspath(self.options.logfile) if os.path.isdir(logfile_abs_path): raise errors.Usage("logfile's path %s should be file" % self.options.logfile) if not os.path.exists(os.path.dirname(logfile_abs_path)): os.makedirs(os.path.dirname(logfile_abs_path)) msger.set_interactive(False) msger.set_logfile(logfile_abs_path) configmgr.create['logfile'] = self.options.logfile if self.options.config: configmgr.reset() configmgr._siteconf = self.options.config if self.options.outdir is not None: configmgr.create['outdir'] = abspath(self.options.outdir) if self.options.cachedir is not None: configmgr.create['cachedir'] = abspath(self.options.cachedir) os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] for cdir in ('outdir', 'cachedir'): if os.path.exists(configmgr.create[cdir]) \ and not os.path.isdir(configmgr.create[cdir]): msger.error('Invalid directory specified: %s' \ % configmgr.create[cdir]) if self.options.local_pkgs_path is not None: if not os.path.exists(self.options.local_pkgs_path): msger.error('Local pkgs directory: \'%s\' not exist' \ % self.options.local_pkgs_path) configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path if self.options.release: configmgr.create['release'] = self.options.release.rstrip('/') if self.options.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in self.options.record_pkgs.split(','): if infotype not in ('name', 'content', 'license', 'vcs'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license", "vcs"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: configmgr.create['arch'] = self.options.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s' % (self.options.arch, ', '.join(supported_arch))) if self.options.pkgmgr is not None: configmgr.create['pkgmgr'] = self.options.pkgmgr if self.options.runtime: configmgr.set_runtime(self.options.runtime) if self.options.pack_to is not None: configmgr.create['pack_to'] = self.options.pack_to if self.options.copy_kernel: configmgr.create['copy_kernel'] = self.options.copy_kernel if self.options.install_pkgs: configmgr.create['install_pkgs'] = [] for pkgtype in self.options.install_pkgs.split(','): if pkgtype not in ('source', 'debuginfo', 'debugsource'): raise errors.Usage('Invalid parameter specified: "%s", ' 'valid values: source, debuginfo, ' 'debusource' % pkgtype) configmgr.create['install_pkgs'].append(pkgtype) if self.options.enabletmpfs: configmgr.create['enabletmpfs'] = self.options.enabletmpfs if self.options.repourl: for item in self.options.repourl: try: key, val = item.split('=') except: continue configmgr.create['repourl'][key] = val
def main(parser, args, argv): """mic create entry point.""" #args is argparser namespace, argv is the input cmd line if args is None: raise errors.Usage("Invalid arguments") if not os.path.exists(args.ksfile): raise errors.CreatorError("Can't find the file: %s" % args.ksfile) if os.geteuid() != 0: msger.error("Root permission is required, abort") try: w = pwd.getpwuid(os.geteuid()) except KeyError: msger.warning("Might fail in compressing stage for undetermined user") abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if args.logfile: logfile_abs_path = abspath(args.logfile) if os.path.isdir(logfile_abs_path): raise errors.Usage("logfile's path %s should be file" % args.logfile) configmgr.create['logfile'] = logfile_abs_path configmgr.set_logfile() if args.subcommand == "auto": do_auto(parser, args.ksfile, argv) return if args.interactive: msger.enable_interactive() else: msger.disable_interactive() if args.verbose: msger.set_loglevel('VERBOSE') if args.debug: try: import rpm rpm.setVerbosity(rpm.RPMLOG_NOTICE) except ImportError: pass msger.set_loglevel('DEBUG') #check the imager type createrClass = None for subcmd, klass in pluginmgr.get_plugins('imager').iteritems(): if subcmd == args.subcommand and hasattr(klass, 'do_create'): createrClass = klass if createrClass is None: raise errors.CreatorError("Can't support subcommand %s" % args.subcommand) if args.config: configmgr.reset() configmgr._siteconf = args.config if args.outdir is not None: configmgr.create['outdir'] = abspath(args.outdir) if args.cachedir is not None: configmgr.create['cachedir'] = abspath(args.cachedir) os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir'] for cdir in ('outdir', 'cachedir'): if os.path.exists(configmgr.create[cdir]) \ and not os.path.isdir(configmgr.create[cdir]): raise errors.Usage('Invalid directory specified: %s' \ % configmgr.create[cdir]) if not os.path.exists(configmgr.create[cdir]): os.makedirs(configmgr.create[cdir]) if os.getenv('SUDO_UID', '') and os.getenv('SUDO_GID', ''): os.chown(configmgr.create[cdir], int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID'))) if args.local_pkgs_path is not None: if not os.path.exists(args.local_pkgs_path): raise errors.Usage('Local pkgs directory: \'%s\' not exist' \ % args.local_pkgs_path) configmgr.create['local_pkgs_path'] = args.local_pkgs_path if args.release: configmgr.create['release'] = args.release.rstrip('/') if args.record_pkgs: configmgr.create['record_pkgs'] = [] for infotype in args.record_pkgs.split(','): if infotype not in ('name', 'content', 'license', 'vcs'): raise errors.Usage('Invalid pkg recording: %s, valid ones:' ' "name", "content", "license", "vcs"' \ % infotype) configmgr.create['record_pkgs'].append(infotype) if args.strict_mode: configmgr.create['strict_mode'] = args.strict_mode if args.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if args.arch in supported_arch: configmgr.create['arch'] = args.arch else: raise errors.Usage('Invalid architecture: "%s".\n' ' Supported architectures are: \n' ' %s' % (args.arch, ', '.join(supported_arch))) if args.pkgmgr is not None: configmgr.create['pkgmgr'] = args.pkgmgr if args.runtime: configmgr.set_runtime(args.runtime) if args.pack_to is not None: configmgr.create['pack_to'] = args.pack_to if args.copy_kernel: configmgr.create['copy_kernel'] = args.copy_kernel if args.install_pkgs: configmgr.create['install_pkgs'] = [] for pkgtype in args.install_pkgs.split(','): if pkgtype not in ('source', 'debuginfo', 'debugsource'): raise errors.Usage('Invalid parameter specified: "%s", ' 'valid values: source, debuginfo, ' 'debusource' % pkgtype) configmgr.create['install_pkgs'].append(pkgtype) if args.check_pkgs: for pkg in args.check_pkgs.split(','): configmgr.create['check_pkgs'].append(pkg) if args.enabletmpfs: configmgr.create['enabletmpfs'] = args.enabletmpfs if args.repourl: for item in args.repourl: try: key, val = item.split('=') except: continue configmgr.create['repourl'][key] = val if args.repo: for optvalue in args.repo: repo = {} for item in optvalue.split(';'): try: key, val = item.split('=') except: continue repo[key.strip()] = val.strip() if 'name' in repo: configmgr.create['extrarepos'][repo['name']] = repo if args.ignore_ksrepo: configmgr.create['ignore_ksrepo'] = args.ignore_ksrepo if args.run_script: configmgr.create['run_script'] = args.run_script if args.tpk_install: configmgr.create['tpk_install'] = args.tpk_install creater = createrClass() creater.do_create(args)