From 40602488897fcf16f2eedad18eb33149c3b2341d Mon Sep 17 00:00:00 2001 From: Izhar Firdaus Date: Mon, 23 Jun 2008 23:40:53 +0800 Subject: - code cleanup in parser - added type filter in getRepoURL --- chitin/__init__.pyo | Bin 178 -> 0 bytes chitin/parser.py | 11 ++- setup.py | 2 +- yum-plugin/chitin.py | 175 --------------------------------------------- yum-plugin/chitinplugin.py | 175 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+), 179 deletions(-) delete mode 100644 chitin/__init__.pyo delete mode 100644 yum-plugin/chitin.py create mode 100644 yum-plugin/chitinplugin.py diff --git a/chitin/__init__.pyo b/chitin/__init__.pyo deleted file mode 100644 index 2f4bca1..0000000 Binary files a/chitin/__init__.pyo and /dev/null differ diff --git a/chitin/parser.py b/chitin/parser.py index 006d3a5..0a17979 100644 --- a/chitin/parser.py +++ b/chitin/parser.py @@ -21,7 +21,7 @@ # @author Izhar Firdaus from xml.etree.ElementTree import ElementTree,Element -import re, tempfile +import re from chitin.utils import attrsfilter,get_child_value ocins='http://opensuse.org/Standards/One_Click_Install' @@ -72,7 +72,7 @@ class Metapackage: products = self.getGroup().getiterator('{%s}%s' % (ocins,'product')) return attrsfilter(products,kwargs) - def getRepoURL(self,reponame): + def getRepoURL(self,reponame,type=None): """ Function to get 'url' values from current distversion group, and requested reponame @@ -83,11 +83,16 @@ class Metapackage: repos = self.getRepositories() urls = [] for r in repos: - if get_child_value(r,'name') == reponame: + if get_child_value(r,'name').lower() == reponame.lower(): for url in r.getiterator('{%s}%s' % (ocins,'url')): priority = 0 + if type: + if not url.attrib.has_key('type'): continue + if not url.attrib['type'].lower() == type.lower(): continue + if url.attrib.has_key('score'): priority = int(url.attrib['score']) urls.append((url.text.strip(),priority)) + def sorturl(x,y): if x[1] <= y[1]: return +1 diff --git a/setup.py b/setup.py index 1e98c7c..e418851 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ version = '0.0.1' setup(name='chitin', version=version, - description="OpenSuSE One Click Install metadata parsing library for python", + description="One Click Install metadata parsing library in python", long_description="""\ """, classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers diff --git a/yum-plugin/chitin.py b/yum-plugin/chitin.py deleted file mode 100644 index 61037c5..0000000 --- a/yum-plugin/chitin.py +++ /dev/null @@ -1,175 +0,0 @@ -#!/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 Red Hat Inc. 2007, 2008 -# -# Author: Izhar Firdaus -# Examples: -# -# yum chitin-install oneclickinstall-XML-metadata-file -# yum chitin-query details oneclickinstall-XML-metadata-file -# yum chitin-query repositories oneclickinstall-XML-metadata-file -# yum chitin-query packages oneclickinstall-XML-metadata-file -# - -import re -from chitin.parser import Metapackage -from chitin.utils import get_child_value,get_element_tag -from yum.plugins import PluginYumExit,TYPE_CORE,TYPE_INTERACTIVE -from yum import logginglevels -import yum.i18n, tempfile -_ = yum.i18n._ - -requires_api_version = '2.5' -plugin_type = (TYPE_INTERACTIVE,) - -## Use this for now -distro='openSUSE' -release='Factory' - - -def add_tmp_repo(base,name,repourls): - """ - Function to add temporary repository - - @param base The YumBase object for the operation - @param name The repository name - @param repourls A list of urls for the repository - - @return None - """ - tfo = tempfile.NamedTemporaryFile() - repoid = name - repoconfig = """ -[%s] -name=%s -failovermethod=priority -baseurl=%s -enabled=1 -""" % (name,name,'\n'.join(repourls)) - tfo.file.write(repoconfig) - tfo.file.close() - base.getReposFromConfigFile(tfo.name) - -class Query: - def __init__(self,distro,release): - self.distro = distro - self.release = release - - def getNames(self): - return ['chitin-query'] - - def getUsage(self): - return "[details|repositories|packages] [ file]" - - def getSummary(self): - return "Query data from OneClickInstall metadata" - - def doCheck(self, base, basecmd, extcmds): - pass - - def getRepos(self): # so we can act as a "conduit" - return self.repos - - def show_pkg(self, msg, pkg, md, disp=None): - print msg, pkg, md - - def show_pkg_exit(self): - pass - - def doCommand(self, base, basecmd, extcmds): - action = extcmds[0] - param = extcmds[1:] - metapackages = [] - for mp in param: - metapackages.append(Metapackage(mp,'%s %s' % (self.distro,self.release))) - - if action == 'details': - for chitin in metapackages: - print '=======================' - print 'Metadata' - print '=======================' - for c in chitin.getGroup().getchildren(): - tagname = get_element_tag(c) - if tagname in ['name','summary','description']: - print tagname,':',c.text - if action == 'repositories': - for chitin in metapackages: - print '========================' - print 'Repositories' - print '========================' - for r in chitin.getRepositories(): - print get_child_value(r,'name') - print chitin.getRepoURL(get_child_value(r,'name')) - if action == 'packages': - for chitin in metapackages: - print '========================' - print 'Packages' - print '========================' - for p in chitin.getProducts(): - print p.getchildren()[0].text - print '' - return 0, [''] - -class Install: - def __init__(self,distro,release): - self.distro = distro - self.release = release - - def getNames(self): - return ['chitin-install'] - - def getUsage(self): - return "[ file]" - - def getSummary(self): - return "Install packages from OneClickInstall metadata" - - def doCheck(self, base, basecmd, extcmds): - pass - - def getRepos(self): # so we can act as a "conduit" - return self.repos - - def show_pkg(self, msg, pkg, md, disp=None): - print msg, pkg, md - - def show_pkg_exit(self): - pass - - def doCommand(self, base, basecmd, extcmds): - packages = [] - repositories = [] - for mp in extcmds: - chitin = Metapackage(mp,'%s %s' % (self.distro,self.release)) - for p in chitin.getProducts(): - packages.append(get_child_value(p,'name')) - for r in chitin.getRepositories(): - repositories.append((get_child_value(r,'name'),chitin.getRepoURL(get_child_value(r,'name')))) - print packages - print repositories - - base.verbose_logger.log(logginglevels.INFO_2, - _("Setting up Install Process")) - try: - return base.installPkgs(packages) - except yum.Errors.YumBaseError, e: - return 1, [str(e)] - -def config_hook(conduit): - conduit.registerCommand(Query(distro,release)) - conduit.registerCommand(Install(distro,release)) - diff --git a/yum-plugin/chitinplugin.py b/yum-plugin/chitinplugin.py new file mode 100644 index 0000000..61037c5 --- /dev/null +++ b/yum-plugin/chitinplugin.py @@ -0,0 +1,175 @@ +#!/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 Red Hat Inc. 2007, 2008 +# +# Author: Izhar Firdaus +# Examples: +# +# yum chitin-install oneclickinstall-XML-metadata-file +# yum chitin-query details oneclickinstall-XML-metadata-file +# yum chitin-query repositories oneclickinstall-XML-metadata-file +# yum chitin-query packages oneclickinstall-XML-metadata-file +# + +import re +from chitin.parser import Metapackage +from chitin.utils import get_child_value,get_element_tag +from yum.plugins import PluginYumExit,TYPE_CORE,TYPE_INTERACTIVE +from yum import logginglevels +import yum.i18n, tempfile +_ = yum.i18n._ + +requires_api_version = '2.5' +plugin_type = (TYPE_INTERACTIVE,) + +## Use this for now +distro='openSUSE' +release='Factory' + + +def add_tmp_repo(base,name,repourls): + """ + Function to add temporary repository + + @param base The YumBase object for the operation + @param name The repository name + @param repourls A list of urls for the repository + + @return None + """ + tfo = tempfile.NamedTemporaryFile() + repoid = name + repoconfig = """ +[%s] +name=%s +failovermethod=priority +baseurl=%s +enabled=1 +""" % (name,name,'\n'.join(repourls)) + tfo.file.write(repoconfig) + tfo.file.close() + base.getReposFromConfigFile(tfo.name) + +class Query: + def __init__(self,distro,release): + self.distro = distro + self.release = release + + def getNames(self): + return ['chitin-query'] + + def getUsage(self): + return "[details|repositories|packages] [ file]" + + def getSummary(self): + return "Query data from OneClickInstall metadata" + + def doCheck(self, base, basecmd, extcmds): + pass + + def getRepos(self): # so we can act as a "conduit" + return self.repos + + def show_pkg(self, msg, pkg, md, disp=None): + print msg, pkg, md + + def show_pkg_exit(self): + pass + + def doCommand(self, base, basecmd, extcmds): + action = extcmds[0] + param = extcmds[1:] + metapackages = [] + for mp in param: + metapackages.append(Metapackage(mp,'%s %s' % (self.distro,self.release))) + + if action == 'details': + for chitin in metapackages: + print '=======================' + print 'Metadata' + print '=======================' + for c in chitin.getGroup().getchildren(): + tagname = get_element_tag(c) + if tagname in ['name','summary','description']: + print tagname,':',c.text + if action == 'repositories': + for chitin in metapackages: + print '========================' + print 'Repositories' + print '========================' + for r in chitin.getRepositories(): + print get_child_value(r,'name') + print chitin.getRepoURL(get_child_value(r,'name')) + if action == 'packages': + for chitin in metapackages: + print '========================' + print 'Packages' + print '========================' + for p in chitin.getProducts(): + print p.getchildren()[0].text + print '' + return 0, [''] + +class Install: + def __init__(self,distro,release): + self.distro = distro + self.release = release + + def getNames(self): + return ['chitin-install'] + + def getUsage(self): + return "[ file]" + + def getSummary(self): + return "Install packages from OneClickInstall metadata" + + def doCheck(self, base, basecmd, extcmds): + pass + + def getRepos(self): # so we can act as a "conduit" + return self.repos + + def show_pkg(self, msg, pkg, md, disp=None): + print msg, pkg, md + + def show_pkg_exit(self): + pass + + def doCommand(self, base, basecmd, extcmds): + packages = [] + repositories = [] + for mp in extcmds: + chitin = Metapackage(mp,'%s %s' % (self.distro,self.release)) + for p in chitin.getProducts(): + packages.append(get_child_value(p,'name')) + for r in chitin.getRepositories(): + repositories.append((get_child_value(r,'name'),chitin.getRepoURL(get_child_value(r,'name')))) + print packages + print repositories + + base.verbose_logger.log(logginglevels.INFO_2, + _("Setting up Install Process")) + try: + return base.installPkgs(packages) + except yum.Errors.YumBaseError, e: + return 1, [str(e)] + +def config_hook(conduit): + conduit.registerCommand(Query(distro,release)) + conduit.registerCommand(Install(distro,release)) + -- cgit