* 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
This commit is contained in:
Eray Özkural
2006-05-26 13:26:34 +00:00
parent 1a48fe9fd0
commit 95df272286
6 changed files with 30 additions and 27 deletions
-1
View File
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005, TUBITAK/UEKAE
#
+4 -2
View File
@@ -9,9 +9,11 @@
#
# Please read the COPYING file.
#
# Authors: Baris Metin <baris at pardus.org.tr>
# A. Murat Eren <meren at pardus.org.tr>
# Eray Ozkural <eray at pardus.org.tr>
# package bulding stuff
# maintainer: baris and meren
"""package building code"""
# python standard library
import os
+10 -10
View File
@@ -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):
+9 -10
View File
@@ -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)
+3 -2
View File
@@ -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:
+4 -2
View File
@@ -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: