summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIzhar Firdaus <kagesenshi.87@gmail.com>2008-06-23 23:13:14 +0800
committerIzhar Firdaus <kagesenshi.87@gmail.com>2008-06-23 23:13:14 +0800
commite5b94a96d02699032a1467e85bf82505181eb6f7 (patch)
tree3cc86f45b45133f9c215e52cee53d658863a4e1e
parent4e5b4a39c432395b62470176c84b96db44b8d34f (diff)
downloadchitin-e5b94a96d02699032a1467e85bf82505181eb6f7.zip
chitin-e5b94a96d02699032a1467e85bf82505181eb6f7.tar.gz
chitin-e5b94a96d02699032a1467e85bf82505181eb6f7.tar.xz
- added basic yum plugin
-rw-r--r--chitin/utils.py2
-rw-r--r--yum-plugin/chitin.py186
2 files changed, 27 insertions, 161 deletions
diff --git a/chitin/utils.py b/chitin/utils.py
index b10bfc3..47b7e95 100644
--- a/chitin/utils.py
+++ b/chitin/utils.py
@@ -14,6 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+import re
+
def attrsfilter(elements,keywords,operation='or'):
"""
Function to filter elements by its attributes
diff --git a/yum-plugin/chitin.py b/yum-plugin/chitin.py
index 1653085..61037c5 100644
--- a/yum-plugin/chitin.py
+++ b/yum-plugin/chitin.py
@@ -25,87 +25,22 @@
# yum chitin-query packages oneclickinstall-XML-metadata-file
#
-
-from xml.etree.ElementTree import ElementTree,Element
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._
-ocins='http://opensuse.org/Standards/One_Click_Install'
-#distro='fedora'
-#release='9'
+requires_api_version = '2.5'
+plugin_type = (TYPE_INTERACTIVE,)
## Use this for now
distro='openSUSE'
release='Factory'
-requires_api_version = '2.5'
-plugin_type = (TYPE_INTERACTIVE,)
-
-
-def attrsfilter(elements,keywords,operation='or'):
- """
- Function to filter elements by its attributes
-
- @param elements A list of elements to be filtered
- @param keywords A dictionary containing required tags and its values
- @param operation A string, either 'or' or 'and', for operation selection
-
- @return A list of filtered elements by attributes
- """
- retval = []
- if not keywords: return elements
- if operation == 'or':
- for element in elements:
- for key in keywords:
- if element.attrib.has_key(key):
- if element.attrib[key] == keywords[key]:
- retval.append(element)
- break
- elif operation == 'and':
- for element in elements:
- for key in keywords:
- if not element.attrib.has_key(key): break
- if element.attrib[key] != keywords[key]: break
- retval.append(element)
- return retval
-
-def get_element_tag(element):
- """
- Function to get the element tag without namespace
-
- @param element An element which will be extracted the tag name
-
- @return A string, containing the tag name without namespace
- """
- tag = re.match('{.*?}(.*)',element.tag)
- if tag:
- return tag.group(1)
- else:
- return tag
-
-def get_child_value(element,childname):
- """
- Function to get the value of an element's child element
-
- @param element An element to be queried
- @param childname A string, containing the tagname of the child
-
- @return A string containing child's text value if child is a leaf element,
- or a ElementTree element if child is a parent to 1 or more elements
- """
- for c in element.getchildren():
- if get_element_tag(c) == childname:
- if c.getchildren():
- return c
- else:
- return c.text
-
-
def add_tmp_repo(base,name,repourls):
"""
Function to add temporary repository
@@ -129,86 +64,16 @@ enabled=1
tfo.file.close()
base.getReposFromConfigFile(tfo.name)
-class OCIMetapackage:
- """
- Parser class for OCI Metapackage XML.
- """
- def __init__(self,element,distversion):
- """
- @param element ElementTree object which stores the XML file
- @param distversion A string containing '$distro $release'
-
- @return None
- """
- self.element = element
- self.distversion = distversion
-
- def getGroup(self):
- """
- Function to get Group element from OCI Metadata
-
- @return 'group' Element of the current distversion
- """
- for group in self.element.getiterator('{%s}%s' % (ocins,'group')):
- if group.attrib['distversion'] == self.distversion:
- return group
-
- def getRepositories(self,*args,**kwargs):
- """
- Function to get 'repository' elements from the current distversion group
-
- @kwargs Keyword arguments for filtering results
-
- @return A list containing a filtered list of 'repository' Elements
- """
- repos = self.getGroup().getiterator('{%s}%s' % (ocins,'repository'))
- return attrsfilter(repos,kwargs)
-
- def getProducts(self,*args,**kwargs):
- """
- Function to get 'product' elements from the current distversion group
-
- @kwargs Keyword arguments for filtering results
-
- @return A list containing a filtered list of 'product' Elements
- """
- products = self.getGroup().getiterator('{%s}%s' % (ocins,'product'))
- return attrsfilter(products,kwargs)
-
- def getRepoURL(self,reponame):
- """
- Function to get 'url' values from current distversion group, and requested reponame
-
- @param reponame The repository name
-
- @return A list of URLs from the requested repository, sorted higher score first
- """
- repos = self.getRepositories()
- urls = []
- for r in repos:
- if get_child_value(r,'name') == reponame:
- for url in r.getiterator('{%s}%s' % (ocins,'url')):
- priority = 0
- 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
- else:
- return -1
- urls.sort(sorturl)
- return [ url[0] for url in urls ]
-
-class OCIQuery:
+class Query:
def __init__(self,distro,release):
self.distro = distro
self.release = release
def getNames(self):
- return ['oci-query']
+ return ['chitin-query']
def getUsage(self):
- return "[details|repositories|packages] [OCI file]"
+ return "[details|repositories|packages] [ file]"
def getSummary(self):
return "Query data from OneClickInstall metadata"
@@ -230,46 +95,45 @@ class OCIQuery:
param = extcmds[1:]
metapackages = []
for mp in param:
- et = ElementTree(Element('metapackage'),open(mp))
- metapackages.append(OCIMetapackage(et,'%s %s' % (self.distro,self.release)))
+ metapackages.append(Metapackage(mp,'%s %s' % (self.distro,self.release)))
if action == 'details':
- for oci in metapackages:
+ for chitin in metapackages:
print '======================='
print 'Metadata'
print '======================='
- for c in oci.getGroup().getchildren():
+ 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 oci in metapackages:
+ for chitin in metapackages:
print '========================'
print 'Repositories'
print '========================'
- for r in oci.getRepositories():
+ for r in chitin.getRepositories():
print get_child_value(r,'name')
- print oci.getRepoURL(get_child_value(r,'name'))
+ print chitin.getRepoURL(get_child_value(r,'name'))
if action == 'packages':
- for oci in metapackages:
+ for chitin in metapackages:
print '========================'
print 'Packages'
print '========================'
- for p in oci.getProducts():
+ for p in chitin.getProducts():
print p.getchildren()[0].text
print ''
return 0, ['']
-class OCIInstall:
+class Install:
def __init__(self,distro,release):
self.distro = distro
self.release = release
def getNames(self):
- return ['oci-install']
+ return ['chitin-install']
def getUsage(self):
- return "[OCI file]"
+ return "[ file]"
def getSummary(self):
return "Install packages from OneClickInstall metadata"
@@ -290,12 +154,11 @@ class OCIInstall:
packages = []
repositories = []
for mp in extcmds:
- et = ElementTree(Element('metapackage'),open(mp))
- oci = OCIMetapackage(et,'%s %s' % (self.distro,self.release))
- for p in oci.getProducts():
+ chitin = Metapackage(mp,'%s %s' % (self.distro,self.release))
+ for p in chitin.getProducts():
packages.append(get_child_value(p,'name'))
- for r in oci.getRepositories():
- repositories.append((get_child_value(r,'name'),oci.getRepoURL(get_child_value(r,'name'))))
+ for r in chitin.getRepositories():
+ repositories.append((get_child_value(r,'name'),chitin.getRepoURL(get_child_value(r,'name'))))
print packages
print repositories
@@ -307,5 +170,6 @@ class OCIInstall:
return 1, [str(e)]
def config_hook(conduit):
- conduit.registerCommand(OCIQuery(distro,release))
- conduit.registerCommand(OCIInstall(distro,release))
+ conduit.registerCommand(Query(distro,release))
+ conduit.registerCommand(Install(distro,release))
+