* implement a database of components
* extend index commands: allow for multiple dirs to be indexed at once NB: unfortunately, this exposes a bug in autoxml XmlFile support that I knew but had forgotten...
This commit is contained in:
@@ -94,10 +94,11 @@ Legend:
|
||||
+ requirements
|
||||
+ xml format, add to PSPEC
|
||||
+ index component.xml's and make use of them in build
|
||||
- a database of components:
|
||||
- query components by name
|
||||
- query list of packages in a component
|
||||
- index: update component database(s)
|
||||
/ a database of components:
|
||||
+ query components by name
|
||||
+ query list of packages in a component
|
||||
+ index: update component database(s)
|
||||
/ bug fixing
|
||||
- install/remove components
|
||||
- safety switch: preserve system.base, install system.devel for build, etc.
|
||||
+ multiple package repository (eray)
|
||||
|
||||
+11
-5
@@ -38,6 +38,7 @@ import pisi.packagedb as packagedb
|
||||
import pisi.repodb
|
||||
import pisi.installdb
|
||||
import pisi.sourcedb
|
||||
import pisi.component as component
|
||||
from pisi.index import Index
|
||||
import pisi.cli
|
||||
from pisi.operations import install, remove, upgrade
|
||||
@@ -70,12 +71,14 @@ def init(database = True, options = None, ui = None, comar = True):
|
||||
ctx.repodb = pisi.repodb.init()
|
||||
ctx.installdb = pisi.installdb.init()
|
||||
ctx.filesdb = pisi.files.FilesDB()
|
||||
ctx.componentdb = pisi.component.ComponentDB()
|
||||
packagedb.init_db()
|
||||
pisi.sourcedb.init()
|
||||
else:
|
||||
ctx.repodb = None
|
||||
ctx.installdb = None
|
||||
ctx.filesdb = None
|
||||
ctx.componentdb = None
|
||||
ctx.ui.debug('PISI API initialized')
|
||||
ctx.initialized = True
|
||||
|
||||
@@ -84,7 +87,8 @@ def finalize():
|
||||
pisi.installdb.finalize()
|
||||
if ctx.filesdb != None:
|
||||
ctx.filesdb.close()
|
||||
|
||||
if ctx.componentdb != None:
|
||||
ctx.componentdb.close()
|
||||
packagedb.finalize_db()
|
||||
pisi.sourcedb.finalize()
|
||||
ctx.ui.debug('PISI API finalized')
|
||||
@@ -223,11 +227,13 @@ def info_name(package_name):
|
||||
else:
|
||||
raise Error(_('Package %s not found') % package_name)
|
||||
|
||||
def index(repo_dir = '.', output = 'pisi-index.xml'):
|
||||
|
||||
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
||||
def index(dirs, output = 'pisi-index.xml'):
|
||||
index = Index()
|
||||
index.index(repo_dir)
|
||||
if not dirs:
|
||||
dirs = ['.']
|
||||
for repo_dir in dirs:
|
||||
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
||||
index.index(repo_dir)
|
||||
index.write(output)
|
||||
ctx.ui.info(_('* Index file written'))
|
||||
|
||||
|
||||
@@ -565,14 +565,11 @@ source and binary packages.
|
||||
|
||||
self.init()
|
||||
from pisi.api import index
|
||||
if len(self.args)==1:
|
||||
index(self.args[0], ctx.get_option('output'))
|
||||
if len(self.args)>0:
|
||||
index(self.args, ctx.get_option('output'))
|
||||
elif len(self.args)==0:
|
||||
ctx.ui.info( _('Indexing current directory.'))
|
||||
index('.', ctx.get_option('output'))
|
||||
else:
|
||||
ctx.ui.info( _('Indexing only a single directory supported.'))
|
||||
return
|
||||
self.finalize()
|
||||
|
||||
|
||||
|
||||
+51
-3
@@ -9,9 +9,7 @@
|
||||
#
|
||||
# Please read the COPYING file.
|
||||
#
|
||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||
|
||||
"""a placeholder for data types, might factor elsewhere later"""
|
||||
# Author: Eray Ozkural <eray@uludag.org.tr>
|
||||
|
||||
import gettext
|
||||
__trans = gettext.translation('pisi', fallback=True)
|
||||
@@ -20,6 +18,7 @@ _ = __trans.ugettext
|
||||
import pisi
|
||||
import pisi.pxml.xmlfile as xmlfile
|
||||
import pisi.pxml.autoxml as autoxml
|
||||
import pisi.lockeddbshelve as shelve
|
||||
|
||||
class Error(pisi.Error):
|
||||
pass
|
||||
@@ -57,6 +56,10 @@ class Component(xmlfile.XmlFile):
|
||||
# Dependencies to other components
|
||||
t_Dependencies = [ [autoxml.String], autoxml.optional, "Dependencies/Component"]
|
||||
|
||||
# the components contained by this guy.
|
||||
# to be filled by the component database, thus it is optional.
|
||||
t_Components = [ [autoxml.String], autoxml.optional, "Components/Component"]
|
||||
|
||||
# TODO: this is probably not necessary since we use fully qualified
|
||||
# module names (like in Java)
|
||||
#t_PartOf = [autoxml.Text, autoxml.mandatory]
|
||||
@@ -74,3 +77,48 @@ class Component(xmlfile.XmlFile):
|
||||
# t_Dependencies = [ [autoxml.Text], autoxml.optional, "Component"]
|
||||
# #t_Parts = [ [pisi.component.ComponentTree], autoxml.optional, "Component"]
|
||||
|
||||
class ComponentDB(object):
|
||||
"""a database of components"""
|
||||
|
||||
#FIXME: we might need a database per repo in the future
|
||||
def __init__(self):
|
||||
self.d = shelve.LockedDBShelf('components')
|
||||
|
||||
def close(self):
|
||||
self.d.close()
|
||||
|
||||
def has_component(self, name):
|
||||
return self.d.has_key(name)
|
||||
|
||||
def get_component(self, name):
|
||||
return self.d[name]
|
||||
|
||||
def list_components(self):
|
||||
list = []
|
||||
for (pkg, x) in self.d.iteritems():
|
||||
list.append(pkg)
|
||||
return list
|
||||
|
||||
def add_component(self, component):
|
||||
self.d[name] = component.name
|
||||
|
||||
def add_package(self, component_name, package):
|
||||
if not self.has_component(component_name):
|
||||
raise Error(_('Information for component %s not available') % component_name)
|
||||
component = self.get_component(component_name)
|
||||
component.components.append(package)
|
||||
self.d[component_name] = component # update
|
||||
|
||||
def remove_package(self, component_name, package):
|
||||
if not self.has_component(component_name):
|
||||
raise Error(_('Information for component %s not available') % component_name)
|
||||
component = self.get_component(component_name)
|
||||
component.components.remove(package)
|
||||
self.d[component_name] = component # update
|
||||
|
||||
def clear(self):
|
||||
self.d.clear()
|
||||
|
||||
def remove_component(self, name):
|
||||
name = str(name)
|
||||
del self.d[name]
|
||||
|
||||
+2
-2
@@ -79,10 +79,10 @@ class Index(XmlFile):
|
||||
def update_db(self, repo):
|
||||
pkgdb = packagedb.get_db(repo)
|
||||
pkgdb.clear()
|
||||
for comp in self.components:
|
||||
compdb.add_component(pkg)
|
||||
for pkg in self.packages:
|
||||
pkgdb.add_package(pkg)
|
||||
#for comp in self.components:
|
||||
# compdb.add_component(pkg)
|
||||
|
||||
def add_package(self, path, repo_uri):
|
||||
package = Package(path, 'r')
|
||||
|
||||
+4
-1
@@ -78,6 +78,8 @@ class PackageDB(object):
|
||||
self.dr[dep_name].append( (name, dep) )
|
||||
else:
|
||||
self.dr[dep_name] = [ (name, dep) ]
|
||||
# add component
|
||||
ctx.componentdb.add_package(package_info.partOf, package_info.name)
|
||||
|
||||
def clear(self):
|
||||
self.d.clear()
|
||||
@@ -85,7 +87,8 @@ class PackageDB(object):
|
||||
def remove_package(self, name):
|
||||
name = str(name)
|
||||
del self.d[name]
|
||||
|
||||
#FIXME: what's happening to dr?
|
||||
ctx.componentdb.remove_package(package_info.partOf, package_info.name)
|
||||
|
||||
packagedbs = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user