[yum-cvs] yum/yum __init__.py, 1.141, 1.142 comps.py, 1.4, 1.5 groups.py, 1.8, NONE newcomps.py, 1.3, NONE
Seth Vidal
skvidal at login.linux.duke.edu
Fri Oct 28 04:20:22 UTC 2005
Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv22034
Modified Files:
__init__.py comps.py
Removed Files:
groups.py newcomps.py
Log Message:
removed groups.py, move newcomps.py to comps.py and remove old comps.py
Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -r1.141 -r1.142
--- __init__.py 25 Oct 2005 15:08:51 -0000 1.141
+++ __init__.py 28 Oct 2005 04:20:19 -0000 1.142
@@ -32,7 +32,7 @@
import rpmUtils
import rpmUtils.updates
import rpmUtils.arch
-import newcomps
+import comps
import config
import parser
import repos
@@ -1475,7 +1475,7 @@
return results
- def install(self, input):
+ def install(self, po=None, **kwargs):
"""try to mark for install the input
- input can be a pkg object or string"""
# convert 'input'
Index: comps.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/comps.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- comps.py 28 Mar 2005 15:52:04 -0000 1.4
+++ comps.py 28 Oct 2005 04:20:19 -0000 1.5
@@ -1,120 +1,128 @@
-#!/usr/bin/python
-# -*- mode: 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 2005 Duke University
-from cElementTree import iterparse
-import signal
-import getopt
import sys
+from constants import *
+from cElementTree import iterparse
import exceptions
-TRUE=1
-FALSE=0
-def parse_boolean(s):
- if s.lower() in ('yes', 'true'):
- return TRUE
- return FALSE
-
-def getattrib(elem, key, default=None):
- '''Retrieve an attribute named key from elem. Return default if not found.
-
- This is required because ElementTree includes namespace information in the
- name of each attribute.
- '''
- for k, v in elem.attrib.iteritems():
- k = k.split('}', 1)[-1]
- if k == key:
- return v
- return default
+lang_attr = '{http://www.w3.org/XML/1998/namespace}lang'
+def parse_boolean(strng):
+ if BOOLEAN_STATES.has_key(strng.lower()):
+ return BOOLEAN_STATES[strng.lower()]
+ else:
+ return False
+
class CompsException(exceptions.Exception):
pass
-
-class Group:
- def __init__(self, comps, elem=None):
- self.comps = comps
- self.user_visible = TRUE
- self.default = FALSE
- self.removable = FALSE
- self.name=""
+
+class Group(object):
+ def __init__(self, elem=None):
+ self.user_visible = True
+ self.default = False
+ self.selected = False
+ self.name = ""
self.description = ""
self.translated_name = {}
self.translated_description = {}
- self.packages = {}
- self.langonly = None
- self.groups = {}
- self.metapkgs = {}
- self.requires = []
- self.id = None
-
- # FIXME: this is a horrible, horrible hack. but we can't stick it
- # in with the package without making the tuple larger and that's
- # certain to break something and I don't have time to track them
- # all down. so we have to keep separate track of any "requirements"
- # the package has to have to be installed. this is *only* used right
- # now for some i18n packages. if it gets used for anything else, it
- # is guaranteed to break within anaconda. jlk - 12 aug 2002
- self.pkgConditionals = {}
+ self.mandatory_packages = {}
+ self.optional_packages = {}
+ self.default_packages = {}
+ self.langonly = None ## what the hell is this?
+ self.groupid = None
+ self.installed = False
+
if elem:
self.parse(elem)
+
+ def __str__(self):
+ return self.name
+
+ def _packageiter(self):
+ lst = self.mandatory_packages.keys() + \
+ self.optional_packages.keys() + \
+ self.default_packages.keys()
+
+ return lst
+
+ packages = property(_packageiter)
+
+ def nameByLang(self, lang):
+ if self.translated_name.has_key[lang]:
+ return self.translated_name[lang]
+ else:
+ return self.name
- def parse(self, elem):
+ def descriptionByLang(self, lang):
+ if self.translated_description.has_key[lang]:
+ return self.translated_description[lang]
+ else:
+ return self.description
+
+ def parse(self, elem):
for child in elem:
- if child.tag == 'name':
+
+ if child.tag == 'id':
+ id = child.text
+ if self.groupid is not None:
+ raise CompsException
+ self.groupid = id
+
+ elif child.tag == 'name':
text = child.text
if text:
text = text.encode('utf8')
- lang = getattrib(child, 'lang')
+
+ lang = child.attrib.get(lang_attr)
if lang:
self.translated_name[lang] = text
else:
self.name = text
-
- elif child.tag == 'id':
- id = child.text
- if self.id is not None:
- raise CompsException
- self.id = id
-
+
+
elif child.tag == 'description':
text = child.text
if text:
text = text.encode('utf8')
- lang = getattrib(child, 'lang')
+
+ lang = child.attrib.get(lang_attr)
if lang:
self.translated_description[lang] = text
else:
self.description = text
-
+
elif child.tag == 'uservisible':
self.user_visible = parse_boolean(child.text)
-
+
elif child.tag == 'default':
self.default = parse_boolean(child.text)
-
- elif child.tag == 'requires':
- # FIXME: this isn't in use anymore
- text = child.text
- if text in self.requires:
- raise CompsException
- self.requires.append(text)
-
- elif child.tag == 'langonly':
+
+ elif child.tag == 'langonly': ## FIXME - what the hell is langonly?
text = child.text
if self.langonly is not None:
raise CompsException
self.langonly = text
-
+
elif child.tag == 'packagelist':
self.parse_package_list(child)
-
- elif child.tag == 'grouplist':
- self.parse_group_list(child)
-
+
def parse_package_list(self, packagelist_elem):
-
for child in packagelist_elem:
if child.tag == 'packagereq':
type = child.attrib.get('type')
@@ -125,220 +133,210 @@
raise CompsException
package = child.text
- self.packages[package] = (type, package)
-
- # see note above about the hack this is.
- reqs = child.attrib.get('requires')
- if reqs:
- self.pkgConditionals[package] = reqs
-
- def parse_group_list(self, grouplist_elem):
-
- for child in grouplist_elem:
- if child.tag == 'groupreq':
- type = getattrib(child, 'type')
- if not type:
- type = u'mandatory'
-
- if type not in ('mandatory', 'default', 'optional'):
- raise CompsException
-
- group = child.text
- self.groups[group] = (type, group)
-
- elif child.tag == 'metapkg':
- type = getattrib(child, 'type')
- if not type:
- type = u'default'
- if type not in ('default', 'optional'):
- raise CompsException
- group = child.text
- self.metapkgs[group] = (type, group)
-
- def sanity_check(self):
- if not self.comps:
- raise CompsException
- if not self.name:
- raise CompsException
- for (type, package) in self.packages.values():
- try:
- self.comps.packages[package]
- except KeyError:
- pass
-# raise CompsException
-
-
-class Package:
- def __init__(self, comps, elem=None):
- self.comps = comps
- self.name = None
- self.version = None
- self.supported = FALSE
- self.excludearch = None
- self.dependencies = []
- self.installed = 0
- if elem:
- self.parse(elem)
-
- def sanity_check(self):
- if self.name == None:
- return FALSE
-
- def parse_dependency_list(self, packagedeps_elem):
- for child in packagedeps_elem:
- if child.tag == 'dependency':
- self.dependencies.append(child.text)
-
- def parse(self, group_elem):
- for child in group_elem:
- if child.tag == 'name':
- self.name = child.text
-
- elif child.tag == 'version':
- self.version = child.text
-
- elif child.tag == 'excludearch':
- self.excludearch = child.text
-
- elif child.tag == 'packagelist':
- self.parse_package_list(child)
+ if type == 'mandatory':
+ self.mandatory_packages[package] = 1
+ elif type == 'default':
+ self.default_packages[package] = 1
+ elif type == 'optional':
+ self.optional_packages[package] = 1
+
+ def add(self, obj):
+ """Add another group object to this object"""
+
+ # we only need package lists and any translation that we don't already
+ # have
+
+ for pkg in obj.mandatory_packages.keys():
+ self.mandatory_packages[pkg] = 1
+ for pkg in obj.default_packages.keys():
+ self.default_packages[pkg] = 1
+ for pkg in obj.optional_packages.keys():
+ self.optional_packages[pkg] = 1
+
+ # name and description translations
+ for lang in obj.translated_name.keys():
+ if not self.translated_name.has_key(lang):
+ self.translated_name[lang] = obj.translated_name[lang]
+
+ for lang in obj.translated_description.keys():
+ if not self.translated_description.has_key(lang):
+ self.translated_description[lang] = obj.translated_description[lang]
+
+
+
- elif child.tag == 'supported':
- self.supported = parse_boolean(child.text)
- elif child.tag == 'dependencylist':
- self.parse_dependency_list(child)
+class Category(object):
+ def __init__(self, elem=None):
+ self.name = ""
+ self.categoryid = None
+ self.description = ""
+ self.translated_name = {}
+ self.translated_description = {}
+ self._groups = {}
-class GroupHierarchy(dict):
- def __init__(self, comps, elem=None):
- self.comps = comps
- self.order = []
- self.translations = {}
if elem:
self.parse(elem)
-
+
+ def __str__(self):
+ return self.name
+
+ def _groupiter(self):
+ return self._groups.keys()
+
+ groups = property(_groupiter)
+
def parse(self, elem):
for child in elem:
- if child.tag == "category":
- self.parse_category(child)
- else:
- print "unhandled node in <comps.grouphierarchy>: " + child.tag
+ if child.tag == 'id':
+ id = child.text
+ if self.categoryid is not None:
+ raise CompsException
+ self.categoryid = id
- def parse_category(self, category_elem):
- translations = {}
- subs = []
- name = None
-
- for child in category_elem:
- if child.tag == "name":
+ elif child.tag == 'name':
text = child.text
if text:
text = text.encode('utf8')
- lang = getattrib(child, 'lang')
+
+ lang = child.attrib.get(lang_attr)
if lang:
- translations[lang] = text
+ self.translated_name[lang] = text
else:
- name = text
-
- elif child.tag == "subcategories":
- subs.extend(self.parse_subcategories(child))
-
- else:
- print "unhandled node in <comps.grouphierarchy.category>: " + \
- elem.tag
-
- if not name:
- raise CompsException, "no name specified"
-
- if not self.has_key(name):
- self.order.append(name)
- self[name] = subs
- else:
- self[name] = self[name].extend(subs)
- self.translations[name] = translations
-
- def parse_subcategories(self, category_elem):
- ret = []
- for child in category_elem:
- if child.tag == "subcategory":
- id = child.text
- if not id:
- raise CompsException
- ret.append(id)
- else:
- print "unhandled node in <comps.grouphierarchy.parse_category>:" + child.tag
+ self.name = text
+
+ elif child.tag == 'description':
+ text = child.text
+ if text:
+ text = text.encode('utf8')
+
+ lang = child.attrib.get(lang_attr)
+ if lang:
+ self.translated_description[lang] = text
+ else:
+ self.description = text
+
+ elif child.tag == 'grouplist':
+ self.parse_group_list(child)
- return ret
-
+ def parse_group_list(self, grouplist_elem):
+ for child in grouplist_elem:
+ if child.tag == 'groupid':
+ groupid = child.text
+ self._groups[groupid] = 1
+
+ def add(self, obj):
+ """Add another category object to this object"""
+
+ for grp in obj.groups:
+ self._groups[grp] = 1
+
+ # name and description translations
+ for lang in obj.translated_name.keys():
+ if not self.translated_name.has_key(lang):
+ self.translated_name[lang] = obj.translated_name[lang]
+ for lang in obj.translated_description.keys():
+ if not self.translated_description.has_key(lang):
+ self.translated_description[lang] = obj.translated_description[lang]
-class Comps(object):
- def __init__(self, srcfile=None):
+
+class Comps:
+ def __init__(self, overwrite_groups=False):
self.groups = {}
- self.packages = {}
- self.hierarchy = {}
-
- if srcfile != None:
- self.load(srcfile)
-
- def load(self, srcfile):
+ self.categories = {}
+ self.compscount = 0
+ self.overwrite_groups = overwrite_groups
+ self.compiled = False # have groups been compiled into avail/installed
+ # lists, yet.
+
+ def add(self, srcfile = None):
+ if not srcfile:
+ raise CompsException
+
if type(srcfile) == type('str'):
# srcfile is a filename string
infile = open(srcfile, 'rt')
else:
# srcfile is a file object
infile = srcfile
-
+
+ self.compscount += 1
+ self.compiled = False
+
parser = iterparse(infile)
for event, elem in parser:
if elem.tag == "group":
- group = Group(self, elem)
- self.groups[group.name] = group
-
- elif elem.tag == "package":
- package = Package(self, elem)
- self.packages[package.name] = package
-
- elif elem.tag == "grouphierarchy":
- self.hierarchy = GroupHierarchy(self, elem)
-
- if 0:
- for group in self.hierarchy.order:
- print group
- print self.hierarchy[group]
- if 0:
- for group in self.groups.values():
- print group.name
- for package in self.packages.values():
- print package.name
- print package.dependencies
- for group in self.groups.values():
- group.sanity_check()
- for package in self.packages.values():
- package.sanity_check()
+ group = Group(elem)
+ if self.groups.has_key(group.groupid):
+ thatgroup = self.groups[group.groupid]
+ thatgroup.add(group)
+ else:
+ self.groups[group.groupid] = group
+ if elem.tag == "category":
+ category = Category(elem)
+ if self.categories.has_key(category.categoryid):
+ thatcat = self.categories[category.categoryid]
+ thatcat.add(category)
+ else:
+ self.categories[category.categoryid] = category
+
+ del parser
+
+ def compile(self, pkgtuplist):
+ """ compile the groups into installed/available groups """
+
+ # convert the tuple list to a simple dict of pkgnames
+ inst_pkg_names = {}
+ for (n,a,e,v,r) in pkgtuplist:
+ inst_pkg_names[n] = 1
+
-usage = "usage: pkggroup.py compsfile.xml"
+ for group in self.groups.values():
+ # if it has any mandatory or default packages in the group, then
+ # make sure they're all installed, if any are missing then
+ # the group is not installed.
+ if len(group.mandatory_packages.keys()) > 0 or len(group.default_packages.keys()) > 0:
+ check_pkgs = group.mandatory_packages.keys() + group.default_packages.keys()
+ group.installed = True
+ for pkgname in check_pkgs:
+ if not inst_pkg_names.has_key(pkgname):
+ group.installed = False
+ # if it doesn't have any of those then see if it has ANY of the
+ # optional packages installed. If so - then the group is installed
+ else:
+ check_pkgs = group.optional_packages.keys()
+ group.installed = False
+ for pkgname in check_pkgs:
+ if inst_pkg_names.has_key(pkgname):
+ group.installed = True
+
+ self.compiled = True
def main():
- signal.signal(signal.SIGINT, signal.SIG_DFL)
- opts, args = getopt.getopt(sys.argv[1:], '',
- ['help'])
-
- for opt, arg in opts:
- if opt == '--help':
- print usage
- sys.exit(0)
- if len(args) != 1:
- print >> sys.stderr, usage
- sys.exit(1)
try:
- p = Comps(args[0])
-
+ print sys.argv[1]
+ p = Comps()
+ for srcfile in sys.argv[1:]:
+ p.add(srcfile)
+
+ for group in p.groups.values():
+ print group
+ for pkg in group.packages:
+ print ' ' + pkg
+
+ for category in p.categories.values():
+ print category.name
+ for group in category.groups:
+ print ' ' + group
+
except IOError:
- print >> sys.stderr, "pkggroup.py: No such file:\'%s\'" % args[0]
+ print >> sys.stderr, "newcomps.py: No such file:\'%s\'" % sys.argv[1]
sys.exit(1)
+
if __name__ == '__main__':
main()
+
--- groups.py DELETED ---
--- newcomps.py DELETED ---
More information about the Yum-cvs-commits
mailing list