From e3606fe83707fa0134cea11778adca9ffb5272c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Mon, 5 Feb 2007 21:46:54 +0000 Subject: [PATCH] Hardcoding paths is evil! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit baris@evliya ~ $ pisi info dbus [...snip...] kde4@evliya ~ $ pisi info dbus -d DEBUG: PiSi API initialized Sistem Hatası: Program Sonlandırıldı. exceptions.IOError: [Errno 13] Erişim engellendi: '/tmp/files.xml' Genel yardım için lütfen 'pisi help' komutunu kullanınız. Geri-iz: File "/usr/bin/pisi", line 89, in ? cli.run_command() File "/usr/lib/pardus/pisi/cli/pisicli.py", line 111, in run_command self.command.run() File "/usr/lib/pardus/pisi/cli/commands.py", line 866, in run self.info_package(arg) File "/usr/lib/pardus/pisi/cli/commands.py", line 884, in info_package metadata, files = pisi.api.info_name(arg, True) File "/usr/lib/pardus/pisi/api.py", line 336, in info_name files = ctx.installdb.files(package.name) File "/usr/lib/pardus/pisi/installdb.py", line 91, in files files.read(self.files_name(pkg,pkginfo.version,pkginfo.release)) File "/usr/lib/pardus/pisi/pxml/autoxml.py", line 439, in read compress=compress, sign=sign, copylocal=copylocal) File "/usr/lib/pardus/pisi/pxml/xmlfile.py", line 80, in readxml compress=compress,sign=sign, copylocal=copylocal) File "/usr/lib/pardus/pisi/file.py", line 131, in download shutil.copy(oldfn, localfile) File "/usr/lib/python2.4/shutil.py", line 81, in copy copyfile(src, dst) File "/usr/lib/python2.4/shutil.py", line 48, in copyfile fdst = open(dst, 'wb') DEBUG: PiSi API finalized --- pisi/file.py | 12 +++++++++--- pisi/pxml/autoxml.py | 17 ++++++++++++++--- pisi/pxml/xmlfile.py | 8 ++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pisi/file.py b/pisi/file.py index fb257735..c08bd47a 100644 --- a/pisi/file.py +++ b/pisi/file.py @@ -90,11 +90,14 @@ class File: return localfile @staticmethod - def download(uri, transfer_dir = "/tmp", sha1sum = False, + def download(uri, transfer_dir = None, sha1sum = False, compress = None, sign = None, copylocal = False): assert isinstance(uri, URI) + if not transfer_dir: + transfer_dir = ctx.config.tmp_dir() + if sha1sum: sha1filename = File.download(URI(uri.get_uri() + '.sha1sum'), transfer_dir) sha1f = file(sha1filename) @@ -139,11 +142,14 @@ class File: return localfile - def __init__(self, uri, mode, transfer_dir = "/tmp", + def __init__(self, uri, mode, transfer_dir = None, sha1sum = False, compress = None, sign = None): "it is pointless to open a file without a URI and a mode" - self.transfer_dir = transfer_dir + if trasfer_dir: + self.transfer_dir = transfer_dir + else: + self.trasfer_dir = ctx.config.tmp_dir() self.sha1sum = sha1sum self.compress = compress self.sign = sign diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index 30291fcb..f2817223 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -310,8 +310,11 @@ class autoxml(oo.autosuper, oo.autoprop): # generate top-level helper functions cls.initializers = inits - def initialize(self, uri = None, keepDoc = False, tmpDir = '/tmp', + def initialize(self, uri = None, keepDoc = False, tmpDir = None, **args): + if not tmpDir: + tmpDir = ctx.config.tmp_dir() + if xmlfile_support: if args.has_key('tag'): XmlFile.__init__(self, tag = args['tag']) @@ -432,9 +435,13 @@ class autoxml(oo.autosuper, oo.autoprop): if errs: errs.append(_("autoxml.parse: String '%s' has errors") % xml) - def read(self, uri, keepDoc = False, tmpDir = '/tmp', + def read(self, uri, keepDoc = False, tmpDir = None, sha1sum = False, compress = None, sign = None, copylocal = False): "read XML file and decode it into a python object" + + if not tmpDir: + tmpDir = ctx.config.tmp_dir() + self.readxml(uri, tmpDir, sha1sum=sha1sum, compress=compress, sign=sign, copylocal=copylocal) errs = [] @@ -453,7 +460,7 @@ class autoxml(oo.autosuper, oo.autoprop): errs.append(_("autoxml.read: File '%s' has errors") % uri) raise Error(*errs) - def write(self, uri, keepDoc = False, tmpDir = '/tmp', + def write(self, uri, keepDoc = False, tmpDir = None, sha1sum = False, compress = None, sign = None): "encode the contents of the python object into an XML file" errs = self.errors() @@ -461,6 +468,10 @@ class autoxml(oo.autosuper, oo.autoprop): errs.append(_("autoxml.write: object validation has failed")) raise Error(*errs) errs = [] + + if not tmpDir: + tmpDir = ctx.config.tmp_dir() + self.newDocument() self.encode(self.rootNode(), errs) if hasattr(self, 'write_hook'): diff --git a/pisi/pxml/xmlfile.py b/pisi/pxml/xmlfile.py index 263624a4..350ba89f 100644 --- a/pisi/pxml/xmlfile.py +++ b/pisi/pxml/xmlfile.py @@ -72,8 +72,12 @@ class XmlFile(object): raise Error(_("File '%s' has invalid XML") % (f) ) - def readxml(self, uri, tmpDir='/tmp', sha1sum=False, + def readxml(self, uri, tmpDir=None, sha1sum=False, compress=None, sign=None, copylocal = False): + + if not tmpDir: + tmpDir = ctx.config.tmp_dir() + uri = File.make_uri(uri) #try: localpath = File.download(uri, tmpDir, sha1sum=sha1sum, @@ -86,7 +90,7 @@ class XmlFile(object): except Exception, e: raise Error(_("File '%s' has invalid XML") % (localpath) ) - def writexml(self, uri, tmpDir = '/tmp', sha1sum=False, compress=None, sign=None): + def writexml(self, uri, tmpDir = None, sha1sum=False, compress=None, sign=None): f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign) f.write(self.doc.toPrettyString()) f.close()