* 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:
+2
-3
@@ -223,15 +223,14 @@ def info_name(package_name):
|
|||||||
else:
|
else:
|
||||||
raise Error(_('Package %s not found') % package_name)
|
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)
|
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
||||||
index = Index()
|
index = Index()
|
||||||
index.index(repo_dir)
|
index.index(repo_dir)
|
||||||
index.write(ctx.const.pisi_index)
|
index.write(output)
|
||||||
ctx.ui.info(_('* Index file written'))
|
ctx.ui.info(_('* Index file written'))
|
||||||
|
|
||||||
|
|
||||||
def add_repo(name, indexuri):
|
def add_repo(name, indexuri):
|
||||||
repo = pisi.repodb.Repo(URI(indexuri))
|
repo = pisi.repodb.Repo(URI(indexuri))
|
||||||
ctx.repodb.add_repo(name, repo)
|
ctx.repodb.add_repo(name, repo)
|
||||||
|
|||||||
@@ -557,16 +557,19 @@ source and binary packages.
|
|||||||
self.parser.add_option("-a", "--absolute-uris", action="store_true",
|
self.parser.add_option("-a", "--absolute-uris", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=_("store absolute links for indexed files."))
|
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):
|
def run(self):
|
||||||
|
|
||||||
self.init()
|
self.init()
|
||||||
from pisi.api import index
|
from pisi.api import index
|
||||||
if len(self.args)==1:
|
if len(self.args)==1:
|
||||||
index(self.args[0])
|
index(self.args[0], ctx.get_option('output'))
|
||||||
elif len(self.args)==0:
|
elif len(self.args)==0:
|
||||||
ctx.ui.info( _('Indexing current directory.'))
|
ctx.ui.info( _('Indexing current directory.'))
|
||||||
index()
|
index('.', ctx.get_option('output'))
|
||||||
else:
|
else:
|
||||||
ctx.ui.info( _('Indexing only a single directory supported.'))
|
ctx.ui.info( _('Indexing only a single directory supported.'))
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ class Component(xmlfile.XmlFile):
|
|||||||
tag = "PISI"
|
tag = "PISI"
|
||||||
|
|
||||||
t_Name = [autoxml.Text, autoxml.mandatory] # fully qualified name
|
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_LocalName = [autoxml.LocalText, autoxml.mandatory]
|
||||||
t_Description = [autoxml.LocalText, autoxml.mandatory]
|
t_Description = [autoxml.LocalText, autoxml.mandatory]
|
||||||
#t_Icon = [autoxml.Binary, autoxml.mandatory]
|
#t_Icon = [autoxml.Binary, autoxml.mandatory]
|
||||||
|
|||||||
+31
-2
@@ -31,6 +31,8 @@ from pisi.package import Package
|
|||||||
from pisi.pxml.xmlfile import XmlFile
|
from pisi.pxml.xmlfile import XmlFile
|
||||||
import pisi.pxml.autoxml as autoxml
|
import pisi.pxml.autoxml as autoxml
|
||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
|
import pisi.component as component
|
||||||
|
import pisi.specfile as specfile
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -42,6 +44,7 @@ class Index(XmlFile):
|
|||||||
|
|
||||||
t_Sources = [ [specfile.Source], autoxml.optional, "Source"]
|
t_Sources = [ [specfile.Source], autoxml.optional, "Source"]
|
||||||
t_Packages = [ [metadata.Package], autoxml.optional, "Package"]
|
t_Packages = [ [metadata.Package], autoxml.optional, "Package"]
|
||||||
|
t_Components = [ [component.Component], autoxml.optional, "Component"]
|
||||||
|
|
||||||
def read_uri(self, filename, repo = None):
|
def read_uri(self, filename, repo = None):
|
||||||
"""Read PSPEC file"""
|
"""Read PSPEC file"""
|
||||||
@@ -65,14 +68,21 @@ class Index(XmlFile):
|
|||||||
for root, dirs, files in os.walk(repo_uri):
|
for root, dirs, files in os.walk(repo_uri):
|
||||||
for fn in files:
|
for fn in files:
|
||||||
if fn.endswith(ctx.const.package_suffix):
|
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)
|
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):
|
def update_db(self, repo):
|
||||||
pkgdb = packagedb.get_db(repo)
|
pkgdb = packagedb.get_db(repo)
|
||||||
pkgdb.clear()
|
pkgdb.clear()
|
||||||
for pkg in self.packages:
|
for pkg in self.packages:
|
||||||
pkgdb.add_package(pkg)
|
pkgdb.add_package(pkg)
|
||||||
|
#for comp in self.components:
|
||||||
|
# compdb.add_component(pkg)
|
||||||
|
|
||||||
def add_package(self, path, repo_uri):
|
def add_package(self, path, repo_uri):
|
||||||
package = Package(path, 'r')
|
package = Package(path, 'r')
|
||||||
@@ -97,5 +107,24 @@ class Index(XmlFile):
|
|||||||
else:
|
else:
|
||||||
self.packages.append(md.package)
|
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
|
#TODO: add source
|
||||||
|
|
||||||
|
|||||||
+14
-13
@@ -106,22 +106,26 @@ class LocalText(dict):
|
|||||||
newnode.appendChild(newtext)
|
newnode.appendChild(newtext)
|
||||||
node.appendChild(newnode)
|
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()):
|
def errors(self, where = unicode()):
|
||||||
errs = []
|
errs = []
|
||||||
try:
|
langs = [ LocalText.get_lang(), 'tr', 'en' ]
|
||||||
langs = [ locale.getlocale()[0][0:2], 'tr', 'en' ]
|
|
||||||
except:
|
|
||||||
raise Error(_('LocalText: locale not initialized'))
|
|
||||||
if not util.any(lambda x : self.has_key(x), langs):
|
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"))
|
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
|
#FIXME: check if all entries are unicode
|
||||||
return errs
|
return errs
|
||||||
|
|
||||||
def format(self, f, errs):
|
def format(self, f, errs):
|
||||||
try:
|
L = LocalText.get_lang()
|
||||||
L = locale.getlocale()[0][0:2] # try to read language, pathetic isn't it?
|
|
||||||
except:
|
|
||||||
raise Error(_('LocalText: locale not initialized'))
|
|
||||||
if self.has_key(L):
|
if self.has_key(L):
|
||||||
f.add_flowing_data(self[L])
|
f.add_flowing_data(self[L])
|
||||||
elif self.has_key('en'):
|
elif self.has_key('en'):
|
||||||
@@ -144,10 +148,7 @@ class LocalText(dict):
|
|||||||
ctx.ui.warning(x)
|
ctx.ui.warning(x)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
try:
|
L = LocalText.get_lang()
|
||||||
L = locale.getlocale()[0][0:2] # try to read language, pathetic isn't it?
|
|
||||||
except:
|
|
||||||
raise Error(_('LocalText: locale not initialized'))
|
|
||||||
if self.has_key(L):
|
if self.has_key(L):
|
||||||
return unicode(self[L])
|
return unicode(self[L])
|
||||||
elif self.has_key('en'):
|
elif self.has_key('en'):
|
||||||
|
|||||||
Executable
+29
@@ -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()
|
||||||
Reference in New Issue
Block a user