* 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:
@@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2005, TUBITAK/UEKAE
|
# Copyright (C) 2005, TUBITAK/UEKAE
|
||||||
#
|
#
|
||||||
|
|||||||
+4
-2
@@ -9,9 +9,11 @@
|
|||||||
#
|
#
|
||||||
# Please read the COPYING file.
|
# 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
|
"""package building code"""
|
||||||
# maintainer: baris and meren
|
|
||||||
|
|
||||||
# python standard library
|
# python standard library
|
||||||
import os
|
import os
|
||||||
|
|||||||
+10
-10
@@ -71,20 +71,16 @@ class File:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def decompress(localfile, compress):
|
def decompress(localfile, compress):
|
||||||
if compress == File.bz2:
|
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())
|
open(localfile[:-4], "w").write(bz2.BZ2File(localfile).read())
|
||||||
localfile = localfile[:-4]
|
localfile = localfile[:-4]
|
||||||
|
|
||||||
elif compress == File.zip:
|
elif compress == File.zip:
|
||||||
raise Error(_("zip compression not supported yet"))
|
raise Error(_("zip compression not supported yet"))
|
||||||
|
|
||||||
return localfile
|
return localfile
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download(uri, transfer_dir = "/tmp",
|
def download(uri, transfer_dir = "/tmp", sha1sum = False,
|
||||||
sha1sum = False, compress = None, sign = None):
|
compress = None, sign = None, copylocal = False):
|
||||||
|
|
||||||
assert isinstance(uri, URI)
|
assert isinstance(uri, URI)
|
||||||
|
|
||||||
@@ -93,9 +89,9 @@ class File:
|
|||||||
sha1f = file(sha1filename)
|
sha1f = file(sha1filename)
|
||||||
newsha1 = sha1f.readlines()[0]
|
newsha1 = sha1f.readlines()[0]
|
||||||
|
|
||||||
if uri.is_remote_file():
|
if uri.is_remote_file() or copylocal:
|
||||||
localfile = join(transfer_dir, uri.filename())
|
localfile = join(transfer_dir, uri.filename())
|
||||||
|
|
||||||
# TODO: code to use old .sha1sum file, is this a necessary optimization?
|
# TODO: code to use old .sha1sum file, is this a necessary optimization?
|
||||||
#oldsha1fn = localfile + '.sha1sum'
|
#oldsha1fn = localfile + '.sha1sum'
|
||||||
#if os.exists(oldsha1fn):
|
#if os.exists(oldsha1fn):
|
||||||
@@ -106,8 +102,12 @@ class File:
|
|||||||
# early terminate, we already got it ;)
|
# early terminate, we already got it ;)
|
||||||
raise AlreadyHaveException(uri, localfile)
|
raise AlreadyHaveException(uri, localfile)
|
||||||
|
|
||||||
ctx.ui.info(_("Fetching %s") % uri.get_uri())
|
if uri.is_remote_file():
|
||||||
fetch_url(uri, transfer_dir)
|
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:
|
else:
|
||||||
localfile = uri.get_uri() #TODO: use a special function here?
|
localfile = uri.get_uri() #TODO: use a special function here?
|
||||||
if not os.path.exists(localfile):
|
if not os.path.exists(localfile):
|
||||||
|
|||||||
+9
-10
@@ -64,24 +64,23 @@ class Index(XmlFile):
|
|||||||
pisi.util.clean_dir(tmpdir)
|
pisi.util.clean_dir(tmpdir)
|
||||||
pisi.util.check_dir(tmpdir)
|
pisi.util.check_dir(tmpdir)
|
||||||
|
|
||||||
if not force:
|
# write uri
|
||||||
urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w')
|
urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w')
|
||||||
urlfile.write(filename) # uri
|
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"):
|
if filename.endswith(".bz2"):
|
||||||
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
|
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
|
||||||
compress=File.bz2, sign=File.detached)
|
compress=File.bz2, sign=File.detached, copylocal = True)
|
||||||
else:
|
else:
|
||||||
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
|
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
|
||||||
compress=None, sign=File.detached)
|
compress=None, sign=File.detached, copylocal = True)
|
||||||
|
|
||||||
if not repo:
|
if not repo:
|
||||||
repo = self.distribution.name()
|
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):
|
def check_signature(self, filename, repo):
|
||||||
tmpdir = os.path.join(ctx.config.index_dir(), repo)
|
tmpdir = os.path.join(ctx.config.index_dir(), repo)
|
||||||
|
|||||||
@@ -423,9 +423,10 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
|
|
||||||
if xmlfile_support:
|
if xmlfile_support:
|
||||||
def read(self, uri, keepDoc = False, tmpDir = '/tmp',
|
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"
|
"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 = []
|
errs = []
|
||||||
self.decode(self.rootNode(), errs)
|
self.decode(self.rootNode(), errs)
|
||||||
if errs:
|
if errs:
|
||||||
|
|||||||
@@ -55,10 +55,12 @@ class XmlFile(object):
|
|||||||
"""returns root document element"""
|
"""returns root document element"""
|
||||||
return self.doc
|
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)
|
uri = File.make_uri(uri)
|
||||||
try:
|
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:
|
except IOError:
|
||||||
raise Error(_("Cannot access URI %s") % (uri) )
|
raise Error(_("Cannot access URI %s") % (uri) )
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user