From 69a6046bf8d31b6aeb15fe9680d7be669c98cfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 22 Jun 2017 16:32:35 +0200 Subject: [PATCH] multilib_yum: Remove main() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nothing is calling this file as an executable, so there is no reason to have logic for parsing arguments. Signed-off-by: Lubomír Sedlář --- pungi/multilib_yum.py | 115 ------------------------------------------ 1 file changed, 115 deletions(-) diff --git a/pungi/multilib_yum.py b/pungi/multilib_yum.py index 7156c229..993b9381 100755 --- a/pungi/multilib_yum.py +++ b/pungi/multilib_yum.py @@ -268,118 +268,3 @@ def po_is_multilib(po, methods): if method.select(po): return method_name return None - - -def do_multilib(yum_arch, methods, repos, tmpdir, logfile): - import os - import yum - import rpm - import logging - - archlist = yum.rpmUtils.arch.getArchList(yum_arch) - - yumbase = yum.YumBase() - yumbase.preconf.init_plugins = False - yumbase.preconf.root = tmpdir - # order matters! - # must run doConfigSetup() before touching yumbase.conf - yumbase.doConfigSetup(fn="/dev/null") - yumbase.conf.cache = False - yumbase.conf.cachedir = tmpdir - yumbase.conf.exactarch = True - yumbase.conf.gpgcheck = False - yumbase.conf.logfile = logfile - yumbase.conf.plugins = False - yumbase.conf.reposdir = [] - yumbase.verbose_logger.setLevel(logging.ERROR) - - yumbase.doRepoSetup() - yumbase.doTsSetup() - yumbase.doRpmDBSetup() - yumbase.ts.pushVSFlags((rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)) - - for repo in yumbase.repos.findRepos("*"): - repo.disable() - - for i, baseurl in enumerate(repos): - repo_id = "multilib-%s" % i - if "://" not in baseurl: - baseurl = "file://" + os.path.abspath(baseurl) - yumbase.add_enable_repo(repo_id, baseurls=[baseurl]) - - yumbase.doSackSetup(archlist=archlist) - yumbase.doSackFilelistPopulate() - - method_kwargs = {} - - result = [] - for po in sorted(yumbase.pkgSack): - method = po_is_multilib(po, methods) - if method: - nvra = "%s-%s-%s.%s.rpm" % (po.name, po.version, po.release, po.arch) - result.append((nvra, method)) - return result - - -def main(): - import optparse - import shutil - import tempfile - - class MyOptionParser(optparse.OptionParser): - def print_help(self, *args, **kwargs): - optparse.OptionParser.print_help(self, *args, **kwargs) - print - print "Available multilib methods:" - for key, value in sorted(METHOD_MAP.items()): - default = (key in DEFAULT_METHODS) and " (default)" or "" - print " %-10s %s%s" % (key, value.__doc__ or "", default) - - parser = MyOptionParser("usage: %prog [options]") - - parser.add_option( - "--arch", - ) - parser.add_option( - "--method", - action="append", - default=DEFAULT_METHODS, - help="multilib method", - ) - parser.add_option( - "--repo", - dest="repos", - action="append", - help="path or url to yum repo; can be specified multiple times", - ) - parser.add_option("--tmpdir") - parser.add_option("--logfile", action="store") - - opts, args = parser.parse_args() - - if args: - parser.error("no arguments expected") - - if not opts.repos: - parser.error("provide at least one repo") - - for method_name in opts.method: - if method_name not in METHOD_MAP: - parser.error("unknown method: %s" % method_name) - print opts.method - - tmpdir = opts.tmpdir - if not opts.tmpdir: - tmpdir = tempfile.mkdtemp(prefix="multilib_") - - init() - nvra_list = do_multilib(opts.arch, opts.method, opts.repos, tmpdir, opts.logfile) - for nvra, method in nvra_list: - print "MULTILIB(%s): %s" % (method, nvra) - - if not opts.tmpdir: - shutil.rmtree(tmpdir) - - -if __name__ == "__main__": - main()