pisi'yi çalışır hale getirme operasyonu!

- yeni context'in kullanılmasını sağla (kod çalışsın diye, context'i bu şekilde bırakmak güzel bir kod oluşturmuyor).
- düzeltirken hatırlamadığım onlarca hata...
This commit is contained in:
Barış Metin
2005-08-30 18:44:33 +00:00
parent 63c80a12d9
commit 47950a019c
34 changed files with 291 additions and 256 deletions
+4 -1
View File
@@ -21,8 +21,11 @@ from pisi.cli.pisicli import PisiCLI
def handle_exception(exception, value, tb): def handle_exception(exception, value, tb):
import traceback import traceback
import exceptions import exceptions
import pisi.ui
from pisi.xmlext import XmlError from pisi.xmlext import XmlError
from pisi.ui import ui
ui = pisi.ui.CLI()
if exception == exceptions.KeyboardInterrupt: if exception == exceptions.KeyboardInterrupt:
ui.error(_("\nKeyboardInterrupt: Exiting...\n")) ui.error(_("\nKeyboardInterrupt: Exiting...\n"))
+7 -8
View File
@@ -14,8 +14,7 @@
from os import getenv, environ from os import getenv, environ
# Pisi-Core Modules # Pisi-Core Modules
import pisi.config import pisi.context as ctx
import pisi.constants
# Set individual information, that are generally needed for ActionsAPI # Set individual information, that are generally needed for ActionsAPI
@@ -24,7 +23,7 @@ def exportFlags():
# Build systems depend on these environment variables. That is why # Build systems depend on these environment variables. That is why
# we export them instead of using as (instance) variables. # we export them instead of using as (instance) variables.
values = pisi.config.config.values values = ctx.config.values
environ['HOST'] = values.build.host environ['HOST'] = values.build.host
environ['CFLAGS'] = values.build.cflags environ['CFLAGS'] = values.build.cflags
environ['CXXFLAGS'] = values.build.cxxflags environ['CXXFLAGS'] = values.build.cxxflags
@@ -75,9 +74,9 @@ class Dirs:
kde = '/usr/kde/3.4' kde = '/usr/kde/3.4'
qt = '/usr/qt/3' qt = '/usr/qt/3'
class Variables(pisi.config.Config): def initVariables():
const = pisi.constants.const ctx.env = Env()
env = Env() ctx.dirs = Dirs()
dirs = Dirs() return ctx
glb = Variables() glb = initVariables()
+27 -29
View File
@@ -26,8 +26,8 @@ import pisi.dependency as dependency
import pisi.pgraph as pgraph import pisi.pgraph as pgraph
import pisi.operations as operations import pisi.operations as operations
import pisi.packagedb as packagedb import pisi.packagedb as packagedb
from pisi.repodb import repodb import pisi.repodb
from pisi.installdb import installdb import pisi.installdb
from pisi.index import Index from pisi.index import Index
class Error(pisi.Error): class Error(pisi.Error):
@@ -50,14 +50,12 @@ def init(database = True, options = None, ui = None ):
# initialize repository databases # initialize repository databases
if database: if database:
import pisi.repodb ctx.repodb = pisi.repodb.init()
pisi.repodb.init() ctx.installdb = pisi.installdb.init()
import pisi.installdb
pisi.installdb.init() packagedb.init()
import pisi.packagedb # import pisi.sourcedb
pisi.packagedb.init() # pisi.sourcedb.init()
import pisi.sourcedb
pisi.sourcedb.init()
def install(packages): def install(packages):
"""install a list of packages (either files/urls, or names)""" """install a list of packages (either files/urls, or names)"""
@@ -68,7 +66,7 @@ def install(packages):
try: try:
# determine if this is a list of files/urls or names # determine if this is a list of files/urls or names
if packages[0].endswith(const.package_prefix): # they all have to! if packages[0].endswith(ctx.const.package_prefix): # they all have to!
install_pkg_files(packages) install_pkg_files(packages)
else: else:
install_pkg_names(packages) install_pkg_names(packages)
@@ -92,7 +90,7 @@ def install_pkg_files(package_URIs):
ctx.ui.debug('A = %s\n' % str(package_URIs)) ctx.ui.debug('A = %s\n' % str(package_URIs))
for x in package_URIs: for x in package_URIs:
if not x.endswith(const.package_prefix): if not x.endswith(ctx.const.package_prefix):
ctx.ui.error('Mixing file names and package names not supported YET.\n') ctx.ui.error('Mixing file names and package names not supported YET.\n')
return False return False
@@ -235,15 +233,15 @@ def upgrade_pkg_names(A):
"""Re-installs packages from the repository, trying to perform """Re-installs packages from the repository, trying to perform
a maximum number of upgrades.""" a maximum number of upgrades."""
ignore_build = config.options and config.options.ignore_build_no ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
# filter packages that are not installed # filter packages that are not installed
Ap = [] Ap = []
for x in A: for x in A:
if not installdb.is_installed(x): if not ctx.installdb.is_installed(x):
ctx.ui.info('Package %s is not installed.\n' % x) ctx.ui.info('Package %s is not installed.\n' % x)
continue continue
(version, release, build) = installdb.get_version(x) (version, release, build) = ctx.installdb.get_version(x)
pkg = packagedb.get_package(x) pkg = packagedb.get_package(x)
if ignore_build or (not build): if ignore_build or (not build):
if release < pkg.release: if release < pkg.release:
@@ -283,8 +281,8 @@ def upgrade_pkg_names(A):
print 'checking ', dep print 'checking ', dep
# add packages that can be upgraded # add packages that can be upgraded
if dependency.repo_satisfies_dep(dep): if dependency.repo_satisfies_dep(dep):
if installdb.is_installed(dep.package): if ctx.installdb.is_installed(dep.package):
(v,r,b) = installdb.get_version(dep.package) (v,r,b) = ctx.installdb.get_version(dep.package)
rep_pkg = packagedb.get_package(dep.package) rep_pkg = packagedb.get_package(dep.package)
(vp,rp,bp) = (rep_pkg.version, rep_pkg.release, (vp,rp,bp) = (rep_pkg.version, rep_pkg.release,
rep_pkg.build) rep_pkg.build)
@@ -313,7 +311,7 @@ def remove(A):
# filter packages that are not installed # filter packages that are not installed
Ap = [] Ap = []
for x in A: for x in A:
if installdb.is_installed(x): if ctx.installdb.is_installed(x):
Ap.append(x) Ap.append(x)
else: else:
ctx.ui.info('Package %s does not exist. Cannot remove.\n' % x) ctx.ui.info('Package %s does not exist. Cannot remove.\n' % x)
@@ -328,7 +326,7 @@ def remove(A):
G_f = pgraph.PGraph(packagedb) # construct G_f G_f = pgraph.PGraph(packagedb) # construct G_f
# find the "install closure" graph of G_f by package # find the (install closure) graph of G_f by package
# set A using packagedb # set A using packagedb
print A print A
for x in A: for x in A:
@@ -353,7 +351,7 @@ def remove(A):
order = G_f.topological_sort() order = G_f.topological_sort()
print order print order
for x in order: for x in order:
if installdb.is_installed(x): if ctx.installdb.is_installed(x):
operations.remove_single(x) operations.remove_single(x)
else: else:
ctx.ui.info('Package %s is not installed. Cannot remove.\n' % x) ctx.ui.info('Package %s is not installed. Cannot remove.\n' % x)
@@ -367,7 +365,7 @@ def configure_pending():
pass pass
def info(package): def info(package):
if package.endswith(const.package_prefix): if package.endswith(ctx.const.package_prefix):
return info_file(package) return info_file(package)
else: else:
return info_name(package) return info_name(package)
@@ -375,10 +373,10 @@ def info(package):
def info_file(package): def info_file(package):
from package import Package from package import Package
if not os.path.exist(package): if not os.path.exists(package):
raise Error ('File %s not found' % package) raise Error ('File %s not found' % package)
package = Package(package_name) package = Package(package)
package.read() package.read()
return package.metadata, package.files return package.metadata, package.files
@@ -392,8 +390,8 @@ def info_name(package_name):
#FIXME: get it from sourcedb #FIXME: get it from sourcedb
metadata.source = None metadata.source = None
#TODO: fetch the files from server if possible #TODO: fetch the files from server if possible
if installdb.is_installed(package.name): if ctx.installdb.is_installed(package.name):
files = installdb.files(package.name) files = ctx.installdb.files(package.name)
else: else:
files = None files = None
return metadata, files return metadata, files
@@ -414,11 +412,11 @@ class Repo:
def add_repo(name, indexuri): def add_repo(name, indexuri):
repo = Repo(URI(indexuri)) repo = Repo(URI(indexuri))
repodb.add_repo(name, repo) ctx.repodb.add_repo(name, repo)
def remove_repo(name): def remove_repo(name):
if repodb.has_repo(name): if ctx.repodb.has_repo(name):
repodb.remove_repo(name) ctx.repodb.remove_repo(name)
else: else:
ctx.ui.error('* Repository %s does not exist. Cannot remove.\n' ctx.ui.error('* Repository %s does not exist. Cannot remove.\n'
% name) % name)
@@ -427,7 +425,7 @@ def update_repo(repo):
ctx.ui.info('* Updating repository: %s\n' % repo) ctx.ui.info('* Updating repository: %s\n' % repo)
index = Index() index = Index()
index.read(repodb.get_repo(repo).indexuri.get_uri(), repo) index.read(ctx.repodb.get_repo(repo).indexuri.get_uri(), repo)
index.update_db(repo) index.update_db(repo)
ctx.ui.info('* Package database updated.\n') ctx.ui.info('* Package database updated.\n')
+43 -44
View File
@@ -24,7 +24,6 @@ _ = __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
from pisi.context import BuildContext
from pisi.sourcearchive import SourceArchive from pisi.sourcearchive import SourceArchive
from pisi.files import Files, FileInfo from pisi.files import Files, FileInfo
from pisi.metadata import MetaData from pisi.metadata import MetaData
@@ -105,23 +104,23 @@ class BuildContext(object):
packageDir = self.spec.source.name + '-' + \ packageDir = self.spec.source.name + '-' + \
self.spec.source.version + '-' + self.spec.source.release self.spec.source.version + '-' + self.spec.source.release
return config.destdir + config.values.dirs.tmp_dir \ return ctx.config.destdir + ctx.config.values.dirs.tmp_dir \
+ '/' + packageDir + '/' + packageDir
def pkg_work_dir(self): def pkg_work_dir(self):
return self.pkg_dir() + const.work_dir_suffix return self.pkg_dir() + ctx.const.work_dir_suffix
def pkg_install_dir(self): def pkg_install_dir(self):
return self.pkg_dir() + const.install_dir_suffix return self.pkg_dir() + ctx.const.install_dir_suffix
class PisiBuild: class PisiBuild:
"""PisiBuild class, provides the package build and creation routines""" """PisiBuild class, provides the package build and creation routines"""
def __init__(self, pspec): def __init__(self, pspec):
self.ctx = BuildContext(pspec) self.bctx = BuildContext(pspec)
self.pspecDir = os.path.dirname(os.path.realpath(self.ctx.pspecfile)) self.pspecDir = os.path.dirname(os.path.realpath(self.bctx.pspecfile))
self.spec = self.ctx.spec self.spec = self.bctx.spec
self.sourceArchive = SourceArchive(self.ctx) self.sourceArchive = SourceArchive(self.bctx)
self.set_environment_vars() self.set_environment_vars()
@@ -166,9 +165,9 @@ class PisiBuild:
def set_environment_vars(self): def set_environment_vars(self):
"""Sets the environment variables for actions API to use""" """Sets the environment variables for actions API to use"""
evn = { evn = {
"PKG_DIR": self.ctx.pkg_dir(), "PKG_DIR": self.bctx.pkg_dir(),
"WORK_DIR": self.ctx.pkg_work_dir(), "WORK_DIR": self.bctx.pkg_work_dir(),
"INSTALL_DIR": self.ctx.pkg_install_dir(), "INSTALL_DIR": self.bctx.pkg_install_dir(),
"SRC_NAME": self.spec.source.name, "SRC_NAME": self.spec.source.name,
"SRC_VERSION": self.spec.source.version, "SRC_VERSION": self.spec.source.version,
"SRC_RELEASE": self.spec.source.release "SRC_RELEASE": self.spec.source.release
@@ -179,40 +178,40 @@ class PisiBuild:
ctx.ui.info(_("Fetching source from: %s\n") % self.spec.source.archiveUri) ctx.ui.info(_("Fetching source from: %s\n") % self.spec.source.archiveUri)
self.sourceArchive.fetch() self.sourceArchive.fetch()
ctx.ui.info(_("Source archive is stored: %s/%s\n") ctx.ui.info(_("Source archive is stored: %s/%s\n")
%(config.archives_dir(), self.spec.source.archiveName)) %(ctx.config.archives_dir(), self.spec.source.archiveName))
def unpack_source_archive(self): def unpack_source_archive(self):
ctx.ui.info(_("Unpacking archive...")) ctx.ui.info(_("Unpacking archive..."))
self.sourceArchive.unpack() self.sourceArchive.unpack()
ctx.ui.info(_(" unpacked (%s)\n") % self.ctx.pkg_work_dir()) ctx.ui.info(_(" unpacked (%s)\n") % self.bctx.pkg_work_dir())
self.set_state("unpacked") self.set_state("unpacked")
def run_setup_action(self): def run_setup_action(self):
# Run configure, build and install phase # Run configure, build and install phase
ctx.ui.action(_("Setting up source...\n")) ctx.ui.action(_("Setting up source...\n"))
self.run_action_function(const.setup_func) self.run_action_function(ctx.const.setup_func)
self.set_state("setupaction") self.set_state("setupaction")
def run_build_action(self): def run_build_action(self):
ctx.ui.action(_("Building source...\n")) ctx.ui.action(_("Building source...\n"))
self.run_action_function(const.build_func) self.run_action_function(ctx.const.build_func)
self.set_state("buildaction") self.set_state("buildaction")
def run_install_action(self): def run_install_action(self):
ctx.ui.action(_("Installing...\n")) ctx.ui.action(_("Installing...\n"))
# Before install make sure install_dir is clean # Before install make sure install_dir is clean
if os.path.exists(self.ctx.pkg_install_dir()): if os.path.exists(self.bctx.pkg_install_dir()):
util.clean_dir(self.ctx.pkg_install_dir()) util.clean_dir(self.bctx.pkg_install_dir())
# install function is mandatory! # install function is mandatory!
self.run_action_function(const.install_func, True) self.run_action_function(ctx.const.install_func, True)
self.set_state("installaction") self.set_state("installaction")
def compile_action_script(self): def compile_action_script(self):
"""Compiles actions.py and sets the actionLocals and actionGlobals""" """Compiles actions.py and sets the actionLocals and actionGlobals"""
specdir = os.path.dirname(self.ctx.pspecfile) specdir = os.path.dirname(self.bctx.pspecfile)
scriptfile = os.path.join(specdir, const.actions_file) scriptfile = os.path.join(specdir, ctx.const.actions_file)
try: try:
localSymbols = globalSymbols = {} localSymbols = globalSymbols = {}
buf = open(scriptfile).read() buf = open(scriptfile).read()
@@ -235,7 +234,7 @@ class PisiBuild:
except KeyError: except KeyError:
workdir = self.spec.source.name + "-" + self.spec.source.version workdir = self.spec.source.name + "-" + self.spec.source.version
return os.path.join(self.ctx.pkg_work_dir(), workdir) return os.path.join(self.bctx.pkg_work_dir(), workdir)
def run_action_function(self, func, mandatory=False): def run_action_function(self, func, mandatory=False):
"""Calls the corresponding function in actions.py. """Calls the corresponding function in actions.py.
@@ -263,14 +262,14 @@ class PisiBuild:
def apply_patches(self): def apply_patches(self):
files_dir = os.path.abspath(os.path.join(self.pspecDir, files_dir = os.path.abspath(os.path.join(self.pspecDir,
const.files_dir)) ctx.const.files_dir))
for patch in self.spec.source.patches: for patch in self.spec.source.patches:
patchFile = os.path.join(files_dir, patch.filename) patchFile = os.path.join(files_dir, patch.filename)
if patch.compressionType: if patch.compressionType:
patchFile = util.uncompress(patchFile, patchFile = util.uncompress(patchFile,
compressType=patch.compressionType, compressType=patch.compressionType,
targetDir=config.tmp_dir()) targetDir=ctx.config.tmp_dir())
ctx.ui.action(_("* Applying patch: %s\n") % patch.filename) ctx.ui.action(_("* Applying patch: %s\n") % patch.filename)
util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target) util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target)
@@ -283,33 +282,33 @@ class PisiBuild:
metadata = MetaData() metadata = MetaData()
metadata.from_spec(self.spec.source, package) metadata.from_spec(self.spec.source, package)
metadata.package.distribution = config.values.general.distribution metadata.package.distribution = ctx.config.values.general.distribution
metadata.package.distributionRelease = config.values.general.distribution_release metadata.package.distributionRelease = ctx.config.values.general.distribution_release
metadata.package.architecture = "Any" metadata.package.architecture = "Any"
# FIXME: Bu hatalı. installsize'ı almak için tüm # FIXME: Bu hatalı. installsize'ı almak için tüm
# pkg_install_dir()'ın boyutunu hesaplayamayız. Bir source # pkg_install_dir()'ın boyutunu hesaplayamayız. Bir source
# birden fazla kaynak üretebilir. package.paths ile # birden fazla kaynak üretebilir. package.paths ile
# karşılaştırarak file listesinden boyutları hesaplatmalıyız. # karşılaştırarak file listesinden boyutları hesaplatmalıyız.
d = self.ctx.pkg_install_dir() d = self.bctx.pkg_install_dir()
size = util.dir_size(d) size = util.dir_size(d)
metadata.package.installedSize = str(size) metadata.package.installedSize = str(size)
# build no # build no
if config.options.ignore_build_no: if ctx.config.options.ignore_build_no:
metadata.package.build = None # means, build no information n/a metadata.package.build = None # means, build no information n/a
ctx.ui.warning('build number is not available.') ctx.ui.warning('build number is not available.')
else: else:
metadata.package.build = self.calc_build_no(metadata.package.name) metadata.package.build = self.calc_build_no(metadata.package.name)
metadata.write(os.path.join(self.ctx.pkg_dir(), const.metadata_xml)) metadata.write(os.path.join(self.bctx.pkg_dir(), ctx.const.metadata_xml))
self.metadata = metadata self.metadata = metadata
def gen_files_xml(self, package): def gen_files_xml(self, package):
"""Generetes files.xml using the path definitions in specfile and """Generetes files.xml using the path definitions in specfile and
generated files by the build system.""" generated files by the build system."""
files = Files() files = Files()
install_dir = self.ctx.pkg_install_dir() install_dir = self.bctx.pkg_install_dir()
collisions = check_path_collision(package, collisions = check_path_collision(package,
self.spec.packages) self.spec.packages)
if collisions: if collisions:
@@ -327,24 +326,24 @@ class PisiBuild:
d[frpath] = FileInfo(frpath, ftype, fsize, fhash) d[frpath] = FileInfo(frpath, ftype, fsize, fhash)
for (p, fileinfo) in d.iteritems(): for (p, fileinfo) in d.iteritems():
files.append(fileinfo) files.append(fileinfo)
files.write(os.path.join(self.ctx.pkg_dir(), const.files_xml)) files.write(os.path.join(self.bctx.pkg_dir(), ctx.const.files_xml))
self.files = files self.files = files
def calc_build_no(self, package_name): def calc_build_no(self, package_name):
"""Calculate build number""" """Calculate build number"""
# find previous build in config.options.output_dir # find previous build in ctx.config.options.output_dir
found = [] found = []
for root, dirs, files in os.walk(config.options.output_dir): for root, dirs, files in os.walk(ctx.config.options.output_dir):
for fn in files: for fn in files:
fn = fn.decode('utf-8') fn = fn.decode('utf-8')
if fn.startswith(package_name + '-') and \ if fn.startswith(package_name + '-') and \
fn.endswith(const.package_prefix): fn.endswith(ctx.const.package_prefix):
old_package_fn = os.path.join(root, fn) old_package_fn = os.path.join(root, fn)
ctx.ui.info('(found old version %s)' % old_package_fn) ctx.ui.info('(found old version %s)' % old_package_fn)
old_pkg = Package(old_package_fn, 'r') old_pkg = Package(old_package_fn, 'r')
from os.path import join from os.path import join
old_pkg.read(join(config.tmp_dir(), 'oldpkg')) old_pkg.read(join(ctx.config.tmp_dir(), 'oldpkg'))
old_build = old_pkg.metadata.package.build old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) ) found.append( (old_package_fn, old_build) )
if not found: if not found:
@@ -362,7 +361,7 @@ class PisiBuild:
# compare old files.xml with the new one.. # compare old files.xml with the new one..
old_pkg = Package(old_package_fn, 'r') old_pkg = Package(old_package_fn, 'r')
from os.path import join from os.path import join
old_pkg.read(join(config.tmp_dir(), 'oldpkg')) old_pkg.read(join(ctx.config.tmp_dir(), 'oldpkg'))
# FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
changed = False changed = False
@@ -405,11 +404,11 @@ class PisiBuild:
ctx.ui.action(_("** Building package %s\n") % package.name); ctx.ui.action(_("** Building package %s\n") % package.name);
ctx.ui.action(_("Generating %s...") % const.files_xml) ctx.ui.action(_("Generating %s...") % ctx.const.files_xml)
self.gen_files_xml(package) self.gen_files_xml(package)
ctx.ui.info(_(" done.\n")) ctx.ui.info(_(" done.\n"))
ctx.ui.action(_("Generating %s...") % const.metadata_xml) ctx.ui.action(_("Generating %s...") % ctx.const.metadata_xml)
self.gen_metadata_xml(package) self.gen_metadata_xml(package)
ctx.ui.info(_(" done.\n")) ctx.ui.info(_(" done.\n"))
@@ -424,29 +423,29 @@ class PisiBuild:
# add comar files to package # add comar files to package
os.chdir(self.pspecDir) os.chdir(self.pspecDir)
for pcomar in package.providesComar: for pcomar in package.providesComar:
fname = os.path.join(const.comar_dir, fname = os.path.join(ctx.const.comar_dir,
pcomar.script) pcomar.script)
pkg.add_to_package(fname) pkg.add_to_package(fname)
# store additional files # store additional files
install_dir = self.ctx.pkg_dir() + const.install_dir_suffix install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix
for afile in package.additionalFiles: for afile in package.additionalFiles:
src = os.path.join(const.files_dir, afile.filename) src = os.path.join(ctx.const.files_dir, afile.filename)
dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target)) dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
util.copy_file(src, dest) util.copy_file(src, dest)
if afile.permission: if afile.permission:
os.chmod(dest, int(afile.permission) | 0777) os.chmod(dest, int(afile.permission) | 0777)
# add xmls and files # add xmls and files
os.chdir(self.ctx.pkg_dir()) os.chdir(self.bctx.pkg_dir())
pkg.add_to_package(const.metadata_xml) pkg.add_to_package(ctx.const.metadata_xml)
pkg.add_to_package(const.files_xml) pkg.add_to_package(ctx.const.files_xml)
# Now it is time to add files to the packages using newly # Now it is time to add files to the packages using newly
# created files.xml # created files.xml
files = Files() files = Files()
files.read(const.files_xml) files.read(ctx.const.files_xml)
for finfo in files.list: for finfo in files.list:
pkg.add_to_package("install/" + finfo.path) pkg.add_to_package("install/" + finfo.path)
+9 -15
View File
@@ -15,6 +15,7 @@ from optparse import OptionParser
import pisi import pisi
import pisi.cli import pisi.cli
import pisi.context as ctx
from pisi.uri import URI from pisi.uri import URI
@@ -113,10 +114,8 @@ class Command(object):
"""initialize PiSi components""" """initialize PiSi components"""
# NB: command imports here or in the command class run fxns # NB: command imports here or in the command class run fxns
import pisi
import pisi.api import pisi.api
pisi.api.init(database, self.options) pisi.api.init(database, self.options)
import pisi.context as ctx
def finalize(self): def finalize(self):
"""do cleanup work for PiSi components""" """do cleanup work for PiSi components"""
@@ -227,7 +226,7 @@ fetch all necessary files and build the package for you.
return return
self.init() self.init()
ctx.ui.info('Output directory: %s\n' % config.options.output_dir) ctx.ui.info('Output directory: %s\n' % ctx.config.options.output_dir)
for arg in self.args: for arg in self.args:
pisi.api.build(arg, self.authInfo) pisi.api.build(arg, self.authInfo)
self.finalize() self.finalize()
@@ -372,8 +371,7 @@ Upgrade the entire system.
return return
self.init() self.init()
from pisi.installdb import installdb pisi.api.upgrade(ctx.installdb.list_installed())
pisi.api.upgrade(installdb.list_installed())
self.finalize() self.finalize()
@@ -503,15 +501,14 @@ Usage: list-installed
def run(self): def run(self):
self.init(True) self.init(True)
from pisi.installdb import installdb list = ctx.installdb.list_installed()
list = installdb.list_installed()
list.sort() list.sort()
if self.options.install_info: if self.options.install_info:
print 'Package Name |St| Version| Rel.| Build| Distro| Date' print 'Package Name |St| Version| Rel.| Build| Distro| Date'
print '========================================================================' print '========================================================================'
for pkg in list: for pkg in list:
package = pisi.packagedb.inst_packagedb.get_package(pkg) package = pisi.packagedb.inst_packagedb.get_package(pkg)
inst_info = installdb.get_info(pkg) inst_info = ctx.installdb.get_info(pkg)
if self.options.long: if self.options.long:
print package print package
print inst_info print inst_info
@@ -621,10 +618,9 @@ Lists currently tracked repositories.
def run(self): def run(self):
self.init() self.init()
from pisi.repodb import repodb for repo in ctx.repodb.list():
for repo in repodb.list():
print repo print repo
print ' ', repodb.get_repo(repo).indexuri.get_uri() print ' ', ctx.repodb.get_repo(repo).indexuri.get_uri()
self.finalize() self.finalize()
@@ -643,7 +639,6 @@ Gives a brief list of PiSi components published in the repository.
name = ("list-available", "la") name = ("list-available", "la")
def run(self): def run(self):
from pisi.repodb import repodb
self.init(True) self.init(True)
@@ -652,7 +647,7 @@ Gives a brief list of PiSi components published in the repository.
self.print_packages(arg) self.print_packages(arg)
else: else:
# print for all repos # print for all repos
for repo in repodb.list(): for repo in ctx.repodb.list():
ctx.ui.info("Repository : %s\n" % repo) ctx.ui.info("Repository : %s\n" % repo)
self.print_packages(repo) self.print_packages(repo)
self.finalize() self.finalize()
@@ -678,10 +673,9 @@ class ListPending(Command):
name = ("list-pending", "lp") name = ("list-pending", "lp")
def run(self): def run(self):
from pisi.installdb import installdb
self.init(True) self.init(True)
list = installdb.list_pending() list = ctx.installdb.list_pending()
list.sort() list.sort()
for p in list: for p in list:
print p print p
+3
View File
@@ -26,6 +26,9 @@ config = None
# default UI is CLI # default UI is CLI
ui = None # not now ui = None # not now
installdb = None
repodb = None
#def register(_impl): #def register(_impl):
# """ Register a UI implementation""" # """ Register a UI implementation"""
# ui = _impl # ui = _impl
+2 -1
View File
@@ -14,6 +14,7 @@
#import pisi.db as db #import pisi.db as db
import pisi.context as ctx import pisi.context as ctx
import pisi.packagedb as packagedb
from pisi.version import Version from pisi.version import Version
from pisi.xmlext import * from pisi.xmlext import *
from pisi.xmlfile import XmlFile from pisi.xmlfile import XmlFile
@@ -89,7 +90,7 @@ def installed_satisfies_dep(depinfo):
"""determine if a package in *repository* satisfies given """determine if a package in *repository* satisfies given
dependency spec""" dependency spec"""
pkg_name = depinfo.package pkg_name = depinfo.package
if not installdb.is_installed(pkg_name): if not ctx.installdb.is_installed(pkg_name):
return False return False
else: else:
pkg = packagedb.inst_packagedb.get_package(pkg_name) pkg = packagedb.inst_packagedb.get_package(pkg_name)
+2 -2
View File
@@ -23,8 +23,8 @@ from base64 import encodestring
# pisi modules # pisi modules
import pisi import pisi
import pisi.util as util import pisi.util as util
from pisi.uri import URI
import pisi.context as ctx import pisi.context as ctx
from pisi.uri import URI
class FetchError(pisi.Error): class FetchError(pisi.Error):
@@ -37,7 +37,7 @@ def fetch_url(url, dest, progress=None):
fetch.progress = progress fetch.progress = progress
fetch.fetch() fetch.fetch()
if progress: if progress:
ctx.ctx.ui.info('\n') ctx.ui.info('\n')
class Fetcher: class Fetcher:
+3 -3
View File
@@ -16,12 +16,12 @@
import os import os
from pisi.package import Package import pisi.context as ctx
from pisi.xmlfile import XmlFile
import pisi.metadata as metadata import pisi.metadata as metadata
import pisi.packagedb as packagedb import pisi.packagedb as packagedb
import pisi.context as ctx
import pisi.util as util import pisi.util as util
from pisi.package import Package
from pisi.xmlfile import XmlFile
from pisi.uri import URI from pisi.uri import URI
class Index(XmlFile): class Index(XmlFile):
+27 -28
View File
@@ -17,16 +17,15 @@
import os import os
import pisi import pisi
import pisi.context as ctx
import pisi.packagedb as packagedb
import pisi.dependency as dependency
import pisi.operations as operations
from pisi.specfile import * from pisi.specfile import *
from pisi.package import Package from pisi.package import Package
from pisi.ui import ui
from pisi.installdb import installdb
import pisi.packagedb as packagedb
from pisi.packagedb import inst_packagedb
import pisi.dependency as dependency
from pisi.metadata import MetaData from pisi.metadata import MetaData
from pisi.comariface import comard from pisi.comariface import comard
import pisi.operations as operations
#import conflicts #import conflicts
class InstallError(pisi.Error): class InstallError(pisi.Error):
@@ -45,7 +44,7 @@ class Installer:
def install(self, ask_reinstall = True): def install(self, ask_reinstall = True):
"entry point" "entry point"
ui.info('Installing %s, version %s, release %s, build %s\n' % ctx.ui.info('Installing %s, version %s, release %s, build %s\n' %
(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
@@ -72,12 +71,12 @@ class Installer:
# check conflicts # check conflicts
for pkg in self.metadata.package.conflicts: for pkg in self.metadata.package.conflicts:
if installdb.is_installed(self.pkginfo): if ctx.installdb.is_installed(self.pkginfo):
raise InstallError("Package conflicts " + pkg) raise InstallError("Package conflicts " + pkg)
# check dependencies # check dependencies
if not dependency.installable(self.pkginfo.name): if not dependency.installable(self.pkginfo.name):
ui.error('Dependencies for ' + self.pkginfo.name + ctx.ui.error('Dependencies for ' + self.pkginfo.name +
' not satisfied\n') ' not satisfied\n')
raise InstallError("Package not installable") raise InstallError("Package not installable")
@@ -86,12 +85,12 @@ class Installer:
pkg = self.pkginfo pkg = self.pkginfo
if installdb.is_installed(pkg.name): # is this a reinstallation? if ctx.installdb.is_installed(pkg.name): # is this a reinstallation?
(iversion, irelease, ibuild) = installdb.get_version(pkg.name) (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)
# determine if same version # determine if same version
same_ver = False same_ver = False
ignore_build = config.options and config.options.ignore_build_no ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
if (not ibuild) or (not pkg.build) or ignore_build: if (not ibuild) or (not pkg.build) or ignore_build:
# we don't look at builds to compare two package versions # we don't look at builds to compare two package versions
if pkg.version == iversion and pkg.release == irelease: if pkg.version == iversion and pkg.release == irelease:
@@ -102,21 +101,21 @@ class Installer:
if same_ver: if same_ver:
if self.ask_reinstall: if self.ask_reinstall:
if not ui.confirm('Re-install same version package?'): if not ctx.ui.confirm('Re-install same version package?'):
raise InstallError('Package re-install declined') raise InstallError('Package re-install declined')
else: else:
upgrade = False upgrade = False
# is this an upgrade? # is this an upgrade?
# determine and report the kind of upgrade: version, release, build # determine and report the kind of upgrade: version, release, build
if pkg.version > iversion: if pkg.version > iversion:
ui.info('Upgrading to new upstream version\n') ctx.ui.info('Upgrading to new upstream version\n')
upgrade = True upgrade = True
elif pkg.release > irelease: elif pkg.release > irelease:
ui.info('Upgrading to new distribution release\n') ctx.ui.info('Upgrading to new distribution release\n')
upgrade = True upgrade = True
elif ((not ignore_build) and ibuild and pkg.build elif ((not ignore_build) and ibuild and pkg.build
and pkg.build > ibuild): and pkg.build > ibuild):
ui.info('Upgrading to new distribution build\n') ctx.ui.info('Upgrading to new distribution build\n')
upgrade = True upgrade = True
# is this a downgrade? confirm this action. # is this a downgrade? confirm this action.
@@ -127,7 +126,7 @@ class Installer:
x = 'Downgrade to old distribution release?' x = 'Downgrade to old distribution release?'
else: else:
x = 'Downgrade to old distribution build?' x = 'Downgrade to old distribution build?'
if not ui.confirm(x): if not ctx.ui.confirm(x):
raise InstallError('Package downgrade declined') raise InstallError('Package downgrade declined')
# remove old package then # remove old package then
@@ -136,24 +135,24 @@ class Installer:
def extract_install(self): def extract_install(self):
"unzip package in place" "unzip package in place"
ui.info('Extracting files,\n') ctx.ui.info('Extracting files,\n')
self.package.extract_dir_flat('install', config.destdir) self.package.extract_dir_flat('install', ctx.config.destdir)
def store_pisi_files(self): def store_pisi_files(self):
"""put files.xml, metadata.xml, actions.py and COMAR scripts """put files.xml, metadata.xml, actions.py and COMAR scripts
somewhere in the file system. We'll need these in future...""" somewhere in the file system. We'll need these in future..."""
ui.info('Storing %s, ' % const.files_xml) ctx.ui.info('Storing %s, ' % ctx.const.files_xml)
self.package.extract_file(const.files_xml, self.package.pkg_dir()) self.package.extract_file(ctx.const.files_xml, self.package.pkg_dir())
ui.info('%s.\n' % const.metadata_xml) ctx.ui.info('%s.\n' % ctx.const.metadata_xml)
self.package.extract_file(const.metadata_xml, self.package.pkg_dir()) self.package.extract_file(ctx.const.metadata_xml, self.package.pkg_dir())
for pcomar in self.metadata.package.providesComar: for pcomar in self.metadata.package.providesComar:
fpath = os.path.join(const.comar_dir, pcomar.script) fpath = os.path.join(ctx.const.comar_dir, pcomar.script)
# comar prefix is added to the pkg_dir while extracting comar # comar prefix is added to the pkg_dir while extracting comar
# script file. so we'll use pkg_dir as destination. # script file. so we'll use pkg_dir as destination.
ui.info('Storing %s\n' % fpath) ctx.ui.info('Storing %s\n' % fpath)
self.package.extract_file(fpath, self.package.pkg_dir()) self.package.extract_file(fpath, self.package.pkg_dir())
def register_comar_scripts(self): def register_comar_scripts(self):
@@ -161,7 +160,7 @@ class Installer:
for pcomar in self.metadata.package.providesComar: for pcomar in self.metadata.package.providesComar:
scriptPath = os.path.join(self.package.comar_dir(),pcomar.script) scriptPath = os.path.join(self.package.comar_dir(),pcomar.script)
ui.info("Registering COMAR script %s\n" % pcomar.script) ctx.ui.info("Registering COMAR script %s\n" % pcomar.script)
# FIXME: We must check the result of the command (possibly # FIXME: We must check the result of the command (possibly
# with id?) # with id?)
if comard: if comard:
@@ -174,11 +173,11 @@ class Installer:
"update databases" "update databases"
# installdb # installdb
installdb.install(self.metadata.package.name, ctx.installdb.install(self.metadata.package.name,
self.metadata.package.version, self.metadata.package.version,
self.metadata.package.release, self.metadata.package.release,
self.metadata.package.build, self.metadata.package.build,
self.metadata.package.distribution) self.metadata.package.distribution)
# installed packages # installed packages
inst_packagedb.add_package(self.pkginfo) packagedb.inst_packagedb.add_package(self.pkginfo)
+11 -5
View File
@@ -76,8 +76,8 @@ class InstallDB:
def files_name(self, pkg, version, release): def files_name(self, pkg, version, release):
from os.path import join from os.path import join
pkg_dir = join(config.lib_dir(), pkg + '-' + version + '-' + release) pkg_dir = join(ctx.config.lib_dir(), pkg + '-' + version + '-' + release)
return join(pkg_dir, const.files_xml) return join(pkg_dir, ctx.const.files_xml)
def files(self, pkg): def files(self, pkg):
pkg = str(pkg) pkg = str(pkg)
@@ -133,7 +133,7 @@ class InstallDB:
pkg = str(pkg) pkg = str(pkg)
if self.is_installed(pkg): if self.is_installed(pkg):
raise InstallDBError("already installed") raise InstallDBError("already installed")
if config.options and config.options.ignore_comar: if ctx.config.options and ctx.config.options.ignore_comar:
state = 'ip' state = 'ip'
self.dp[pkg] = True self.dp[pkg] = True
else: else:
@@ -152,8 +152,14 @@ class InstallDB:
if self.d.has_key(pkg): if self.d.has_key(pkg):
del self.d[pkg] del self.d[pkg]
installdb = None
db = None
def init(): def init():
installdb = InstallDB() global db
if db:
return db
db = InstallDB()
return db
+2 -1
View File
@@ -20,6 +20,7 @@ import os
import fcntl import fcntl
import pisi import pisi
import pisi.context
class LockedDBShelf(shelve.DBShelf): class LockedDBShelf(shelve.DBShelf):
@@ -41,7 +42,7 @@ class LockedDBShelf(shelve.DBShelf):
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')
LockedDBShelf.open(self,filename, dbname, filetype, flags, mode) self.open(filename, dbname, filetype, flags, mode)
def open(self, filename, dbname, filetype, flags, mode): def open(self, filename, dbname, filetype, flags, mode):
pisi.util.check_dir(pisi.context.config.db_dir()) pisi.util.check_dir(pisi.context.config.db_dir())
+1 -2
View File
@@ -17,9 +17,8 @@
# Baris Metin <baris@uludag.org.tr # Baris Metin <baris@uludag.org.tr
import pisi.context as ctx import pisi.context as ctx
from pisi.xmlfile import *
import pisi.specfile as specfile import pisi.specfile as specfile
from pisi.xmlfile import *
from pisi.util import Checks from pisi.util import Checks
class SourceInfo: class SourceInfo:
+11 -13
View File
@@ -14,40 +14,39 @@ import os
import pisi import pisi
import pisi.context as ctx import pisi.context as ctx
from pisi.uri import URI
import pisi.util as util import pisi.util as util
import pisi.packagedb as packagedb import pisi.packagedb as packagedb
from pisi.uri import URI
# single package operations # single package operations
def remove_single(package_name): def remove_single(package_name):
"""Remove a single package""" """Remove a single package"""
from installdb import installdb
from comariface import comard from comariface import comard
inst_packagedb = packagedb.inst_packagedb inst_packagedb = packagedb.inst_packagedb
#TODO: check dependencies #TODO: check dependencies
ui.info('Removing package %s' % package_name) ctx.ui.info('Removing package %s' % package_name)
if not 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)
for fileinfo in installdb.files(package_name).list: for fileinfo in ctx.installdb.files(package_name).list:
fpath = os.path.join(config.destdir, fileinfo.path) fpath = os.path.join(ctx.config.destdir, fileinfo.path)
# TODO: We have to store configuration files for futher # TODO: We have to store configuration files for futher
# usage. Currently we'are doing it like rpm does, saving # usage. Currently we'are doing it like rpm does, saving
# with a prefix and leaving the user to edit it. In the future # with a prefix and leaving the user to edit it. In the future
# we'll have a plan for these configuration files. # we'll have a plan for these configuration files.
if fileinfo.type == const.conf: if fileinfo.type == ctx.const.conf:
os.rename(fpath, fpath + ".pisi") os.rename(fpath, fpath + ".pisi")
else: else:
os.unlink(fpath) os.unlink(fpath)
installdb.remove(package_name) ctx.installdb.remove(package_name)
packagedb.remove_package(package_name) packagedb.remove_package(package_name)
if comard: if comard:
# FIXME: (return value)... # FIXME: (return value)...
comard.remove(package_name) comard.remove(package_name)
ui.info('.\n') ctx.ui.info('.\n')
def install_single(pkg, upgrade = False): def install_single(pkg, upgrade = False):
"""install a single package from URI or ID""" """install a single package from URI or ID"""
@@ -71,8 +70,7 @@ def install_single_name(name, upgrade = False):
# find package in repository # find package in repository
repo = packagedb.which_repo(name) repo = packagedb.which_repo(name)
if repo: if repo:
from repodb import repodb repo = ctx.repodb.get_repo(repo)
repo = repodb.get_repo(repo)
pkg = packagedb.get_package(name) pkg = packagedb.get_package(name)
# FIXME: let pkg.packageURI be stored as URI type rather than string # FIXME: let pkg.packageURI be stored as URI type rather than string
@@ -83,12 +81,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()))
ui.debug("Package URI: %s\n" % pkg_path) ctx.ui.debug("Package URI: %s\n" % 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:
ui.error("Package %s not found in any active repository.\n" % pkg) ctx.ui.error("Package %s not found in any active repository.\n" % pkg)
# deneme, don't remove ulan # deneme, don't remove ulan
class AtomicOperation(object): class AtomicOperation(object):
+3 -3
View File
@@ -38,7 +38,7 @@ class Package:
if url.is_remote_file(): if url.is_remote_file():
from fetcher import fetch_url from fetcher import fetch_url
from ui import ui from ui import ui
dest = config.packages_dir() dest = ctx.config.packages_dir()
fetch_url(url, dest, ui.Progress) fetch_url(url, dest, ui.Progress)
self.filepath = join(dest, url.filename()) self.filepath = join(dest, url.filename())
@@ -83,7 +83,7 @@ class Package:
def read(self, outdir = None): def read(self, outdir = None):
if not outdir: if not outdir:
outdir = config.tmp_dir() outdir = ctx.config.tmp_dir()
# extract control files # extract control files
self.extract_PISI_files(outdir) self.extract_PISI_files(outdir)
@@ -103,7 +103,7 @@ class Package:
+ self.metadata.package.version + '-' \ + self.metadata.package.version + '-' \
+ self.metadata.package.release + self.metadata.package.release
return join( config.lib_dir(), packageDir) return join( ctx.config.lib_dir(), packageDir)
def comar_dir(self): def comar_dir(self):
return self.pkg_dir() + ctx.const.comar_dir_suffix return self.pkg_dir() + ctx.const.comar_dir_suffix
+8 -4
View File
@@ -43,8 +43,7 @@ class PackageDB(object):
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
from ui import ui ctx.ui.error("Another instance of PISI is running. Try later!\n")
ui.error("Another instance of PISI is running. Try later!\n")
sys.exit(1) sys.exit(1)
self.d = shelve.open(self.fname) self.d = shelve.open(self.fname)
self.dr = shelve.open(self.fname2) self.dr = shelve.open(self.fname2)
@@ -151,5 +150,10 @@ thirdparty_packagedb = None
inst_packagedb = None inst_packagedb = None
def init(): def init():
thirdparty_packagedb = PackageDB('thirdparty') global thirdparty_packagedb
inst_packagedb = PackageDB('installed') global inst_packagedb
if not thirdparty_packagedb:
thirdparty_packagedb = PackageDB('thirdparty')
if not inst_packagedb:
inst_packagedb = PackageDB('installed')
+11 -12
View File
@@ -11,9 +11,9 @@
# Author: Eray Ozkural # Author: Eray Ozkural
from bsddb import db from bsddb import db
import bsddb.dbshelve as shelve
import os, fcntl import os, fcntl
import pisi.lockeddbshelve as shelve
import pisi.context as ctx import pisi.context as ctx
import pisi.packagedb as packagedb import pisi.packagedb as packagedb
import pisi.util as util import pisi.util as util
@@ -22,10 +22,7 @@ from pisi.uri import URI
class RepoDB(object): class RepoDB(object):
"""RepoDB maps repo ids to repository information""" """RepoDB maps repo ids to repository information"""
def __init__(self): def __init__(self):
self.filename = os.path.join(ctx.config.db_dir(), 'repo.bdb') self.d = shelve.LockedDBShelf("repo")
self.d = shelve.open(self.filename)
self.fdummy = open(self.filename + '.lock', 'w')
fcntl.flock(self.fdummy, fcntl.LOCK_EX)
def init_dbs(self): def init_dbs(self):
# initialize package/source dbs # initialize package/source dbs
@@ -33,9 +30,7 @@ class RepoDB(object):
packagedb.add_db(x) packagedb.add_db(x)
def __del__(self): def __del__(self):
#fcntl.flock(self.fdummy, fcntl.LOCK_UN) self.d.close()
self.fdummy.close()
#os.unlink(self.filename + '.lock')
def has_repo(self, name): def has_repo(self, name):
name = str(name) name = str(name)
@@ -59,10 +54,14 @@ class RepoDB(object):
name = str(name) name = str(name)
del self.d[name] del self.d[name]
repodb = None db = None
def init(): def init():
repodb = RepoDB() global db
repodb.init_dbs() if db:
print 'repodb initialized' return db
db = RepoDB()
db.init_dbs()
return db
+13 -11
View File
@@ -21,10 +21,11 @@ from os import access, R_OK
# pisi modules # pisi modules
import pisi import pisi
import pisi.util as util
import pisi.context as ctx
from pisi.archive import Archive 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
import pisi.util as util
class SourceArchiveError(pisi.Error): class SourceArchiveError(pisi.Error):
pass pass
@@ -32,19 +33,20 @@ class SourceArchiveError(pisi.Error):
class SourceArchive: class SourceArchive:
"""source archive. this is a class responsible for fetching """source archive. this is a class responsible for fetching
and unpacking a source archive""" and unpacking a source archive"""
def __init__(self, ctx): def __init__(self, bctx):
self.ctx = ctx self.url = URI(bctx.spec.source.archiveUri)
self.url = URI(self.ctx.spec.source.archiveUri) self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
self.archiveFile = join(config.archives_dir(), self.url.filename()) self.archiveName = bctx.spec.source.archiveName
self.archiveType = self.ctx.spec.source.archiveType self.archiveType = bctx.spec.source.archiveType
self.archiveSHA1 = self.ctx.spec.source.archiveSHA1 self.archiveSHA1 = bctx.spec.source.archiveSHA1
self.bctx = bctx
def fetch(self, interactive=True): def fetch(self, interactive=True):
if not self.is_cached(interactive): if not self.is_cached(interactive):
if interactive: if interactive:
progress = ui.Progress progress = ctx.ui.Progress
else: progress = None else: progress = None
fetch_url(self.url, config.archives_dir(), progress) fetch_url(self.url, ctx.config.archives_dir(), progress)
def is_cached(self, interactive=True): def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK): if not access(self.archiveFile, R_OK):
@@ -53,7 +55,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:
ui.info('%s [cached]\n' % self.ctx.spec.source.archiveName) ctx.ui.info('%s [cached]\n' % self.archiveName)
return True return True
return False return False
@@ -65,4 +67,4 @@ class SourceArchive:
raise SourceArchiveError, "unpack: check_file_hash failed" raise SourceArchiveError, "unpack: check_file_hash failed"
archive = Archive(self.archiveFile, self.archiveType) archive = Archive(self.archiveFile, self.archiveType)
archive.unpack(self.ctx.pkg_work_dir(), cleanDir) archive.unpack(self.bctx.pkg_work_dir(), cleanDir)
+9 -4
View File
@@ -24,13 +24,13 @@ import fcntl
from bsddb import db from bsddb import db
import pisi.util as util import pisi.util as util
from pisi.config import config import pisi.context as ctx
class SourceDB(object): class SourceDB(object):
def __init__(self): def __init__(self):
util.check_dir(config.db_dir()) util.check_dir(ctx.config.db_dir())
self.filename = os.path.join(config.db_dir(), 'source.bdb') self.filename = os.path.join(ctx.config.db_dir(), 'source.bdb')
self.d = shelve.open(self.filename) self.d = shelve.open(self.filename)
self.fdummy = file(self.filename + '.lock', 'w') self.fdummy = file(self.filename + '.lock', 'w')
fcntl.flock(self.fdummy, fcntl.LOCK_EX) fcntl.flock(self.fdummy, fcntl.LOCK_EX)
@@ -62,5 +62,10 @@ class SourceDB(object):
sourcedb = None sourcedb = None
def init(): def init():
sourcedb = SourceDB() global sourcedb
if sourcedb:
return sourcedb
sourcedb = SourceDB()
return sourcedb
+9 -10
View File
@@ -12,9 +12,8 @@
from os.path import basename, dirname, join from os.path import basename, dirname, join
import pisi.context as ctx
from pisi.ui import ui from pisi.ui import ui
from pisi.config import config
from pisi.constants import const
from pisi.uri import URI from pisi.uri import URI
from pisi.specfile import SpecFile from pisi.specfile import SpecFile
@@ -26,7 +25,7 @@ class SourceFetcher(object):
self.location = dirname(self.url.uri) self.location = dirname(self.url.uri)
pkgname = basename(dirname(self.url.path())) pkgname = basename(dirname(self.url.path()))
self.dest = join(config.tmp_dir(), pkgname) self.dest = join(ctx.config.tmp_dir(), pkgname)
def fetch_all(self): def fetch_all(self):
# fetch pspec file # fetch pspec file
@@ -43,7 +42,7 @@ class SourceFetcher(object):
return pspec return pspec
def fetch_actionsfile(self): def fetch_actionsfile(self):
actionsuri = join(self.location, const.actions_file) actionsuri = join(self.location, ctx.const.actions_file)
self.url.uri = actionsuri self.url.uri = actionsuri
self.fetch() self.fetch()
@@ -51,27 +50,27 @@ class SourceFetcher(object):
spec = self.spec spec = self.spec
for patch in spec.source.patches: for patch in spec.source.patches:
patchuri = join(self.location, patchuri = join(self.location,
const.files_dir, patch.filename) ctx.const.files_dir, patch.filename)
self.url.uri = patchuri self.url.uri = patchuri
self.fetch(const.files_dir) self.fetch(ctx.const.files_dir)
def fetch_comarfiles(self): def fetch_comarfiles(self):
spec = self.spec spec = self.spec
for package in spec.packages: for package in spec.packages:
for pcomar in package.providesComar: for pcomar in package.providesComar:
comaruri = join(self.location, comaruri = join(self.location,
const.comar_dir, pcomar.script) ctx.const.comar_dir, pcomar.script)
self.url.uri = comaruri self.url.uri = comaruri
self.fetch(const.comar_dir) self.fetch(ctx.const.comar_dir)
def fetch_additionalFiles(self): def fetch_additionalFiles(self):
spec = self.spec spec = self.spec
for pkg in spec.packages: for pkg in spec.packages:
for afile in pkg.additionalFiles: for afile in pkg.additionalFiles:
afileuri = join(self.location, afileuri = join(self.location,
const.files_dir, afile.filename) ctx.const.files_dir, afile.filename)
self.url.uri = afileuri self.url.uri = afileuri
self.fetch(const.files_dir) self.fetch(ctx.const.files_dir)
def fetch(self, appendDest=""): def fetch(self, appendDest=""):
from fetcher import fetch_url from fetcher import fetch_url
+1 -1
View File
@@ -21,9 +21,9 @@
from os.path import basename from os.path import basename
# pisi modules # pisi modules
import pisi
from pisi.xmlext import * from pisi.xmlext import *
from pisi.xmlfile import XmlFile from pisi.xmlfile import XmlFile
import pisi
from pisi.dependency import DepInfo from pisi.dependency import DepInfo
from pisi.util import Checks from pisi.util import Checks
-1
View File
@@ -16,7 +16,6 @@
import sys import sys
from pisi.colors import colorize from pisi.colors import colorize
import pisi.context as ctx
class CLI: class CLI:
+2 -1
View File
@@ -26,6 +26,7 @@ import statvfs
# pisi modules # pisi modules
import pisi import pisi
import pisi.context as ctx
class FileError(pisi.Error): class FileError(pisi.Error):
pass pass
@@ -357,4 +358,4 @@ def partition_freespace(directory):
######################################## ########################################
def package_name(name, version, release): def package_name(name, version, release):
return name + '-' + version + '-' + release + const.package_prefix return name + '-' + version + '-' + release + ctx.const.package_prefix
+1 -1
View File
@@ -12,7 +12,7 @@
# Authors: Eray Ozkural <eray@uludag.org.tr> # Authors: Eray Ozkural <eray@uludag.org.tr>
import util import pisi.util as util
class Version: class Version:
def __init__(self, verstring): def __init__(self, verstring):
+24 -22
View File
@@ -13,32 +13,34 @@ import os
from os.path import exists as pathexists from os.path import exists as pathexists
from os.path import basename, islink, join from os.path import basename, islink, join
import pisi.context as ctx
import pisi.api
from pisi import archive from pisi import archive
from pisi import sourcearchive from pisi import sourcearchive
from pisi import fetcher from pisi import fetcher
from pisi import util from pisi import util
from pisi import context from pisi.build import BuildContext
from pisi.config import config from pisi.config import config
from pisi import uri from pisi import uri
class ArchiveFileTestCase(unittest.TestCase): class ArchiveFileTestCase(unittest.TestCase):
# def setUp(self): def setUp(self):
# pass pisi.api.init()
def testUnpackTar(self): def testUnpackTar(self):
ctx = context.BuildContext("tests/popt/pspec.xml") bctx = BuildContext("tests/popt/pspec.xml")
achv = sourcearchive.SourceArchive(ctx) achv = sourcearchive.SourceArchive(bctx)
assert ctx.spec.source.archiveType == "targz" assert bctx.spec.source.archiveType == "targz"
# skip fetching and directly unpack the previously fetched (by # skip fetching and directly unpack the previously fetched (by
# fetchertests) archive # fetchertests) archive
if not achv.isCached(interactive=False): if not achv.is_cached(interactive=False):
achv.fetch(interactive=False) achv.fetch(interactive=False)
achv.unpack() achv.unpack()
targetDir = ctx.pkg_work_dir() targetDir = bctx.pkg_work_dir()
# but testing is hard # but testing is hard
# "var/tmp/pisi/popt-1.7-3/work" (targetDir) # "var/tmp/pisi/popt-1.7-3/work" (targetDir)
assert pathexists(targetDir + "/popt-1.7") assert pathexists(targetDir + "/popt-1.7")
@@ -51,15 +53,15 @@ class ArchiveFileTestCase(unittest.TestCase):
"5af9dd7d754f788cf511c57ce0af3d555fed009d") "5af9dd7d754f788cf511c57ce0af3d555fed009d")
def testUnpackZip(self): def testUnpackZip(self):
ctx = context.BuildContext("tests/sandbox/pspec.xml") bctx = BuildContext("tests/sandbox/pspec.xml")
assert ctx.spec.source.archiveType == "zip" assert bctx.spec.source.archiveType == "zip"
achv = sourcearchive.SourceArchive(ctx) achv = sourcearchive.SourceArchive(bctx)
achv.fetch(interactive=False) achv.fetch(interactive=False)
achv.unpack(cleanDir=True) achv.unpack(cleanDir=True)
targetDir = ctx.pkg_work_dir() targetDir = bctx.pkg_work_dir()
assert pathexists(targetDir + "/sandbox") assert pathexists(targetDir + "/sandbox")
testfile = targetDir + "/sandbox/loremipsum.txt" testfile = targetDir + "/sandbox/loremipsum.txt"
@@ -75,9 +77,9 @@ class ArchiveFileTestCase(unittest.TestCase):
def testMakeZip(self): def testMakeZip(self):
# first unpack our dear sandbox.zip # first unpack our dear sandbox.zip
ctx = context.BuildContext("tests/sandbox/pspec.xml") bctx = BuildContext("tests/sandbox/pspec.xml")
targetDir = ctx.pkg_work_dir() targetDir = bctx.pkg_work_dir()
achv = sourcearchive.SourceArchive(ctx) achv = sourcearchive.SourceArchive(bctx)
achv.fetch(interactive=False) achv.fetch(interactive=False)
achv.unpack(cleanDir=True) achv.unpack(cleanDir=True)
del achv del achv
@@ -92,18 +94,18 @@ class ArchiveFileTestCase(unittest.TestCase):
def testUnpackZipCond(self): def testUnpackZipCond(self):
ctx = context.BuildContext("tests/sandbox/pspec.xml") bctx = BuildContext("tests/sandbox/pspec.xml")
url = uri.URI(ctx.spec.source.archiveUri) url = uri.URI(bctx.spec.source.archiveUri)
targetDir = ctx.pkg_work_dir() targetDir = bctx.pkg_work_dir()
filePath = join(config.archives_dir(), url.filename()) filePath = join(config.archives_dir(), url.filename())
# check cached # check cached
if util.sha1_file(filePath) != ctx.spec.source.archiveSHA1: if util.sha1_file(filePath) != bctx.spec.source.archiveSHA1:
fetch = fetcher.Fetcher(ctx.spec.source.archiveUri, targetDir) fetch = fetcher.Fetcher(bctx.spec.source.archiveUri, targetDir)
fetch.fetch() fetch.fetch()
assert ctx.spec.source.archiveType == "zip" assert bctx.spec.source.archiveType == "zip"
achv = archive.Archive(filePath, ctx.spec.source.archiveType) achv = archive.Archive(filePath, bctx.spec.source.archiveType)
achv.unpack_files(["sandbox/loremipsum.txt"], targetDir) achv.unpack_files(["sandbox/loremipsum.txt"], targetDir)
assert pathexists(targetDir + "/sandbox") assert pathexists(targetDir + "/sandbox")
testfile = targetDir + "/sandbox/loremipsum.txt" testfile = targetDir + "/sandbox/loremipsum.txt"
+6 -1
View File
@@ -10,11 +10,13 @@
import unittest import unittest
from pisi.constants import const import pisi.context as ctx
class ContextTestCase(unittest.TestCase): class ContextTestCase(unittest.TestCase):
def testConstness(self): def testConstness(self):
const = ctx.const
# test if we can get a const attribute? # test if we can get a const attribute?
try: try:
test = const.package_prefix test = const.package_prefix
@@ -46,6 +48,8 @@ class ContextTestCase(unittest.TestCase):
pass pass
def testConstValues(self): def testConstValues(self):
const = ctx.const
constDict = { constDict = {
"actions_file": "actions.py", "actions_file": "actions.py",
"setup_func": "setup", "setup_func": "setup",
@@ -59,4 +63,5 @@ class ContextTestCase(unittest.TestCase):
else: else:
self.fail("Constants does not have an attribute named %s" % k) self.fail("Constants does not have an attribute named %s" % k)
suite = unittest.makeSuite(ContextTestCase) suite = unittest.makeSuite(ContextTestCase)
+10 -6
View File
@@ -11,17 +11,21 @@
import unittest import unittest
import os import os
import pisi.context as ctx
import pisi.api
from pisi.specfile import SpecFile
from pisi import fetcher from pisi import fetcher
from pisi import util from pisi import util
from pisi import context
from pisi import config
from pisi import uri from pisi import uri
class FetcherTestCase(unittest.TestCase): class FetcherTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = context.BuildContext("tests/popt/pspec.xml") pisi.api.init()
self.url = uri.URI(self.ctx.spec.source.archiveUri)
self.destpath = config.config.archives_dir() self.spec = SpecFile()
self.spec.read("tests/popt/pspec.xml")
self.url = uri.URI(self.spec.source.archiveUri)
self.destpath = ctx.config.archives_dir()
self.fetch = fetcher.Fetcher(self.url, self.destpath) self.fetch = fetcher.Fetcher(self.url, self.destpath)
def testFetch(self): def testFetch(self):
@@ -29,6 +33,6 @@ class FetcherTestCase(unittest.TestCase):
fetchedFile = os.path.join(self.destpath, self.url.filename()) fetchedFile = os.path.join(self.destpath, self.url.filename())
if os.access(fetchedFile, os.R_OK): if os.access(fetchedFile, os.R_OK):
self.assertEqual(util.sha1_file(fetchedFile), self.assertEqual(util.sha1_file(fetchedFile),
self.ctx.spec.source.archiveSHA1) self.spec.source.archiveSHA1)
suite = unittest.makeSuite(FetcherTestCase) suite = unittest.makeSuite(FetcherTestCase)
+2 -2
View File
@@ -16,10 +16,10 @@ from pisi.config import config
class GraphTestCase(unittest.TestCase): class GraphTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.g0 = graph.digraph() self.g0 = graph.Digraph()
self.g0.from_list([ (1,2), (1,3), (2,3), (3,4), (4, 5), (4,1)]) self.g0.from_list([ (1,2), (1,3), (2,3), (3,4), (4, 5), (4,1)])
self.g1 = graph.digraph() self.g1 = graph.Digraph()
self.g1.from_list([ (0,2), (0,3), (3,4), (2,4), (0,5), (5,4) ]) self.g1.from_list([ (0,2), (0,3), (3,4), (2,4), (0,5), (5,4) ])
def testCycle(self): def testCycle(self):
+15 -13
View File
@@ -11,29 +11,31 @@
import unittest import unittest
import os import os
from pisi.installdb import installdb import pisi.context as ctx
import pisi.api
import pisi.installdb
from pisi import util from pisi import util
from pisi.config import config
class InstallDBTestCase(unittest.TestCase): class InstallDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
pass pisi.api.init()
self.installdb = ctx.installdb
def testRemoveDummy(self): def testRemoveDummy(self):
installdb.remove('installtest') self.installdb.remove('installtest')
self.assert_(not installdb.is_installed('installtest')) self.assert_(not self.installdb.is_installed('installtest'))
def testInstall(self): def testInstall(self):
installdb.purge('installtest') self.installdb.purge('installtest')
installdb.install('installtest', '0.1', '2', '3') self.installdb.install('installtest', '0.1', '2', '3')
def testRemovePurge(self): def testRemovePurge(self):
installdb.install('installtest', '0.1', '2', '3') self.installdb.install('installtest', '0.1', '2', '3')
self.assert_(installdb.is_installed('installtest')) self.assert_(self.installdb.is_installed('installtest'))
installdb.remove('installtest') self.installdb.remove('installtest')
self.assert_(installdb.is_removed('installtest')) self.assert_(self.installdb.is_removed('installtest'))
installdb.purge('installtest') self.installdb.purge('installtest')
self.assert_(not installdb.is_recorded('installtest')) self.assert_(not self.installdb.is_recorded('installtest'))
suite = unittest.makeSuite(InstallDBTestCase) suite = unittest.makeSuite(InstallDBTestCase)
+1 -1
View File
@@ -36,7 +36,7 @@ class MetaDataTestCase(unittest.TestCase):
def testVerify(self): def testVerify(self):
md = self.testRead() md = self.testRead()
if not md.verify(): if md.has_errors():
self.fail("Couldn't verify!") self.fail("Couldn't verify!")
+9 -3
View File
@@ -11,19 +11,25 @@
import unittest import unittest
import os import os
import pisi.context as ctx
import pisi.api
from pisi.packagedb import PackageDB from pisi.packagedb import PackageDB
from pisi import util from pisi import util
from pisi import context from pisi.specfile import SpecFile
class PackageDBTestCase(unittest.TestCase): class PackageDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
# setUp will be called for each test individually # setUp will be called for each test individually
self.ctx = context.BuildContext('tests/popt/pspec.xml') pisi.api.init()
self.spec = SpecFile()
self.spec.read('tests/popt/pspec.xml')
self.pdb = PackageDB('testdb') self.pdb = PackageDB('testdb')
def testAdd(self): def testAdd(self):
self.pdb.add_package(self.ctx.spec.packages[0]) self.pdb.add_package(self.spec.packages[0])
self.assert_(self.pdb.has_package('popt-libs')) self.assert_(self.pdb.has_package('popt-libs'))
# close the database and remove lock # close the database and remove lock
del self.pdb del self.pdb
+1 -1
View File
@@ -21,7 +21,7 @@ runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x)
def run_all(): def run_all():
import utiltests import utiltests
import xmlfile import xmlfiletests
import specfiletests import specfiletests
import metadatatests import metadatatests
import constantstests import constantstests
+2 -1
View File
@@ -8,6 +8,8 @@
<Source> <Source>
<Name>sandbox</Name> <Name>sandbox</Name>
<Homepage>http://cekirdek.uludag.org.tr/</Homepage> <Homepage>http://cekirdek.uludag.org.tr/</Homepage>
<Summary lang="tr">Test packati</Summary>
<Description lang="tr">Sandbox: Test paketi...</Description>
<Packager> <Packager>
<Name>A. Murat Eren</Name> <Name>A. Murat Eren</Name>
<Email>meren@uludag.org.tr</Email> <Email>meren@uludag.org.tr</Email>
@@ -27,7 +29,6 @@
<Package> <Package>
<Name>sandbox</Name> <Name>sandbox</Name>
<Summary lang="tr">Bla</Summary>
<Category>temprorary:zip</Category> <Category>temprorary:zip</Category>
<Files> <Files>
<File> <File>
+13 -7
View File
@@ -11,22 +11,28 @@
import unittest import unittest
import os import os
from pisi.sourcedb import sourcedb import pisi.context as ctx
import pisi.api
import pisi.sourcedb
from pisi import util from pisi import util
from pisi import context from pisi.specfile import SpecFile
class SourceDBTestCase(unittest.TestCase): class SourceDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = context.BuildContext("tests/popt/pspec.xml") pisi.api.init()
self.sourcedb = pisi.sourcedb.init()
self.spec = SpecFile()
self.spec.read("tests/popt/pspec.xml")
def testAdd(self): def testAdd(self):
sourcedb.add_source(self.ctx.spec.source) self.sourcedb.add_source(self.spec.source)
self.assert_(sourcedb.has_source("popt")) self.assert_(self.sourcedb.has_source("popt"))
def testRemove(self): def testRemove(self):
self.testAdd() self.testAdd()
sourcedb.remove_source("popt") self.sourcedb.remove_source("popt")
self.assert_(not sourcedb.has_source("popt")) self.assert_(not self.sourcedb.has_source("popt"))
suite = unittest.makeSuite(SourceDBTestCase) suite = unittest.makeSuite(SourceDBTestCase)