2007/7/24, Matthew Miller <[EMAIL PROTECTED]>:

On Tue, Jul 24, 2007 at 08:57:34PM +0200, Adel Gadllah wrote:
>       for userpkg in cmd:
>               for skippkg in blacklist:
>                       if userpkg == skippkg:
>                               skip = 1
>               if not re.search(regex, userpkg) and not skip:
>                       exclude.append(userpkg)
>               skip = 0

How about:

        for userpkg in cmd:
            if not userpkg in blacklist and not re.search(regex, userpkg):
                exclude.append(userpkg)

I'm not a python efficiency expert -- there's other structures that are
probably even better. And this same principle can be applied to your other
nested for-loop.


ok thx for the suggestion, removed 2 nested loops

Also, naming the variable "regex" isn't very readable -- it's clearly a
regex given that you're passing it to re.search. And speaking of naming --
isn't your blacklist really a _whitelist_ -- a list of packages _not_ to
block?


thinking about it.... seems you are correct ;)
did a s/regex/excludearch/ and a s/blacklist/whilelist/

new files attached.
#!/usr/bin/python

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Copyright 2007 by Adel Gadllah

import re, os
from yum.plugins import TYPE_CORE

requires_api_version = '2.3'
plugin_type = TYPE_CORE


def exclude_hook(conduit):


	""" Only install i386 packages when told to do so """
	if os.uname()[-1] == 'x86_64':
		basearch(conduit, "x86","i?86$")
	
	""" Only install ppc64 packages when told to do so """	
	if os.uname()[-1] == 'ppc64':
		basearch(conduit, "ppc","ppc64$")

	""" Only install sparc64 packages when told to do so """	
	if os.uname()[-1] == 'sparc64':
		basearch(conduit, "sparc","sparc64$")


def basearch(conduit, barch, excludearch):
	
	exclude = []
	whitelist = []
	skip = 0
	conf , cmd = conduit.getCmdLine()
	packageList = conduit.getPackages()
	
	if cmd[0] != "install":
		return

	""" get whitelist from config file """	
	
	conflist = conduit.confString(barch, 'whitelist')
	if conflist:
		tmp = conflist.split(",")
		for confitem in tmp:
			whitelist.append(confitem.strip())
	
	""" decide which packages we want to exclude """	

	for userpkg in cmd:
           if not userpkg in whitelist and not re.search(excludearch, userpkg):
               exclude.append(userpkg)

	""" exclude the packages """	
	
	for pkg in packageList:
		if pkg.name in exclude and re.search(excludearch, pkg.arch):
			conduit.delPackage(pkg)
			conduit.info(3, "--> excluded %s.%s" % (pkg.name, pkg.arch))	

Attachment: basearchonly.conf
Description: Binary data

_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to