[Yum] [patch] updated version of /etc/yum.d usage patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In attachment you can find updated patch which help to maintain
yum configuration. It's prepared for current CVS (and daily build).

Features:
- Usage separate file for each repository (/etc/yum.d/)
- usefull tool to work with this files (yum-conf)
  - Easy on/off repositories (yum-conf off repository-name 
[repository-name...])
  - Easy to add new repository (yum-conf add url://with/repository/config)
  - Easy to list all repositories and it's state:
      #  yum-conf list
Name            Description                              State         
========================================================================
ASP1            ASPLinux Disk1                           On            
ASP2            ASPLinux Disk2                           On            
ASP3            ASPLinux Disk3                           On            
devel           ASPLinux Devel                           On            
local           ASPLinux Private                         Off          
mastersite      ASPLinux 9 Master Site                   Off
updates         ASPLinux 9 Updates                       On            


-- 
..............................................................
IRC: irc.freenode.net #asplinux                Grigory Bakunov
ICQ: 51369901                        ASPLinux Development Team
Life would be so much easier if
                        we could just look at the source code.

-------------- next part --------------
diff -urN yum-2.0.3cvs.old/bin/Makefile.in yum-2.0.3cvs/bin/Makefile.in
--- yum-2.0.3cvs.old/bin/Makefile.in	2003-09-27 23:28:29.000000000 +0400
+++ yum-2.0.3cvs/bin/Makefile.in	2003-09-30 18:55:25.000000000 +0400
@@ -32,20 +32,23 @@
 INSTALL_SCRIPT = @INSTALL_SCRIPT@
 
 
-all: $(srcdir)/yum-arch $(srcdir)/yum
+all: $(srcdir)/yum-arch $(srcdir)/yum $(srcdir)/yum-conf
 
 
 install: all installdirs
 	$(INSTALL_SCRIPT) -m 755 $(srcdir)/yum-arch $(DESTDIR)$(bindir)/yum-arch
+	$(INSTALL_SCRIPT) -m 755 $(srcdir)/yum-conf $(DESTDIR)$(bindir)/yum-conf
 	$(INSTALL_SCRIPT) -m 755 $(srcdir)/yum $(DESTDIR)$(bindir)/yum
 
 
 uninstall:
+	$(RM) $(bindir)/yum-conf
 	$(RM) $(bindir)/yum-arch
 	$(RM) $(bindir)/yum
 
 
 install-strip: all installdirs
+	$(INSTALL_SCRIPT) $(srcdir)/yum-conf $(bindir)/yum-conf
 	$(INSTALL_SCRIPT) $(srcdir)/yum-arch $(bindir)/yum-arch
 	$(INSTALL_SCRIPT) $(srcdir)/yum $(bindir)/yum
 
@@ -72,6 +75,7 @@
 	mkdir $(top_srcdir)/.disttmp/$$distdir/bin;\
 	cp \
 	$(srcdir)/yum-arch \
+	$(srcdir)/yum-conf \
 	$(srcdir)/yum \
 	$(srcdir)/Makefile.in \
 	$(top_srcdir)/.disttmp/$$distdir/bin
@@ -80,6 +84,7 @@
 	mkdir $(top_srcdir)/.disttmp/$$distdir/bin;\
 	cp \
 	$(srcdir)/yum-arch \
+	$(srcdir)/yum-conf \
 	$(srcdir)/yum \
 	$(srcdir)/Makefile.in \
 	$(top_srcdir)/.disttmp/$$distdir/bin
diff -urN yum-2.0.3cvs.old/bin/yum-conf yum-2.0.3cvs/bin/yum-conf
--- yum-2.0.3cvs.old/bin/yum-conf	1970-01-01 03:00:00.000000000 +0300
+++ yum-2.0.3cvs/bin/yum-conf	2003-09-30 18:52:15.000000000 +0400
@@ -0,0 +1,167 @@
+#!/usr/bin/python
+"""
+License: LGPL
+Authors: Grigory Bakunov
+Copyright 2003 Grigory Bakunov <black@xxxxxxxxxxx>
+
+$Id: TEMPLATE.py.tpl,v 1.1 2003/07/12 14:59:30 black Exp $
+"""
+# $RCSfile: TEMPLATE.py.tpl,v $
+__version__ = "$Revision: 1.1 $"[11:-2]
+__date__ = "$Date: 2003/07/12 14:59:30 $"[7:-2]
+
+import sys
+sys.path.insert(1,'/usr/share/yum')
+
+from urlparse import urlparse
+import locale
+import os
+import os.path
+import clientStuff
+import urllib
+from i18n import _
+
+def usage():
+    """ Show usage """
+    print _('''\
+Usage:
+    yum-conf list
+    yum-conf add URL
+    yum-conf [on|off|remove] NAME [NAME ...]
+
+    yum-conf help  - this screen
+
+    URL  - url to yum configfile
+    NAME - filename to store downloaded from URL config in /etc/yum.d
+''')
+    sys.exit(1)
+
+def cleanname(filename):
+    return os.path.basename(os.path.splitext(filename)[0])
+
+def getFileName(name):
+    fname   = os.path.join("/etc/yum.d/", name + ".yum")
+    fofname = os.path.join("/etc/yum.d/", name + ".off")
+    if os.path.exists(fname):
+        return fname
+    if os.path.exists(fofname):
+        return fofname
+    return None
+
+def isOn(filename):
+    if filename == None:
+        return None
+    if filename[-4:] == '.yum':
+        return 1
+    else:
+        return 0
+
+def switch(name):
+    fname = getFileName(name)
+    if fname == None:
+        return 0
+    if isOn(fname):
+        otherfname = os.path.join("/etc/yum.d", name + ".off")
+    else:
+        otherfname = os.path.join("/etc/yum.d", name + ".yum")
+    os.renames(fname, otherfname)
+    return 1
+
+def gethead(lines):
+    name = None
+    desc = None
+    for line in lines:
+        if line[0] == '[' and line[-2] == ']':
+            name = line[1:-2]
+        if line[0:5] == 'name=':
+            desc = line[5:-1]
+    return (name, desc)
+
+def getheadFromFile(filename):
+    f = open(filename, "r")
+    lines = f.readlines()
+    f.close()
+    return gethead(lines)
+        
+def main(args):
+    # Setting up locale
+    #locale.setlocale(locale.LC_ALL, '')
+
+    if len(args) < 1 or args[0] in ['help', '--help' , '-h']:
+        usage()
+
+    cmd = args.pop(0)
+    if not(cmd in ['on', 'off', 'remove', 'list', 'add']):
+        usage()
+
+    configdir = '/etc/yum.d/'
+    _cfgs_on  = clientStuff.getfilelist(configdir, '.yum', [])
+    _cfgs_off = clientStuff.getfilelist(configdir, '.off', [])
+
+    _cfgs = _cfgs_on + _cfgs_off;
+    if cmd == 'list':
+        format = "%-15s %-40s %-15s"
+        title = format % (_('Name'),_('Description'),_('State'));
+        print title
+        print '=' * len(title)
+        for name in _cfgs:
+            if name in _cfgs_on:
+                print format % (cleanname(name),
+                                getheadFromFile(name)[1],
+                                _("On"))
+            else:
+                print format % (cleanname(name),
+                                getheadFromFile(name)[1],
+                                _("Off"))
+
+    elif cmd == 'add':
+        url = args[0]
+        if urlparse(url)[0] is '':
+            print _('String "%s" is not valid URL') % url
+        else:
+            f = urllib.urlopen(url)
+            lines = f.readlines()
+            (name, desc) = gethead(lines)
+            if name != None:
+                fname    = os.path.join("/etc/yum.d", name + ".yum")
+                fofname = os.path.join("/etc/yum.d", name + ".off")
+                print fname, fofname
+                if os.path.exists(fname) or os.path.exists(fofname):
+                    print _('Repository "%s" already exist') % name
+                else:
+                    f = open(fname, "w")
+                    f.writelines(lines)
+                    f.close()
+                    print _('Repository "%s" added from %s') % (desc, url)
+    elif cmd == 'on':
+        for i in args:
+            if getFileName(i) == None:
+                print _('Repository "%s" doesn\'t exist') % i
+                continue
+            if not isOn(getFileName(i)):
+                switch(i)
+                print _('Repository "%s" switched on') % i
+            else:
+                print _('Repository "%s" already switched on') % i
+    elif cmd == 'off':
+        for i in args:
+            if getFileName(i) == None:
+                print _('Repository "%s" doesn\'t exist') % i
+                continue
+            if isOn(getFileName(i)):
+                switch(i)
+                print _('Repository "%s" switched off') % i
+            else:
+                print _('Repository "%s" already switched off') % i
+    elif cmd == 'remove':
+        for i in args:
+            if getFileName(i) == None:
+                print _('Repository "%s" doesn\'t exist') % i
+                continue
+            os.remove(getFileName(i))
+            print _('Repository "%s" was removed') % i
+    else:
+        usage()
+
+if __name__ == '__main__':
+    main(sys.argv[1:])
diff -urN yum-2.0.3cvs.old/config.py yum-2.0.3cvs/config.py
--- yum-2.0.3cvs.old/config.py	2003-09-27 23:28:29.000000000 +0400
+++ yum-2.0.3cvs/config.py	2003-09-30 18:53:42.000000000 +0400
@@ -27,28 +27,37 @@
 import archwork
 import rpmUtils
 import progress_meter
+import clientStuff
 
 from i18n import _
 
 
 class yumconf:
 
-    def __init__(self, configfile = '/etc/yum.conf'):
+    def __init__(self, configfile = '/etc/yum.conf', configdir = '/etc/yum.d/'):
         self.cfg = ConfigParser.ConfigParser()
         (s,b,p,q,f,o) = urlparse.urlparse(configfile)
-        if s in ('http', 'ftp','file'):
-            configfh = urllib.urlopen(configfile)
-            try:
-                self.cfg.readfp(configfh)
-            except ConfigParser.MissingSectionHeaderError, e:
-                print _('Error accessing URL: %s') % configfile
-                sys.exit(1)
+        if configdir:
+            conflist = clientStuff.getfilelist(configdir, '.yum', [])
         else:
-            if os.access(configfile, os.R_OK):
-                self.cfg.read(configfile)
+            conflist = []
+        conflist.append(configfile)
+        for conf in conflist:
+            (s,b,p,q,f,o) = urlparse.urlparse(conf)
+            if s in ('http', 'ftp','file'):
+                configfh = urllib.urlopen(conf)
+                try:
+                    self.cfg.readfp(configfh)
+                except ConfigParser.MissingSectionHeaderError, e:
+                    print _('Error accessing URL: %s') % conf
+                    sys.exit(1)
             else:
-                print _('Error accessing File: %s') % configfile
-                sys.exit(1)
+                if os.access(conf, os.R_OK):
+                    self.cfg.read(conf)
+                else:
+                    print _('Error accessing File: %s') % conf
+                    sys.exit(1)
+
         self.servers = []
         self.servername = {}
         self.serverurl = {}
diff -urN yum-2.0.3cvs.old/etc/devel.yum yum-2.0.3cvs/etc/devel.yum
--- yum-2.0.3cvs.old/etc/devel.yum	1970-01-01 03:00:00.000000000 +0300
+++ yum-2.0.3cvs/etc/devel.yum	2003-09-30 18:53:42.000000000 +0400
@@ -0,0 +1,5 @@
+[devel]
+name=ASPLinux Devel
+baseurl=http://download.asplinux.ru/contribs/9/
+# UA-IX only
+#baseurl=ftp://ftp.asp-linux.com.ua/pub/contribs/9/
diff -urN yum-2.0.3cvs.old/etc/Makefile.in yum-2.0.3cvs/etc/Makefile.in
--- yum-2.0.3cvs.old/etc/Makefile.in	2003-09-27 23:28:29.000000000 +0400
+++ yum-2.0.3cvs/etc/Makefile.in	2003-09-30 18:53:42.000000000 +0400
@@ -36,14 +36,16 @@
 
 
 install: all installdirs
-	mkdir -p $(DESTDIR)/etc/{cron.daily,init.d,logrotate.d}
+	mkdir -p $(DESTDIR)/etc/{cron.daily,init.d,logrotate.d,yum.d}
 	$(INSTALL_DATA) $(srcdir)/yum.conf $(DESTDIR)/etc/yum.conf
+	$(INSTALL_DATA) $(srcdir)/*.yum $(DESTDIR)/etc/yum.d/
 	$(INSTALL_SCRIPT) $(srcdir)/yum.cron $(DESTDIR)/etc/cron.daily/yum.cron
 	$(INSTALL_SCRIPT) $(srcdir)/yum.init $(DESTDIR)/etc/init.d/yum
 	$(INSTALL_DATA) $(srcdir)/yum.logrotate $(DESTDIR)/etc/logrotate.d/yum
 
 uninstall:
 	$(RM) /etc/yum.conf
+	$(RM) -f /etc/yum.d
 
 
 clean:
@@ -69,6 +71,9 @@
 	cp \
 	$(srcdir)/Makefile.in \
 	$(srcdir)/yum.conf \
+	$(srcdir)/updates.yum \
+	$(srcdir)/mastersite.yum \
+	$(srcdir)/devel.yum \
 	$(srcdir)/yum.cron \
 	$(srcdir)/yum.init \
 	$(srcdir)/yum.logrotate \
@@ -80,6 +85,9 @@
 	cp \
 	$(srcdir)/Makefile.in \
 	$(srcdir)/yum.conf \
+	$(srcdir)/updates.yum \
+	$(srcdir)/mastersite.yum \
+	$(srcdir)/devel.yum \
 	$(srcdir)/yum.cron \
 	$(srcdir)/yum.init \
 	$(srcdir)/yum.logrotate \
diff -urN yum-2.0.3cvs.old/etc/mastersite.yum yum-2.0.3cvs/etc/mastersite.yum
--- yum-2.0.3cvs.old/etc/mastersite.yum	1970-01-01 03:00:00.000000000 +0300
+++ yum-2.0.3cvs/etc/mastersite.yum	2003-09-30 18:53:42.000000000 +0400
@@ -0,0 +1,9 @@
+[mastersite]
+name=ASPLinux 9 Master Site
+baseurl=http://download.asplinux.ru/i386/RPMS.9/
+# Moscow2
+#baseurl=http://download2.asplinux.ru/install/ftp/i386/RPMS.9/
+# UA-IX only
+#baseurl=ftp://ftp.asp-linux.com.ua/pub/i386/RPMS.9/
+# Singapure
+#baseurl=http://ftp1.asplinux.com.sg/install/ftp/i386/RPMS.9/
diff -urN yum-2.0.3cvs.old/etc/updates.yum yum-2.0.3cvs/etc/updates.yum
--- yum-2.0.3cvs.old/etc/updates.yum	1970-01-01 03:00:00.000000000 +0300
+++ yum-2.0.3cvs/etc/updates.yum	2003-09-30 18:53:42.000000000 +0400
@@ -0,0 +1,9 @@
+[updates]
+name=ASPLinux 9 Updates
+baseurl=http://download.asplinux.ru/i386/updates/9/
+# Moscow2
+#baseurl=http://download2.asplinux.ru/install/ftp/i386/updates/9/
+# UA-IX only
+#baseurl=ftp://ftp.asp-linux.com.ua/pub/i386/updates/9/
+# Singapure
+#baseurl=http://ftp1.asplinux.com.sg/install/ftp/i386/updates/9/
diff -urN yum-2.0.3cvs.old/etc/yum.conf yum-2.0.3cvs/etc/yum.conf
--- yum-2.0.3cvs.old/etc/yum.conf	2003-09-27 23:28:29.000000000 +0400
+++ yum-2.0.3cvs/etc/yum.conf	2003-09-30 18:53:42.000000000 +0400
@@ -3,17 +3,6 @@
 debuglevel=2
 logfile=/var/log/yum.log
 pkgpolicy=newest
-distroverpkg=redhat-release
+distroverpkg=asplinux-release
 tolerant=1
 exactarch=1
-
-[base]
-name=Red Hat Linux $releasever - $basearch - Base
-baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/$releasever/$basearch/
-
-
-[updates]
-name=Red Hat Linux $releasever - Updates
-baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/updates/$releasever/
-
-
diff -urN yum-2.0.3cvs.old/yummain.py yum-2.0.3cvs/yummain.py
--- yum-2.0.3cvs.old/yummain.py	2003-09-27 23:28:29.000000000 +0400
+++ yum-2.0.3cvs/yummain.py	2003-09-30 18:53:42.000000000 +0400
@@ -44,9 +44,13 @@
     yumconffile=None
     if os.access("/etc/yum.conf", os.R_OK):
         yumconffile="/etc/yum.conf"
-        
+
+    yumconfdir=None
+    if os.access("/etc/yum.d/", os.R_OK):
+        yumconfdir="/etc/yum.d/"
+
     try:
-        gopts, cmds = getopt.getopt(args, 'tCc:hR:e:d:y', ['help', 'version', 'installroot='])
+        gopts, cmds = getopt.getopt(args, 'tCcr:hR:e:d:y', ['help', 'version', 'installroot='])
     except getopt.error, e:
         errorlog(0, _('Options Error: %s') % e)
         usage()
@@ -65,9 +69,11 @@
                 time.sleep(sleeptime)
             if o == '-c':
                 yumconffile=a
+            if o == '-r':
+                yumconfdir = a
 
         if yumconffile:
-            conf=yumconf(configfile=yumconffile)
+            conf=yumconf(configfile=yumconffile, configdir=yumconfdir)
         else:
             errorlog(0, _('Cannot find any conf file.'))
             sys.exit(1)

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux