From ded712dc7479ebb4ea1469cf0d4592b46a1a17d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sun, 9 Oct 2005 16:42:37 +0000 Subject: [PATCH] * fix: make destdir work * fix: we have to use a fixx0red copy of os.path.join at places --- pisi/build.py | 6 +++--- pisi/config.py | 20 +++++++++++++------- pisi/install.py | 2 +- pisi/installdb.py | 5 ++--- pisi/operations.py | 2 +- pisi/package.py | 2 +- pisi/util.py | 11 +++++++++++ 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/pisi/build.py b/pisi/build.py index 44cd29db..cbd17877 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -103,9 +103,9 @@ class BuildContext(object): "package build directory" packageDir = self.spec.source.name + '-' + \ self.spec.source.version + '-' + self.spec.source.release - - return ctx.config.destdir + ctx.config.values.dirs.tmp_dir \ - + '/' + packageDir + from pisi.util import join_path as join + return join( ctx.config.destdir(), ctx.config.values.dirs.tmp_dir, + packageDir ) def pkg_work_dir(self): return self.pkg_dir() + ctx.const.work_dir_suffix diff --git a/pisi/config.py b/pisi/config.py index 0e3eb371..a1562aa6 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -24,6 +24,7 @@ _ = __trans.ugettext import pisi import pisi.context as ctx from pisi.configfile import ConfigurationFile +from pisi.util import join_path as join class Config(object): """Config Singleton""" @@ -31,7 +32,6 @@ class Config(object): def __init__(self, options = None): self.options = options self.values = ConfigurationFile("/etc/pisi/pisi.conf") - self.destdir = self.values.general.destinationdirectory def get_option(self, opt): if self.options: @@ -44,23 +44,29 @@ class Config(object): # x_dir: system wide directory for storing info type x # pkg_x_dir: per package directory for storing info type x + def destdir(self): + dir = str(self.get_option('destdir')) + if not dir: + dir = self.values.general.destinationdirectory + return dir + def lib_dir(self): - return self.destdir + self.values.dirs.lib_dir + return join(self.destdir(), self.values.dirs.lib_dir) def db_dir(self): - return self.destdir + self.values.dirs.db_dir + return join(self.destdir(), self.values.dirs.db_dir) def archives_dir(self): - return self.destdir + self.values.dirs.archives_dir + return join(self.destdir(), self.values.dirs.archives_dir) def packages_dir(self): - return self.destdir + self.values.dirs.packages_dir + return join(self.destdir(), self.values.dirs.packages_dir) def index_dir(self): - return self.destdir + self.values.dirs.index_dir + return join(self.destdir(), self.values.dirs.index_dir) def tmp_dir(self): - return self.destdir + self.values.dirs.tmp_dir + return join(self.destdir(), self.values.dirs.tmp_dir) # bu dizini neden kullanıyoruz? Yalnızca index.py içerisinde # kullanılıyor ama /var/tmp/pisi/install gibi bir dizine niye diff --git a/pisi/install.py b/pisi/install.py index ac06a200..c248be6e 100644 --- a/pisi/install.py +++ b/pisi/install.py @@ -153,7 +153,7 @@ class Installer: "unzip package in place" ctx.ui.info(_('Extracting files')) - self.package.extract_dir_flat('install', ctx.config.destdir) + self.package.extract_dir_flat('install', ctx.config.destdir()) if self.reinstall: # remove left over files diff --git a/pisi/installdb.py b/pisi/installdb.py index 16548898..ea659836 100644 --- a/pisi/installdb.py +++ b/pisi/installdb.py @@ -73,13 +73,12 @@ class InstallInfo: class InstallDB: def __init__(self): - from os.path import join self.d = shelve.LockedDBShelf('install') self.dp = shelve.LockedDBShelf('configpending') - self.files_dir = os.path.join(ctx.config.db_dir(), 'files') + self.files_dir = pisi.util.join_path(ctx.config.db_dir(), 'files') def files_name(self, pkg, version, release): - from os.path import join + from pisi.util import join_path as join pkg_dir = join(ctx.config.lib_dir(), pkg + '-' + version + '-' + release) return join(pkg_dir, ctx.const.files_xml) diff --git a/pisi/operations.py b/pisi/operations.py index 8b29bea3..2cdc6275 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -29,7 +29,7 @@ import pisi.comariface as comariface # remove stuff def remove_file(fileinfo): - fpath = os.path.join(ctx.config.destdir, fileinfo.path) + fpath = pisi.util.join_path(ctx.config.destdir(), fileinfo.path) # TODO: We have to store configuration files for futher # usage. Currently we'are doing it like rpm does, saving # with a prefix and leaving the user to edit it. In the future diff --git a/pisi/package.py b/pisi/package.py index 8e327d40..2a4485f4 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -115,4 +115,4 @@ class Package: return join( ctx.config.lib_dir(), packageDir) def comar_dir(self): - return self.pkg_dir() + ctx.const.comar_dir_suffix + return join(self.pkg_dir(), ctx.const.comar_dir_suffix) diff --git a/pisi/util.py b/pisi/util.py index a831c9af..d4dc9410 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -191,6 +191,17 @@ def absolute_path(path): comps = splitpath(path) return comps[0] == '' +def join_path(a, *p): + """Join two or more pathname components, inserting '/' as needed""" + """The python original version has a silly logic""" + path = a + for b in p: + if path == '' or path.endswith('/'): + path += b + else: + path += '/' + b + return path + #################################### # File/Directory Related Functions # ####################################