* more of gettext calls for strings

* fix exception names in some modules
* minor cleanup
* update TODO
This commit is contained in:
Eray Özkural
2005-10-03 14:35:12 +00:00
parent ce7f717bca
commit a422fdbae6
18 changed files with 165 additions and 110 deletions
+1 -1
View File
@@ -75,7 +75,6 @@ Legend:
* high priority * high priority
/ configure-pending (eray)
/ i18n support / i18n support
- summary,description için doğru dili kullanmak - summary,description için doğru dili kullanmak
/ pisi mesajlarının çevrilebilir hale getirilmesi (build.py yi örnek alın) / pisi mesajlarının çevrilebilir hale getirilmesi (build.py yi örnek alın)
@@ -99,6 +98,7 @@ Legend:
+ ask alternatives to choose from (eray) + ask alternatives to choose from (eray)
+ eliminate \n's from infos, what's the point? + eliminate \n's from infos, what's the point?
+ metaclass coolness for CLI command framework (eray) + metaclass coolness for CLI command framework (eray)
+ configure-pending (eray)
+ ignore-deps + ignore-deps
+ more robust upgrade + more robust upgrade
+7 -3
View File
@@ -18,8 +18,12 @@ import gettext
__trans = gettext.translation('pisi', fallback=True) __trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext _ = __trans.ugettext
import pisi
import pisi.context as ctx import pisi.context as ctx
class Error(pisi.Error):
pass
def run_postinstall(package_name): def run_postinstall(package_name):
"run postinstall scripts trough COMAR" "run postinstall scripts trough COMAR"
@@ -34,11 +38,11 @@ def run_postinstall(package_name):
elif reply[0] == com.NONE: # package has no postInstall script elif reply[0] == com.NONE: # package has no postInstall script
break break
elif reply[0] == com.FAIL: elif reply[0] == com.FAIL:
e = _("COMAR.call_package(System.Pakcage.postInstall, %s) failed!: %s") % ( e = _("COMAR.call_package(System.Package.postInstall, %s) failed!: %s") % (
self.metadata.package.name, reply[2]) self.metadata.package.name, reply[2])
raise InstallError, e raise Error, e
else: else:
raise InstallError, _("COMAR.call_package ERROR: %d") % reply[0] raise Error, _("COMAR.call_package ERROR: %d") % reply[0]
def run_preremove(package_name): def run_preremove(package_name):
com = ctx.comard com = ctx.comard
+7 -7
View File
@@ -32,7 +32,7 @@ from pisi.metadata import MetaData
import pisi.comariface as comariface import pisi.comariface as comariface
#import conflicts #import conflicts
class InstallError(pisi.Error): class Error(pisi.Error):
pass pass
class Installer: class Installer:
@@ -48,7 +48,7 @@ class Installer:
def install(self, ask_reinstall = True): def install(self, ask_reinstall = True):
"entry point" "entry point"
ctx.ui.info('Installing %s, version %s, release %s, build %s' % ctx.ui.info(_('Installing %s, version %s, release %s, build %s') %
(self.pkginfo.name, self.pkginfo.version, (self.pkginfo.name, self.pkginfo.version,
self.pkginfo.release, self.pkginfo.build)) self.pkginfo.release, self.pkginfo.build))
self.ask_reinstall = ask_reinstall self.ask_reinstall = ask_reinstall
@@ -78,14 +78,14 @@ class Installer:
# check conflicts # check conflicts
for pkg in self.metadata.package.conflicts: for pkg in self.metadata.package.conflicts:
if ctx.installdb.is_installed(self.pkginfo): if ctx.installdb.is_installed(self.pkginfo):
raise InstallError("Package conflicts " + pkg) raise Error(_("Package conflicts %s") % pkg)
# check dependencies # check dependencies
if not ctx.config.get_option('ignore_dependency'): if not ctx.config.get_option('ignore_dependency'):
if not dependency.installable(self.pkginfo.name): if not dependency.installable(self.pkginfo.name):
ctx.ui.error(_('Dependencies for %s not satisfied') % ctx.ui.error(_('Dependencies for %s not satisfied') %
self.pkginfo.name) self.pkginfo.name)
raise InstallError(_("Package not installable")) raise Error(_("Package not installable"))
def check_reinstall(self): def check_reinstall(self):
"check reinstall, confirm action, and schedule reinstall" "check reinstall, confirm action, and schedule reinstall"
@@ -110,7 +110,7 @@ class Installer:
if same_ver: if same_ver:
if self.ask_reinstall: if self.ask_reinstall:
if not ctx.ui.confirm(_('Re-install same version package?')): if not ctx.ui.confirm(_('Re-install same version package?')):
raise InstallError(_('Package re-install declined')) raise Error(_('Package re-install declined'))
else: else:
upgrade = False upgrade = False
# is this an upgrade? # is this an upgrade?
@@ -135,7 +135,7 @@ class Installer:
else: else:
x = _('Downgrade to old distribution build?') x = _('Downgrade to old distribution build?')
if not ctx.ui.confirm(x): if not ctx.ui.confirm(x):
raise InstallError(_('Package downgrade declined')) raise Error(_('Package downgrade declined'))
# schedule for reinstall # schedule for reinstall
self.old_files = ctx.installdb.files(pkg.name) self.old_files = ctx.installdb.files(pkg.name)
@@ -193,7 +193,7 @@ class Installer:
if reply[0] == com.RESULT: if reply[0] == com.RESULT:
break break
else: else:
raise InstallError, _("COMAR.register ERROR!") raise Error, _("COMAR.register ERROR!")
def update_databases(self): def update_databases(self):
+10 -3
View File
@@ -9,7 +9,6 @@
# #
# Please read the COPYING file. # Please read the COPYING file.
# #
# A simple wrapper to implement locking for bsddb's dbshelf
# #
# Authors: Eray Ozkural <eray@uludag.org.tr> # Authors: Eray Ozkural <eray@uludag.org.tr>
@@ -19,10 +18,18 @@ import bsddb.db as db
import os import os
import fcntl import fcntl
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.context import pisi.context
class Error(pisi.Error):
pass
class LockedDBShelf(shelve.DBShelf): class LockedDBShelf(shelve.DBShelf):
"""A simple wrapper to implement locking for bsddb's dbshelf"""
def __init__(self, dbname, flags=db.DB_CREATE, mode=0660, def __init__(self, dbname, flags=db.DB_CREATE, mode=0660,
filetype=db.DB_HASH, dbenv=None): filetype=db.DB_HASH, dbenv=None):
@@ -40,7 +47,7 @@ class LockedDBShelf(shelve.DBShelf):
elif sflag == 'n': elif sflag == 'n':
flags = db.DB_TRUNCATE | db.DB_CREATE flags = db.DB_TRUNCATE | db.DB_CREATE
else: else:
raise error, "flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags" raise Error, _("Flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags")
filename = os.path.join( pisi.context.config.db_dir(), dbname + '.bdb') filename = os.path.join( pisi.context.config.db_dir(), dbname + '.bdb')
self.open(filename, dbname, filetype, flags, mode) self.open(filename, dbname, filetype, flags, mode)
@@ -51,7 +58,7 @@ class LockedDBShelf(shelve.DBShelf):
fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError: except IOError:
import sys import sys
pisi.context.ui.error("Another instance of PISI is running. Try later!") pisi.context.ui.error(_("Another instance of PISI is running. Try later!"))
sys.exit(1) sys.exit(1)
return self.db.open(filename, dbname, filetype, flags, mode) return self.db.open(filename, dbname, filetype, flags, mode)
+15 -10
View File
@@ -7,15 +7,20 @@
# #
# Please read the COPYING file. # Please read the COPYING file.
# #
# Metadata module provides access to metadata.xml. metadata.xml is
# generated during the build process of a package and used in the
# installation. Package repository also uses metadata.xml for building
# a package index.
# Authors: Eray Ozkural <eray@uludag.org.tr> # Authors: Eray Ozkural <eray@uludag.org.tr>
# Baris Metin <baris@uludag.org.tr # Baris Metin <baris@uludag.org.tr
"""
Metadata module provides access to metadata.xml. metadata.xml is
generated during the build process of a package and used in the
installation. Package repository also uses metadata.xml for building
a package index.
"""
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi.context as ctx import pisi.context as ctx
import pisi.specfile as specfile import pisi.specfile as specfile
from pisi.xmlfile import * from pisi.xmlfile import *
@@ -41,7 +46,7 @@ class SourceInfo:
def has_errors(self): def has_errors(self):
if not self.name: if not self.name:
return [ "SourceInfo should have a Name" ] return [ _("SourceInfo should have a Name") ]
return None return None
@@ -87,7 +92,7 @@ class PackageInfo(specfile.PackageInfo):
ret = ret and self.architecture!=None and self.installedSize!=None ret = ret and self.architecture!=None and self.installedSize!=None
if ret: if ret:
return None return None
return [ "Some error in package metadata" ] return [ _("Some error in package metadata") ]
def __str__(self): def __str__(self):
s = specfile.PackageInfo.__str__(self) s = specfile.PackageInfo.__str__(self)
@@ -142,10 +147,10 @@ class MetaData(XmlFile):
err = Checks() err = Checks()
# FIXME: is this an internal error?? -gurer # FIXME: is this an internal error?? -gurer
if not hasattr(self, 'source'): if not hasattr(self, 'source'):
err.add("Metadata should have source") err.add(_("Metadata should have source"))
err.join(self.source.has_errors()) err.join(self.source.has_errors())
if not self.package: if not self.package:
err.add("Metadata should have a package") err.add(_("Metadata should have a package"))
err.join(self.package.has_errors()) err.join(self.package.has_errors())
return err.list return err.list
+9 -5
View File
@@ -13,6 +13,10 @@
import os import os
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
import pisi.util as util import pisi.util as util
@@ -40,7 +44,7 @@ def remove_file(fileinfo):
if os.path.isfile(fpath) or os.path.islink(fpath): if os.path.isfile(fpath) or os.path.islink(fpath):
os.unlink(fpath) os.unlink(fpath)
else: else:
ctx.ui.warning('Not removing non-file, non-link %d' % fpath) ctx.ui.warning(_('Not removing non-file, non-link %d') % fpath)
def run_preremove(package_name): def run_preremove(package_name):
if ctx.comard: if ctx.comard:
@@ -59,9 +63,9 @@ def remove_single(package_name):
#TODO: check dependencies #TODO: check dependencies
ctx.ui.info('Removing package %s' % package_name) ctx.ui.info(_('Removing package %s') % package_name)
if not ctx.installdb.is_installed(package_name): if not ctx.installdb.is_installed(package_name):
raise Exception('Trying to remove nonexistent package ' raise Exception(_('Trying to remove nonexistent package ')
+ package_name) + package_name)
run_preremove(package_name) run_preremove(package_name)
@@ -104,12 +108,12 @@ def install_single_name(name, upgrade = False):
pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()), pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()),
str(pkg_uri.path())) str(pkg_uri.path()))
ctx.ui.debug("Package URI: %s" % pkg_path) ctx.ui.debug(_("Package URI: %s") % pkg_path)
# Package will handle remote file for us! # Package will handle remote file for us!
install_single_file(pkg_path, upgrade) install_single_file(pkg_path, upgrade)
else: else:
ctx.ui.error("Package %s not found in any active repository." % pkg) ctx.ui.error(_("Package %s not found in any active repository.") % pkg)
# deneme, don't remove ulan # deneme, don't remove ulan
class AtomicOperation(object): class AtomicOperation(object):
+8 -4
View File
@@ -17,6 +17,10 @@
from os.path import join, exists from os.path import join, exists
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
import pisi.archive as archive import pisi.archive as archive
@@ -24,7 +28,7 @@ from pisi.uri import URI
from pisi.metadata import MetaData from pisi.metadata import MetaData
from pisi.files import Files from pisi.files import Files
class PackageError(pisi.Error): class Error(pisi.Error):
pass pass
@@ -45,7 +49,7 @@ class Package:
if not exists(self.filepath): if not exists(self.filepath):
fetch_url(url, dest, ctx.ui.Progress) fetch_url(url, dest, ctx.ui.Progress)
else: else:
ctx.ui.info('%s [cached]' % url.filename()) ctx.ui.info(_('%s [cached]') % url.filename())
self.impl = archive.ArchiveZip(self.filepath, 'zip', mode) self.impl = archive.ArchiveZip(self.filepath, 'zip', mode)
@@ -96,12 +100,12 @@ class Package:
self.metadata = MetaData() self.metadata = MetaData()
self.metadata.read( join(outdir, ctx.const.metadata_xml) ) self.metadata.read( join(outdir, ctx.const.metadata_xml) )
if self.metadata.has_errors(): if self.metadata.has_errors():
raise PackageError, "MetaData format wrong" raise Error, _("MetaData format wrong")
self.files = Files() self.files = Files()
self.files.read( join(outdir, ctx.const.files_xml) ) self.files.read( join(outdir, ctx.const.files_xml) )
if self.files.has_errors(): if self.files.has_errors():
raise PackageError, "invalid %s" % ctx.const.files_xml raise Error, _("Invalid %s") % ctx.const.files_xml
def pkg_dir(self): def pkg_dir(self):
packageDir = self.metadata.package.name + '-' \ packageDir = self.metadata.package.name + '-' \
+5 -1
View File
@@ -23,6 +23,10 @@ import bsddb.dbshelve as shelve
import os, fcntl import os, fcntl
from bsddb import db from bsddb import db
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.util as util import pisi.util as util
import pisi.context as ctx import pisi.context as ctx
@@ -127,7 +131,7 @@ def get_package(name):
return thirdparty_packagedb.get_package(name) return thirdparty_packagedb.get_package(name)
if inst_packagedb.has_package(name): if inst_packagedb.has_package(name):
return inst_packagedb.get_package(name) return inst_packagedb.get_package(name)
raise Error('get_package: package %s not found' % name) raise Error(_('get_package: package %s not found') % name)
def get_rev_deps(name): def get_rev_deps(name):
repo = which_repo(name) repo = which_repo(name)
+5 -1
View File
@@ -13,6 +13,10 @@
from bsddb import db from bsddb import db
import os, fcntl import os, fcntl
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.lockeddbshelve as shelve import pisi.lockeddbshelve as shelve
import pisi.context as ctx import pisi.context as ctx
@@ -71,7 +75,7 @@ class RepoDB(object):
def add_repo(self, name, repo_info): def add_repo(self, name, repo_info):
if self.d.has_key("repo-" + name): if self.d.has_key("repo-" + name):
raise Error('Repository %s already exists' % name) raise Error(_('Repository %s already exists') % name)
self.d["repo-" + name] = repo_info self.d["repo-" + name] = repo_info
order = self.d["order"] order = self.d["order"]
order.append(name) order.append(name)
+6 -3
View File
@@ -17,6 +17,9 @@
from os.path import join from os.path import join
from os import access, R_OK from os import access, R_OK
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
# pisi modules # pisi modules
import pisi import pisi
@@ -26,7 +29,7 @@ from pisi.archive import Archive
from pisi.uri import URI from pisi.uri import URI
from pisi.fetcher import fetch_url from pisi.fetcher import fetch_url
class SourceArchiveError(pisi.Error): class Error(pisi.Error):
pass pass
class SourceArchive: class SourceArchive:
@@ -54,7 +57,7 @@ class SourceArchive:
# check hash # check hash
if util.check_file_hash(self.archiveFile, self.archiveSHA1): if util.check_file_hash(self.archiveFile, self.archiveSHA1):
if interactive: if interactive:
ctx.ui.info('%s [cached]' % self.archiveName) ctx.ui.info(_('%s [cached]') % self.archiveName)
return True return True
return False return False
@@ -63,7 +66,7 @@ class SourceArchive:
# check archive file's integrity # check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archiveSHA1): if not util.check_file_hash(self.archiveFile, self.archiveSHA1):
raise SourceArchiveError, "unpack: check_file_hash failed" raise Error, _("unpack: check_file_hash failed")
archive = Archive(self.archiveFile, self.archiveType) archive = Archive(self.archiveFile, self.archiveType)
archive.unpack(self.bctx.pkg_work_dir(), cleanDir) archive.unpack(self.bctx.pkg_work_dir(), cleanDir)
+11 -9
View File
@@ -9,20 +9,24 @@
# #
# Please read the COPYING file. # Please read the COPYING file.
# #
# package source database
# interface for update/query to local package repository
# Author: Eray Ozkural <eray@uludag.org.tr> # Author: Eray Ozkural <eray@uludag.org.tr>
# we basically store everything in sourceinfo class """
# yes, we are cheap package source database
interface for update/query to local package repository
we basically store everything in sourceinfo class
yes, we are cheap
"""
import bsddb.dbshelve as shelve import bsddb.dbshelve as shelve
import os import os
import fcntl import fcntl
from bsddb import db from bsddb import db
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi.util as util import pisi.util as util
import pisi.context as ctx import pisi.context as ctx
@@ -49,9 +53,7 @@ class SourceDB(object):
return self.d[name] return self.d[name]
def add_source(self, source_info): def add_source(self, source_info):
# FIXME: how can you make a negative assertion -gurer assert not source_info.has_errors()
# and yes i'm not very clever :)
# assert source_info.has_errors()
name = str(source_info.name) name = str(source_info.name)
self.d[name] = source_info self.d[name] = source_info
+5 -1
View File
@@ -12,6 +12,10 @@
from os.path import basename, dirname, join from os.path import basename, dirname, join
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi.context as ctx import pisi.context as ctx
from pisi.uri import URI from pisi.uri import URI
from pisi.specfile import SpecFile from pisi.specfile import SpecFile
@@ -74,7 +78,7 @@ class SourceFetcher(object):
def fetch(self, appendDest=""): def fetch(self, appendDest=""):
from fetcher import fetch_url from fetcher import fetch_url
ctx.ui.info("Fetching %s" % self.url.uri) ctx.ui.info(_("Fetching %s") % self.url.uri)
dest = join(self.dest, appendDest) dest = join(self.dest, appendDest)
fetch_url(self.url, dest) fetch_url(self.url, dest)
+19 -13
View File
@@ -18,13 +18,19 @@
# with Gurer's observations. # with Gurer's observations.
"""Specfile module is our handler for PSPEC files. PSPEC (PISI SPEC) """
Specfile module is our handler for PSPEC files. PSPEC (PISI SPEC)
files are specification files for PISI source packages. This module files are specification files for PISI source packages. This module
provides read and write access to PSPEC files.""" provides read and write access to PSPEC files.
"""
# standard python modules # standard python modules
from os.path import basename from os.path import basename
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
# pisi modules # pisi modules
import pisi import pisi
from pisi.xmlext import * from pisi.xmlext import *
@@ -77,9 +83,9 @@ class AdditionalFileInfo:
def has_errors(self): def has_errors(self):
err = Checks() err = Checks()
if not self.filename: if not self.filename:
err.add("AdditionalFile should have file name string") err.add(_("AdditionalFile should have file name string"))
if not self.target: if not self.target:
err.add("AdditionalFile should have a target attribute") err.add(_("AdditionalFile should have a target attribute"))
return err.list return err.list
def __str__(self): def __str__(self):
@@ -116,7 +122,7 @@ class PatchInfo:
def has_errors(self): def has_errors(self):
if not self.filename: if not self.filename:
return [ "Patch should have a filename string" ] return [ _("Patch should have a filename string") ]
return None return None
def __str__(self): def __str__(self):
@@ -175,7 +181,7 @@ class PathInfo:
def has_errors(self): def has_errors(self):
if not self.pathname: if not self.pathname:
return [ "Path tag should have a name string" ] return [ _("Path tag should have a name string") ]
return None return None
def __str__(self): def __str__(self):
@@ -197,7 +203,7 @@ class ComarProvide:
def has_errors(self): def has_errors(self):
if not self.om or not self.script: if not self.om or not self.script:
return [ "COMAR provide should have something :)" ] return [ _("COMAR provide should have something :)") ]
return None return None
def __str__(self): def __str__(self):
@@ -267,11 +273,11 @@ class SourceInfo:
err.has_tag(self.packager, "Source", "Packager") err.has_tag(self.packager, "Source", "Packager")
err.has_tag(self.license, "Source", "License") err.has_tag(self.license, "Source", "License")
if (not self.archiveUri) or (not self.archiveType): if (not self.archiveUri) or (not self.archiveType):
err.add("Source archive URI and type should be given") err.add(_("Source archive URI and type should be given"))
if not self.archiveSHA1: if not self.archiveSHA1:
errd.add("Source archive should have a SHA1 sum") errd.add(_("Source archive should have a SHA1 sum"))
if len(self.history) <= 0: if len(self.history) <= 0:
err.add("Source needs some education about History :)") err.add(_("Source needs some education in History :)"))
err.join(self.packager.has_errors()) err.join(self.packager.has_errors())
for update in self.history: for update in self.history:
@@ -347,7 +353,7 @@ class PackageInfo:
err.has_tag(self.description, "Package", "Description") err.has_tag(self.description, "Package", "Description")
err.has_tag(self.license, "Package", "License") err.has_tag(self.license, "Package", "License")
if len(self.paths) <= 0: if len(self.paths) <= 0:
err.add("Package should have some files") err.add(_("Package should have some files"))
for path in self.paths: for path in self.paths:
err.join(path.has_errors()) err.join(path.has_errors())
@@ -404,7 +410,7 @@ class SpecFile(XmlFile):
e = "" e = ""
for x in errs: for x in errs:
e += x + "\n" e += x + "\n"
raise XmlError("File '%s' has errors:\n%s" % (filename, e)) raise XmlError(_("File '%s' has errors:\n%s") % (filename, e))
def override_tags(self): def override_tags(self):
"""Override tags from Source in Packages. Some tags in Packages """Override tags from Source in Packages. Some tags in Packages
@@ -457,7 +463,7 @@ class SpecFile(XmlFile):
err = Checks() err = Checks()
err.join(self.source.has_errors()) err.join(self.source.has_errors())
if len(self.packages) <= 0: if len(self.packages) <= 0:
errs.add("There should be at least one Package section") errs.add(_("There should be at least one Package section"))
for p in self.packages: for p in self.packages:
err.join(p.has_errors()) err.join(p.has_errors())
return err.list return err.list
+5 -1
View File
@@ -13,6 +13,10 @@
from urlparse import urlparse from urlparse import urlparse
from os.path import basename from os.path import basename
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi.util as util import pisi.util as util
class URI(object): class URI(object):
@@ -69,7 +73,7 @@ class URI(object):
def set_auth_info(self, authTuple): def set_auth_info(self, authTuple):
if not isinstance(authTuple, tuple): if not isinstance(authTuple, tuple):
raise Exception, "setAuthInfo needs a tuple (user, pass)" raise Exception, _("setAuthInfo needs a tuple (user, pass)")
self.__authinfo = authTuple self.__authinfo = authTuple
def auth_info(self): def auth_info(self):
+15 -12
View File
@@ -24,14 +24,18 @@ import sha
import shutil import shutil
import statvfs import statvfs
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
# pisi modules # pisi modules
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
class FileError(pisi.Error): class Error(pisi.Error):
pass pass
class UtilError(pisi.Error): class FileError(Error):
pass pass
@@ -58,7 +62,7 @@ class Checks:
if not var: if not var:
if not self.list: if not self.list:
self.list = [] self.list = []
self.list.append("%s section should have a '%s' tag" % (section, name)) self.list.append(_("%s section should have a '%s' tag") % (section, name))
######################### #########################
@@ -115,17 +119,16 @@ def remove_prefix(a,b):
def run_batch(cmd): def run_batch(cmd):
"""run command non-interactively and report return value and output""" """run command non-interactively and report return value and output"""
ui.info('running ' + cmd) ui.info(_('running ') + cmd)
a = os.popen(cmd) a = os.popen(cmd)
lines = a.readlines() lines = a.readlines()
ret = a.close() ret = a.close()
ui.debug('return value ' + ret) ui.debug(_('return value ') + ret)
successful = ret == None successful = ret == None
if not successful: if not successful:
ui.error('ERROR: executing command: ' + cmd + '\n' + strlist(lines)) ui.error(_('Failed command: %s') % cmd + strlist(lines))
return (successful,lines) return (successful,lines)
def xterm_title(message): def xterm_title(message):
"""sets message as a console window's title""" """sets message as a console window's title"""
if os.environ.has_key("TERM") and sys.stderr.isatty(): if os.environ.has_key("TERM") and sys.stderr.isatty():
@@ -230,7 +233,7 @@ def copy_file(src,dest):
def get_file_hashes(top, exclude_prefix=None, removePrefix=None): def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
"""Generator function iterates over a toplevel path and returns the """Generator function iterates over a toplevel path and returns the
(filePath, sha1Hash) tuple for all files. If excludePrefixes list (filePath, sha1Hash) tuples for all files. If excludePrefixes list
is given as a parameter, function will exclude the filePaths is given as a parameter, function will exclude the filePaths
matching those prefixes. The removePrefix string parameter will be matching those prefixes. The removePrefix string parameter will be
used to remove prefix from filePath while matching excludes, if used to remove prefix from filePath while matching excludes, if
@@ -346,8 +349,8 @@ def do_patch(sourceDir, patchFile, level, target = ''):
o = p.readlines() o = p.readlines()
retval = p.close() retval = p.close()
if retval: if retval:
raise UtilError("ERROR: patch (%s) failed: %s" % (patchFile, raise Error(_("ERROR: patch (%s) failed: %s") % (patchFile,
strlist (o))) strlist (o)))
os.chdir(cwd) os.chdir(cwd)
@@ -379,7 +382,7 @@ def strip_file(filepath):
p = os.popen("strip %s %s" %(flags, f)) p = os.popen("strip %s %s" %(flags, f))
ret = p.close() ret = p.close()
if ret: if ret:
ctx.ui.warning("strip command failed for file '%s'!" % f) ctx.ui.warning(_("strip command failed for file '%s'!") % f)
if "current ar archive" in o: if "current ar archive" in o:
run_strip(filepath, "-g") run_strip(filepath, "-g")
@@ -406,7 +409,7 @@ def clean_locks(top = '.'):
for fn in files: for fn in files:
if fn.endswith('.lock'): if fn.endswith('.lock'):
path = os.path.join(root, fn) path = os.path.join(root, fn)
ctx.ui.info('Removing lock %s', path) ctx.ui.info(_('Removing lock %s'), path)
os.unlink(path) os.unlink(path)
######################################## ########################################
-4
View File
@@ -17,7 +17,6 @@ import re
import pisi.util as util import pisi.util as util
# Basic rule is: # Basic rule is:
# p > (no suffix) > rc > pre > beta > alpha # p > (no suffix) > rc > pre > beta > alpha
keywords = {"alpha": 0, keywords = {"alpha": 0,
@@ -35,7 +34,6 @@ def has_keyword(versionitem):
return False return False
class VersionItem: class VersionItem:
_keyword = "NOKEY" _keyword = "NOKEY"
_value = 0 _value = 0
@@ -157,5 +155,3 @@ class Version:
def __ge__(self,rhs): def __ge__(self,rhs):
return self.pred(rhs, lambda x,y: x>=y) return self.pred(rhs, lambda x,y: x>=y)
+5 -1
View File
@@ -18,6 +18,10 @@
an old library an old library
""" """
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
class XmlError(pisi.Error): class XmlError(pisi.Error):
@@ -50,7 +54,7 @@ def getNodeText(node, tagpath = ""):
# in any case, strip whitespaces... # in any case, strip whitespaces...
return child.data.strip() return child.data.strip()
else: else:
raise XmlError("getNodeText: Expected text node, got something else!") raise XmlError(_("getNodeText: Expected text node, got something else!"))
def getChildText(node_s, tagpath): def getChildText(node_s, tagpath):
"""get the text of a child at the end of a tag path""" """get the text of a child at the end of a tag path"""
+32 -31
View File
@@ -73,27 +73,19 @@ class LocalText(object):
nodes = getAllNodes(node, self.tag) nodes = getAllNodes(node, self.tag)
if not nodes: if not nodes:
if self.req == mandatory: if self.req == mandatory:
errs.append("LocalText '%s' should have at least one '%s' tag\n" % errs.append(_("LocalText '%s' should have at least one '%s' tag\n") %
self.tag) self.tag)
else: else:
for node in nodes: for node in nodes:
lang = getNodeAttribute(node, "xml:lang") lang = getNodeAttribute(node, "xml:lang")
c = getNodeText(node) c = getNodeText(node)
if not c: if not c:
errs.append("'%s' language of tag '%s' should have some text data\n" % errs.append(_("'%s' language of tag '%s' should have some text data\n") %
(lang, self.tag)) (lang, self.tag))
# FIXME: check for dups and 'en' # FIXME: check for dups and 'en'
if not lang: if not lang:
lang = 'en' lang = 'en'
self.locs[lang] = c self.locs[lang] = c
# FIXME: return full list too
#L = language
#if not self.locs.has_key(L):
# L = 'en'
#if not self.locs.has_key(L):
# #errs.append("Tag '%s' should have an English version\n" % d[2])
# return ""
#retur
def encode(self, xml, node, errs): def encode(self, xml, node, errs):
for key in self.locs.iterkeys(): for key in self.locs.iterkeys():
@@ -106,6 +98,15 @@ class LocalText(object):
def format(self, errs): def format(self, errs):
return '' return ''
# FIXME: use something like the below to return a default
#L = language
#if not self.locs.has_key(L):
# L = 'en'
#if not self.locs.has_key(L):
# #errs.append("Tag '%s' should have an English version\n" % d[2])
# return ""
#retur
class autoxml(type): class autoxml(type):
"""High-level automatic XML transformation interface for xmlfile. """High-level automatic XML transformation interface for xmlfile.
The idea is to declare a class for each XML tag. Inside the The idea is to declare a class for each XML tag. Inside the
@@ -283,7 +284,7 @@ class autoxml(type):
elif type(tag_type) is autoxml or type(tag_type) is types.TypeType: elif type(tag_type) is autoxml or type(tag_type) is types.TypeType:
return cls.gen_class_tag(tag, spec) return cls.gen_class_tag(tag, spec)
else: else:
raise Error('gen_tag: unrecognized tag type %s in spec' % raise Error(_('gen_tag: unrecognized tag type %s in spec') %
str(tag_type)) str(tag_type))
def gen_named_comp(cls, token, spec, anonfuns): def gen_named_comp(cls, token, spec, anonfuns):
@@ -316,7 +317,7 @@ class autoxml(type):
return '%s: %s\n' % (token, format_a(value, errs)) return '%s: %s\n' % (token, format_a(value, errs))
else: else:
if req == mandatory: if req == mandatory:
raise Error('Mandatory variable %s not available' % name) raise Error(_('Mandatory variable %s not available') % name)
return '' return ''
return (init, decode, encode, format) return (init, decode, encode, format)
@@ -371,11 +372,11 @@ class autoxml(type):
value = autoxml.basic_cons_map[token_type](text) value = autoxml.basic_cons_map[token_type](text)
except Error: except Error:
value = None value = None
errs.append('Type mismatch: read text cannot be decoded') errs.append(_('Type mismatch: read text cannot be decoded'))
return value return value
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory token %s not available' % token) errs.append(_('Mandatory token %s not available') % token)
return None return None
def encode(xml, node, value, errs): def encode(xml, node, value, errs):
@@ -384,7 +385,7 @@ class autoxml(type):
writetext(xml, node, token, str(value)) writetext(xml, node, token, str(value))
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
def format(value, errs): def format(value, errs):
"""format value for pretty printing""" """format value for pretty printing"""
@@ -412,10 +413,10 @@ class autoxml(type):
obj.decode(node, errs) obj.decode(node, errs)
return obj return obj
except Error: except Error:
errs.append('Type mismatch: DOM cannot be decoded') errs.append(_('Type mismatch: DOM cannot be decoded'))
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
return None return None
def encode(xml, node, obj, errs): def encode(xml, node, obj, errs):
@@ -428,17 +429,17 @@ class autoxml(type):
except Error: except Error:
if req == mandatory: if req == mandatory:
# note: we can receive an error if obj has no content # note: we can receive an error if obj has no content
errs.append('Object cannot be encoded') errs.append(_('Object cannot be encoded'))
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
def format(obj, errs): def format(obj, errs):
try: try:
return obj.format(errs) return obj.format(errs)
except Error: except Error:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
else: else:
return '' return ''
return (init, decode, encode, format) return (init, decode, encode, format)
@@ -449,7 +450,7 @@ class autoxml(type):
#head, last = cls.tagpath_head_last(path) #head, last = cls.tagpath_head_last(path)
if len(tag_type) != 1: if len(tag_type) != 1:
raise Error('List type must contain only one element') raise Error(_('List type must contain only one element'))
x = cls.gen_tag(comp_tag, [tag_type[0], mandatory]) x = cls.gen_tag(comp_tag, [tag_type[0], mandatory])
(init_item, decode_item, encode_item, format_item) = x (init_item, decode_item, encode_item, format_item) = x
@@ -462,7 +463,7 @@ class autoxml(type):
nodes = getAllNodes(node, tag + '/' + comp_tag) nodes = getAllNodes(node, tag + '/' + comp_tag)
#print node, tag + '/' + comp_tag, nodes #print node, tag + '/' + comp_tag, nodes
if len(nodes) is 0 and req is mandatory: if len(nodes) is 0 and req is mandatory:
errs.append('Mandatory list empty') errs.append(_('Mandatory list empty'))
for node in nodes: for node in nodes:
dummy = node.ownerDocument.createElement("Dummy") dummy = node.ownerDocument.createElement("Dummy")
dummy.appendChild(node) dummy.appendChild(node)
@@ -477,7 +478,7 @@ class autoxml(type):
node.appendChild(listnode) node.appendChild(listnode)
else: else:
if req is mandatory: if req is mandatory:
errs.append('Mandatory list empty') errs.append(_('Mandatory list empty'))
def format(l, errs): def format(l, errs):
#print 'format:', name #print 'format:', name
@@ -513,10 +514,10 @@ class autoxml(type):
obj.decode(node, errs) obj.decode(node, errs)
return obj return obj
except Error: except Error:
errs.append('Type mismatch: DOM cannot be decoded') errs.append(_('Type mismatch: DOM cannot be decoded'))
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
return None return None
def encode(xml, node, obj, errs): def encode(xml, node, obj, errs):
@@ -527,17 +528,17 @@ class autoxml(type):
except Error: except Error:
if req == mandatory: if req == mandatory:
# note: we can receive an error if obj has no content # note: we can receive an error if obj has no content
errs.append('Object cannot be encoded') errs.append(_('Object cannot be encoded'))
else: else:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
def format(obj, errs): def format(obj, errs):
try: try:
return obj.format(errs) return obj.format(errs)
except Error: except Error:
if req == mandatory: if req == mandatory:
errs.append('Mandatory argument not available') errs.append(_('Mandatory argument not available'))
else: else:
return '' return ''
return (init, decode, encode, format) return (init, decode, encode, format)
@@ -572,8 +573,8 @@ class XmlFile(object):
try: try:
self.dom = mdom.parse(fileName) self.dom = mdom.parse(fileName)
except ExpatError, inst: except ExpatError, inst:
raise Error("File '%s' has invalid XML: %s\n" % (fileName, raise Error(_("File '%s' has invalid XML: %s\n") % (fileName,
str(inst))) str(inst)))
def writexml(self, fileName): def writexml(self, fileName):
f = codecs.open(fileName,'w', "utf-8") f = codecs.open(fileName,'w', "utf-8")
@@ -583,7 +584,7 @@ class XmlFile(object):
def verifyRootTag(self): def verifyRootTag(self):
actual_roottag = self.rootNode().tagName actual_roottag = self.rootNode().tagName
if actual_roottag != self.rootTag: if actual_roottag != self.rootTag:
raise Error("Root tagname %s not identical to %s as expected " % raise Error(_("Root tagname %s not identical to %s as expected") %
(actual_roottag, self.rootTag) ) (actual_roottag, self.rootTag) )
# construction helpers # construction helpers