From 95df2722869c61714abd8b7e1e06b902fa1dcacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Fri, 26 May 2006 13:26:34 +0000 Subject: [PATCH] * fix: make sha1sum skipping work with local repos, too, add a flag to copy local files to File.download for that * remove redundancy with filename check * fix: move index back into place when no repo ID is given to read_uri --- pisi/atomicoperations.py | 1 - pisi/build.py | 6 ++++-- pisi/file.py | 20 ++++++++++---------- pisi/index.py | 19 +++++++++---------- pisi/pxml/autoxml.py | 5 +++-- pisi/pxml/xmlfilepiks.py | 6 ++++-- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index f497c7d6..0d0565dd 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# -*- coding: utf-8 -*- # # Copyright (C) 2005, TUBITAK/UEKAE # diff --git a/pisi/build.py b/pisi/build.py index faa39aa2..9abae05c 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -9,9 +9,11 @@ # # Please read the COPYING file. # +# Authors: Baris Metin +# A. Murat Eren +# Eray Ozkural -# package bulding stuff -# maintainer: baris and meren +"""package building code""" # python standard library import os diff --git a/pisi/file.py b/pisi/file.py index 82d0c45c..fd7cd292 100644 --- a/pisi/file.py +++ b/pisi/file.py @@ -71,20 +71,16 @@ class File: @staticmethod def decompress(localfile, compress): if compress == File.bz2: - if not localfile.endswith(".bz2"): - raise Error(_("bz2 compressed filename must end with '.bz2'")) - open(localfile[:-4], "w").write(bz2.BZ2File(localfile).read()) localfile = localfile[:-4] - elif compress == File.zip: raise Error(_("zip compression not supported yet")) return localfile @staticmethod - def download(uri, transfer_dir = "/tmp", - sha1sum = False, compress = None, sign = None): + def download(uri, transfer_dir = "/tmp", sha1sum = False, + compress = None, sign = None, copylocal = False): assert isinstance(uri, URI) @@ -93,9 +89,9 @@ class File: sha1f = file(sha1filename) newsha1 = sha1f.readlines()[0] - if uri.is_remote_file(): + if uri.is_remote_file() or copylocal: localfile = join(transfer_dir, uri.filename()) - + # TODO: code to use old .sha1sum file, is this a necessary optimization? #oldsha1fn = localfile + '.sha1sum' #if os.exists(oldsha1fn): @@ -106,8 +102,12 @@ class File: # early terminate, we already got it ;) raise AlreadyHaveException(uri, localfile) - ctx.ui.info(_("Fetching %s") % uri.get_uri()) - fetch_url(uri, transfer_dir) + if uri.is_remote_file(): + ctx.ui.info(_("Fetching %s") % uri.get_uri()) + fetch_url(uri, transfer_dir) + else: + ctx.ui.info(_("Copying %s to transfer dir") % uri.get_uri()) + shutil.copy(uri.get_uri(), transfer_dir) else: localfile = uri.get_uri() #TODO: use a special function here? if not os.path.exists(localfile): diff --git a/pisi/index.py b/pisi/index.py index 8f46c8b2..2a5e55a9 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -64,24 +64,23 @@ class Index(XmlFile): pisi.util.clean_dir(tmpdir) pisi.util.check_dir(tmpdir) - if not force: - urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w') - urlfile.write(filename) # uri + # write uri + urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w') + urlfile.write(filename) # uri - - # FIXME: This is a mess, we have a compress flag and we have to - # use it with filename extention. Because File.decompress also - # checks the extension. We really have to go all over the code - # and simplify it. -- baris if filename.endswith(".bz2"): self.read(filename, tmpDir=tmpdir, sha1sum=not force, - compress=File.bz2, sign=File.detached) + compress=File.bz2, sign=File.detached, copylocal = True) else: self.read(filename, tmpDir=tmpdir, sha1sum=not force, - compress=None, sign=File.detached) + compress=None, sign=File.detached, copylocal = True) if not repo: repo = self.distribution.name() + # and what do we do with it? move it to index dir properly + newtmpdir = os.path.join(ctx.config.index_dir(), repo) + pisi.util.clean_dir(newtmpdir) # replace newtmpdir + shutil.move(tmpdir, newtmpdir) def check_signature(self, filename, repo): tmpdir = os.path.join(ctx.config.index_dir(), repo) diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index 555dd754..4be16c51 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -423,9 +423,10 @@ class autoxml(oo.autosuper, oo.autoprop): if xmlfile_support: def read(self, uri, keepDoc = False, tmpDir = '/tmp', - sha1sum = False, compress = None, sign = None): + sha1sum = False, compress = None, sign = None, copylocal = False): "read XML file and decode it into a python object" - self.readxml(uri, tmpDir, sha1sum=sha1sum, compress=compress, sign=sign) + self.readxml(uri, tmpDir, sha1sum=sha1sum, + compress=compress, sign=sign, copylocal=copylocal) errs = [] self.decode(self.rootNode(), errs) if errs: diff --git a/pisi/pxml/xmlfilepiks.py b/pisi/pxml/xmlfilepiks.py index de68d63c..12f6c58c 100644 --- a/pisi/pxml/xmlfilepiks.py +++ b/pisi/pxml/xmlfilepiks.py @@ -55,10 +55,12 @@ class XmlFile(object): """returns root document element""" return self.doc - def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None): + def readxml(self, uri, tmpDir='/tmp', sha1sum=False, + compress=None, sign=None, copylocal = False): uri = File.make_uri(uri) try: - localpath = File.download(uri, tmpDir,sha1sum=sha1sum,compress=compress,sign=sign) + localpath = File.download(uri, tmpDir, sha1sum=sha1sum, + compress=compress,sign=sign, copylocal=copylocal) except IOError: raise Error(_("Cannot access URI %s") % (uri) ) try: