Add groupdb
This commit is contained in:
@@ -32,6 +32,7 @@ import pisi.db.installdb
|
|||||||
import pisi.db.historydb
|
import pisi.db.historydb
|
||||||
import pisi.db.sourcedb
|
import pisi.db.sourcedb
|
||||||
import pisi.db.componentdb
|
import pisi.db.componentdb
|
||||||
|
import pisi.db.groupdb
|
||||||
import pisi.index
|
import pisi.index
|
||||||
import pisi.config
|
import pisi.config
|
||||||
import pisi.metadata
|
import pisi.metadata
|
||||||
|
|||||||
+5
-3
@@ -13,17 +13,19 @@
|
|||||||
def invalidate_caches():
|
def invalidate_caches():
|
||||||
# Invalidates pisi caches in use and forces to re-fill caches from disk when needed
|
# Invalidates pisi caches in use and forces to re-fill caches from disk when needed
|
||||||
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(),
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(),
|
||||||
installdb.InstallDB(), historydb.HistoryDB()]:
|
installdb.InstallDB(), historydb.HistoryDB(), groupdb.GroupDB()]:
|
||||||
db.invalidate()
|
db.invalidate()
|
||||||
|
|
||||||
def flush_caches():
|
def flush_caches():
|
||||||
# Invalidate and flush caches to re-generate them when needed
|
# Invalidate and flush caches to re-generate them when needed
|
||||||
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB()]:
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(),
|
||||||
|
componentdb.ComponentDB(), groupdb.GroupDB()]:
|
||||||
db.invalidate()
|
db.invalidate()
|
||||||
db.cache_flush()
|
db.cache_flush()
|
||||||
|
|
||||||
def update_caches():
|
def update_caches():
|
||||||
# Updates ondisk caches
|
# Updates ondisk caches
|
||||||
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(), installdb.InstallDB()]:
|
for db in [packagedb.PackageDB(), sourcedb.SourceDB(), componentdb.ComponentDB(),
|
||||||
|
installdb.InstallDB(), groupdb.GroupDB()]:
|
||||||
if db.is_initialized():
|
if db.is_initialized():
|
||||||
db.cache_save()
|
db.cache_save()
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2009, TUBITAK/UEKAE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# Please read the COPYING file.
|
||||||
|
#
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
|
_ = __trans.ugettext
|
||||||
|
|
||||||
|
import pisi
|
||||||
|
import pisi.db.repodb
|
||||||
|
import pisi.db.itembyrepo
|
||||||
|
import pisi.group
|
||||||
|
import pisi.db.lazydb as lazydb
|
||||||
|
|
||||||
|
class GroupDB(lazydb.LazyDB):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
lazydb.LazyDB.__init__(self, cacheable=True)
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
group_nodes = {}
|
||||||
|
group_components = {}
|
||||||
|
|
||||||
|
self.repodb = pisi.db.repodb.RepoDB()
|
||||||
|
|
||||||
|
for repo in self.repodb.list_repos():
|
||||||
|
doc = self.repodb.get_repo_doc(repo)
|
||||||
|
group_nodes[repo] = self.__generate_groups(doc)
|
||||||
|
group_components[repo] = self.__generate_components(doc)
|
||||||
|
|
||||||
|
self.gdb = pisi.db.itembyrepo.ItemByRepo(group_nodes)
|
||||||
|
self.gcdb = pisi.db.itembyrepo.ItemByRepo(group_components)
|
||||||
|
|
||||||
|
def __generate_components(self, doc):
|
||||||
|
groups = {}
|
||||||
|
for c in doc.tags("Component"):
|
||||||
|
groups.setdefault(c.getTagData("Group"), []).append(c.getTagData("Name"))
|
||||||
|
return groups
|
||||||
|
|
||||||
|
def __generate_groups(self, doc):
|
||||||
|
return dict(map(lambda x: (x.getTagData("Name"), x.toString()), doc.tags("Group")))
|
||||||
|
|
||||||
|
def has_group(self, name, repo = None):
|
||||||
|
return self.gdb.has_item(name, repo)
|
||||||
|
|
||||||
|
def list_groups(self, repo=None):
|
||||||
|
return self.gdb.get_item_keys(repo)
|
||||||
|
|
||||||
|
def get_group(self, name, repo = None):
|
||||||
|
|
||||||
|
if not self.has_group(name, repo):
|
||||||
|
raise Exception(_('Group %s not found') % name)
|
||||||
|
|
||||||
|
group = pisi.group.Group()
|
||||||
|
group.parse(self.gdb.get_item(name, repo))
|
||||||
|
|
||||||
|
return group
|
||||||
|
|
||||||
|
def get_group_components(self, name, repo=None):
|
||||||
|
return self.gcdb.get_item(name, repo)
|
||||||
+1
-1
@@ -23,7 +23,7 @@ class Error(pisi.Error):
|
|||||||
|
|
||||||
__metaclass__ = autoxml.autoxml
|
__metaclass__ = autoxml.autoxml
|
||||||
|
|
||||||
class Group:
|
class Group(xmlfile.XmlFile):
|
||||||
"representation for group declarations"
|
"representation for group declarations"
|
||||||
|
|
||||||
__metaclass__ = autoxml.autoxml
|
__metaclass__ = autoxml.autoxml
|
||||||
|
|||||||
+4
-2
@@ -29,6 +29,7 @@ import pisi.pxml.xmlfile as xmlfile
|
|||||||
import pisi.file
|
import pisi.file
|
||||||
import pisi.pxml.autoxml as autoxml
|
import pisi.pxml.autoxml as autoxml
|
||||||
import pisi.component as component
|
import pisi.component as component
|
||||||
|
import pisi.group as group
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -43,6 +44,7 @@ class Index(xmlfile.XmlFile):
|
|||||||
t_Packages = [ [metadata.Package], autoxml.optional, "Package"]
|
t_Packages = [ [metadata.Package], autoxml.optional, "Package"]
|
||||||
#t_Metadatas = [ [metadata.MetaData], autoxml.optional, "MetaData"]
|
#t_Metadatas = [ [metadata.MetaData], autoxml.optional, "MetaData"]
|
||||||
t_Components = [ [component.Component], autoxml.optional, "Component"]
|
t_Components = [ [component.Component], autoxml.optional, "Component"]
|
||||||
|
t_Groups = [ [group.Group], autoxml.optional, "Group"]
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.distribution.name + self.distribution.repositoryname
|
return self.distribution.name + self.distribution.repositoryname
|
||||||
@@ -153,8 +155,8 @@ class Index(xmlfile.XmlFile):
|
|||||||
ctx.ui.info("Adding groups.xml to index...")
|
ctx.ui.info("Adding groups.xml to index...")
|
||||||
groups_xml = group.Groups()
|
groups_xml = group.Groups()
|
||||||
groups_xml.read(path)
|
groups_xml.read(path)
|
||||||
for group in groups_xml.groups:
|
for grp in groups_xml.groups:
|
||||||
self.groups.append(group)
|
self.groups.append(grp)
|
||||||
|
|
||||||
def add_components(self, path):
|
def add_components(self, path):
|
||||||
ctx.ui.info("Adding components.xml to index...")
|
ctx.ui.info("Adding components.xml to index...")
|
||||||
|
|||||||
Reference in New Issue
Block a user