* index components

* start a simple tool for peeking around the source repo
* use defaultlocale() for determining locale as a fallback
* add an --output option to index command
* die, by my hand
This commit is contained in:
Eray Özkural
2005-11-14 11:21:22 +00:00
parent b09b567b7c
commit fd3471ec12
6 changed files with 82 additions and 21 deletions
+2 -3
View File
@@ -223,15 +223,14 @@ def info_name(package_name):
else:
raise Error(_('Package %s not found') % package_name)
def index(repo_dir = '.'):
def index(repo_dir = '.', output = 'pisi-index.xml'):
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
index = Index()
index.index(repo_dir)
index.write(ctx.const.pisi_index)
index.write(output)
ctx.ui.info(_('* Index file written'))
def add_repo(name, indexuri):
repo = pisi.repodb.Repo(URI(indexuri))
ctx.repodb.add_repo(name, repo)
+5 -2
View File
@@ -557,16 +557,19 @@ source and binary packages.
self.parser.add_option("-a", "--absolute-uris", action="store_true",
default=False,
help=_("store absolute links for indexed files."))
self.parser.add_option("-o", "--output", action="store",
default='pisi-index.xml',
help=_("index output file"))
def run(self):
self.init()
from pisi.api import index
if len(self.args)==1:
index(self.args[0])
index(self.args[0], ctx.get_option('output'))
elif len(self.args)==0:
ctx.ui.info( _('Indexing current directory.'))
index()
index('.', ctx.get_option('output'))
else:
ctx.ui.info( _('Indexing only a single directory supported.'))
return
+1 -1
View File
@@ -43,7 +43,7 @@ class Component(xmlfile.XmlFile):
tag = "PISI"
t_Name = [autoxml.Text, autoxml.mandatory] # fully qualified name
t_PartOf = [autoxml.Text, autoxml.mandatory]
#t_PartOf = [autoxml.Text, autoxml.mandatory]
t_LocalName = [autoxml.LocalText, autoxml.mandatory]
t_Description = [autoxml.LocalText, autoxml.mandatory]
#t_Icon = [autoxml.Binary, autoxml.mandatory]
+31 -2
View File
@@ -31,6 +31,8 @@ from pisi.package import Package
from pisi.pxml.xmlfile import XmlFile
import pisi.pxml.autoxml as autoxml
from pisi.uri import URI
import pisi.component as component
import pisi.specfile as specfile
class Error(pisi.Error):
pass
@@ -42,6 +44,7 @@ class Index(XmlFile):
t_Sources = [ [specfile.Source], autoxml.optional, "Source"]
t_Packages = [ [metadata.Package], autoxml.optional, "Package"]
t_Components = [ [component.Component], autoxml.optional, "Component"]
def read_uri(self, filename, repo = None):
"""Read PSPEC file"""
@@ -65,14 +68,21 @@ class Index(XmlFile):
for root, dirs, files in os.walk(repo_uri):
for fn in files:
if fn.endswith(ctx.const.package_suffix):
ctx.ui.info(_('Adding %s to package index') %fn)
ctx.ui.info(_('Adding %s to package index') % fn)
self.add_package(os.path.join(root, fn), repo_uri)
if fn == 'component.xml':
ctx.ui.info(_('Adding %s to component index') % fn)
self.add_component(os.path.join(root, fn))
#if fn == 'pspec.xml':
# self.add_source(os.path.join(root, fn), repo_uri)
def update_db(self, repo):
pkgdb = packagedb.get_db(repo)
pkgdb.clear()
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')
@@ -97,5 +107,24 @@ class Index(XmlFile):
else:
self.packages.append(md.package)
def add_component(self, path):
comp = component.Component()
try:
comp.read(path)
self.components.append(comp)
except:
ctx.ui.error(_('Component in %s is corrupt') % path)
#ctx.ui.error(str(Error(*errs)))
def add_source(self, path):
ctx.ui.info(_('Adding %s to source index') % fn)
sf = specfile.SpecFile()
sf.read(path)
errs = sf.errors()
if sf.errors():
ctx.ui.error(_('SpecFile in %s is corrupt') % path)
ctx.ui.error(str(Error(*errs)))
else:
self.sources.append(sf.source)
#TODO: add source
+14 -13
View File
@@ -106,22 +106,26 @@ class LocalText(dict):
newnode.appendChild(newtext)
node.appendChild(newnode)
@staticmethod
def get_lang():
try:
(lang, encoding) = locale.getlocale()
if not lang:
(lang, encoding) = locale.getdefaultlocale()
return lang[0:2]
except:
raise Error(_('LocalText: unable to get either current or default locale'))
def errors(self, where = unicode()):
errs = []
try:
langs = [ locale.getlocale()[0][0:2], 'tr', 'en' ]
except:
raise Error(_('LocalText: locale not initialized'))
langs = [ LocalText.get_lang(), 'tr', 'en' ]
if not util.any(lambda x : self.has_key(x), langs):
errs.append( where + _("Tag should have at least the current locale, or failing that an English or Turkish version"))
#FIXME: check if all entries are unicode
return errs
def format(self, f, errs):
try:
L = locale.getlocale()[0][0:2] # try to read language, pathetic isn't it?
except:
raise Error(_('LocalText: locale not initialized'))
L = LocalText.get_lang()
if self.has_key(L):
f.add_flowing_data(self[L])
elif self.has_key('en'):
@@ -144,10 +148,7 @@ class LocalText(dict):
ctx.ui.warning(x)
def __str__(self):
try:
L = locale.getlocale()[0][0:2] # try to read language, pathetic isn't it?
except:
raise Error(_('LocalText: locale not initialized'))
L = LocalText.get_lang()
if self.has_key(L):
return unicode(self[L])
elif self.has_key('en'):
+29
View File
@@ -0,0 +1,29 @@
#! /usr/bin/python
import sys
import os
import pisi
import pisi.api
import pisi.config
import pisi.specfile as specfile
import pisi.context as ctx
import pisi.util
options = pisi.config.Options()
if len(sys.argv)>2:
options.destdir=sys.argv[2]
else:
options.destdir = '/'
pisi.api.init(database=False, options=options)
repo_uri = sys.argv[1]
for root, dirs, files in os.walk(repo_uri):
for fn in files:
if fn == 'pspec.xml':
#ctx.ui.info(_('Adding %s to package index') % fn)
sf = specfile.SpecFile()
sf.read(pisi.util.join_path(root, fn))
print sf.source.name, sf.source.partOf
pisi.api.finalize()