[yum-commits] Makefile yum-config-manager.py yum-show-config.py yum-utils.spec

James Antill james at osuosl.org
Fri May 21 17:29:39 UTC 2010


 Makefile              |    2 -
 yum-config-manager.py |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 yum-show-config.py    |   36 ------------------
 yum-utils.spec        |    6 +--
 4 files changed, 99 insertions(+), 40 deletions(-)

New commits:
commit 02c53b058dad485d95fc3669efcfb0c040e1c045
Author: James Antill <james at and.org>
Date:   Fri May 21 13:22:47 2010 -0400

    Change show-config to config-manager, let people set stuff too.

diff --git a/Makefile b/Makefile
index 5019520..79d1e5e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 SUBDIRS = docs
 PKGNAME = yum-utils
-UTILS = package-cleanup debuginfo-install repoclosure repomanage repoquery repo-graph repo-rss yumdownloader yum-builddep repotrack reposync repodiff yum-debug-dump yum-debug-restore verifytree yum-groups-manager find-repos-of-install needs-restarting yum-show-config
+UTILS = package-cleanup debuginfo-install repoclosure repomanage repoquery repo-graph repo-rss yumdownloader yum-builddep repotrack reposync repodiff yum-debug-dump yum-debug-restore verifytree yum-groups-manager find-repos-of-install needs-restarting yum-config-manager
 UTILSROOT = yum-complete-transaction yumdb
 VERSION=$(shell awk '/Version:/ { print $$2 }' ${PKGNAME}.spec)
 RELEASE=$(shell awk -F%: '/Release:/ { print $$2 }' ${PKGNAME}.spec ')
diff --git a/yum-config-manager.py b/yum-config-manager.py
new file mode 100755
index 0000000..4c67477
--- /dev/null
+++ b/yum-config-manager.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python -tt
+
+import os, os.path
+import sys
+import yum
+sys.path.insert(0,'/usr/share/yum-cli')
+from utils import YumUtilBase
+import logging
+
+from iniparse import INIConfig
+
+def writeRawConfigFile(filename, sectionname, cfgoptions, items, optionobj,
+                       only=None):
+    """
+    From writeRawRepoFile, but so we can alter [main] too.
+    """
+    ini = INIConfig(open(filename))
+    # Updated the ConfigParser with the changed values
+    cfgOptions = cfgoptions(sectionname)
+    for name,value in items():
+        if value is None: # Proxy
+            continue
+        option = optionobj(name)
+        if option.default != value or name in cfgOptions :
+            if only is None or name in only:
+                ini[sectionname][name] = option.tostring(value)
+    fp =file(filename, "w")
+    fp.write(str(ini))
+    fp.close()
+
+NAME = 'yum-config-manager'
+VERSION = '1.0'
+USAGE = '"yum-config-manager [options] [section]'
+
+yb = YumUtilBase(NAME, VERSION, USAGE)
+logger = logging.getLogger("yum.verbose.cli.yum-config-manager")
+yb.preconf.debuglevel = 0
+yb.preconf.errorlevel = 0
+yb.optparser = yb.getOptionParser()
+if hasattr(yb, 'getOptionGroup'): # check if the group option API is available
+    group = yb.getOptionGroup()
+else:
+    group = yb.optparser
+group.add_option("--save", default=False, action="store_true",
+          help='save the current options (useful with --setopt)')
+group.add_option("--enable", default=False, action="store_true",
+          help='enable the specified repos (automatically saves)')
+group.add_option("--disable", default=False, action="store_true",
+          help='disable the specified repos (automatically saves)')
+
+try:
+    opts = yb.doUtilConfigSetup()
+except yum.Errors.RepoError, e:
+    logger.error(str(e))
+    sys.exit(50)
+
+args = set(yb.cmds)
+
+if opts.enable and opts.disable:
+    logger.error("Error: Trying to enable and disable repos.")
+    opts.enable = opts.disable = False
+if opts.enable and not args:
+    logger.error("Error: Trying to enable already enabled repos.")
+    opts.enable = False
+
+if not args or 'main' in args:
+    print yb.fmtSection('main')
+    print yb.conf.dump()
+    if opts.save:
+        fn = '/etc/yum/yum.conf'
+        if not os.path.exists(fn):
+            # Try the old default
+            fn = '/etc/yum.conf'
+        ybc = yb.conf
+        writeRawConfigFile(fn, 'main',
+                           ybc.cfg.options, ybc.iteritems, ybc.optionobj)
+
+if opts.enable or opts.disable:
+    opts.save = True
+
+if args:
+    repos = yb.repos.findRepos(','.join(args))
+else:
+    repos = yb.repos.listEnabled()
+
+for repo in sorted(repos):
+    print yb.fmtSection('repo: ' + repo.id)
+    if opts.enable:
+        repo.enable()
+    elif opts.disable:
+        repo.disable()
+    print repo.dump()
+    if opts.save:
+        writeRawConfigFile(repo.repofile, repo.id,
+                           repo.cfg.options, repo.iteritems, repo.optionobj)
diff --git a/yum-show-config.py b/yum-show-config.py
deleted file mode 100755
index 7d16016..0000000
--- a/yum-show-config.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/python -tt
-
-import sys
-import yum
-sys.path.insert(0,'/usr/share/yum-cli')
-from utils import YumUtilBase
-import logging
-
-NAME = 'yum-show-config'
-VERSION = '1.0'
-USAGE = '"yum-show-config [options] [section]'
-
-yb = YumUtilBase(NAME, VERSION, USAGE)
-logger = logging.getLogger("yum.verbose.cli.yum-show-config")
-yb.preconf.debuglevel = 0
-yb.preconf.errorlevel = 0
-yb.optparser = yb.getOptionParser()
-try:
-    opts = yb.doUtilConfigSetup()
-except yum.Errors.RepoError, e:
-    logger.error(str(e))
-    sys.exit(50)
-
-args = set(sys.argv[1:])
-def _test_arg(x):
-    return not args or x in args
-        
-if _test_arg('main'):
-    print yb.fmtSection('main')
-    print yb.conf.dump()
-
-for repo in sorted(yb.repos.listEnabled()):
-    if not _test_arg(repo.id):
-        continue
-    print yb.fmtSection('repo: ' + repo.id)
-    print repo.dump()
diff --git a/yum-utils.spec b/yum-utils.spec
index e111fa6..b891ba8 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -17,8 +17,8 @@ manager. It includes utilities by different authors that make yum easier and
 more powerful to use. These tools include: debuginfo-install, 
 find-repos-of-install, needs-restarting, package-cleanup, repoclosure, 
 repodiff, repo-graph, repomanage, repoquery, repo-rss, reposync,
-repotrack, verifytree, yum-builddep, yum-complete-transaction, yumdownloader,
-yum-debug-dump, yum-debug-restore, yum-groups-manager and yum-show-config.
+repotrack, verifytree, yumdownloader, yum-builddep, yum-complete-transaction, 
+yum-config-manager, yum-debug-dump, yum-debug-restore and yum-groups-manager.
 
 %package -n yum-updateonboot
 Summary: Run yum update on system boot
@@ -432,10 +432,10 @@ fi
 %{_bindir}/verifytree
 %{_bindir}/yumdownloader
 %{_bindir}/yum-builddep
+%{_bindir}/yum-config-manager
 %{_bindir}/yum-debug-dump
 %{_bindir}/yum-groups-manager
 %{_bindir}/yum-debug-restore
-%{_bindir}/yum-show-config
 %{_sbindir}/yum-complete-transaction
 %{_sbindir}/yumdb
 %{_mandir}/man1/yum-utils.1.*


More information about the Yum-commits mailing list