Kaydet (Commit) 22f39e05 authored tarafından Eray Özkural's avatar Eray Özkural

* fix: don't change uri file to a wrong value while rebuilding repo,

  use the new "read" function of Index to achieve this, wasn't too 
  easy to test
* add an "auto" value as compression choice to File to simplify index
  code, for the above fix
üst e925a921
......@@ -383,36 +383,31 @@ def update_repo(repo, force=False):
else:
raise Error(_('No repository named %s found.') % repo)
def delete_cache():
util.clean_dir(ctx.config.packages_dir())
util.clean_dir(ctx.config.archives_dir())
util.clean_dir(ctx.config.tmp_dir())
def rebuild_repo(repo):
ctx.ui.info(_('* Rebuilding \'%s\' named repo... ') % repo, noln=True)
index = Index()
if ctx.repodb.has_repo(repo):
repouri = URI(ctx.repodb.get_repo(repo).indexuri.get_uri())
indexname = repouri.filename()
indexpath = pisi.util.join_path(ctx.config.lib_dir(), 'index', repo, indexname)
uri_str = repouri.get_uri()
if os.path.exists(indexpath):
uri_str = indexpath
index = Index()
indexpath = pisi.util.join_path(ctx.config.index_dir(), repo, indexname)
tmpdir = os.path.join(ctx.config.tmp_dir(), 'index')
pisi.util.clean_dir(tmpdir)
try:
index.read_uri(uri_str, repo, force = True)
index.read(indexpath, tmpdir)
except IOError:
ctx.ui.warning(_("Repo index file \'%s\' not found.") % uri_str)
ctx.ui.warning(_("Repo index file '%s' not found.") % uri_str)
return
ctx.txn_proc(lambda txn : index.update_db(repo, txn=txn))
ctx.ui.info(_('OK.'))
else:
raise Error(_('No repository named %s found.') % repo)
ctx.txn_proc(lambda txn : index.update_db(repo, txn=txn))
ctx.ui.info(_('OK.'))
def delete_cache():
util.clean_dir(ctx.config.packages_dir())
util.clean_dir(ctx.config.archives_dir())
util.clean_dir(ctx.config.tmp_dir())
def rebuild_db(files=False):
assert ctx.database == False
......@@ -465,7 +460,7 @@ def rebuild_db(files=False):
ctx.ui.debug('Resurrecting %s' % package_fn)
pisi.api.resurrect_package(package_fn, files, txn)
def reload_indexes(txn):
def reload_indices(txn):
index_dir = ctx.config.index_dir()
if os.path.exists(index_dir): # it may have been erased, or we may be upgrading from a previous version -- exa
for repo in os.listdir(index_dir):
......@@ -493,4 +488,4 @@ def rebuild_db(files=False):
#ctx.txn_proc(reload)
clean_duplicates()
reload_packages(files, None)
reload_indexes(None)
reload_indices(None)
......@@ -55,8 +55,7 @@ class InvalidSignature(pisi.Error):
class File:
(read, write) = range(2) # modes
(bz2, zip) = range(2) # compress enums
(bz2, gzip, auto) = range(3) # compress enums
(detached, whatelse) = range(2)
@staticmethod
......@@ -67,15 +66,28 @@ class File:
elif not isinstance(uri, URI):
raise Error(_("uri must have type either URI or string"))
return uri
@staticmethod
def choose_method(filename, compress):
# this is really simple (^_^) -- exa
if compress == File.auto:
if filename.endswith('.bz2'):
return File.bz2
elif filename.endswith('.gz'):
return File.gzip
else:
return None
else:
return compress
@staticmethod
def decompress(localfile, compress):
compress = File.choose_method(localfile, compress)
if compress == File.bz2:
open(localfile[:-4], "w").write(bz2.BZ2File(localfile).read())
localfile = localfile[:-4]
elif compress == File.zip:
elif compress == File.gzip:
raise Error(_("zip compression not supported yet"))
return localfile
@staticmethod
......@@ -113,7 +125,7 @@ class File:
else:
localfile = uri.get_uri() #TODO: use a special function here?
if not os.path.exists(localfile):
raise IOError(_("File \'%s\' not found.") % localfile)
raise IOError(_("File '%s' not found.") % localfile)
if not os.access(localfile, os.W_OK):
oldfn = localfile
localfile = join(transfer_dir, os.path.basename(localfile))
......@@ -174,8 +186,8 @@ class File:
compressed_file = self.localfile + ".bz2"
bz2.BZ2File(compressed_file, "w").write(open(self.localfile, "r").read())
elif self.compress == File.zip:
raise Error(_("zip compression not supported yet"))
elif self.compress == File.gzip:
raise Error(_("gzip compression not supported yet"))
if self.sha1sum:
sha1 = pisi.util.sha1_file(self.localfile)
......
......@@ -54,6 +54,10 @@ class Index(XmlFile):
def name():
return self.distribution.name + self.distribution.repositoryname
def read(filename, tmpdir):
XmlFile.read(filename, tmpDir=tmpdir, sha1sum=not force,
compress=File.auto, sign=File.detached, copylocal = True)
# read index for a given repo, force means download even if remote not updated
def read_uri(self, filename, repo = None, force = False):
"""Read PSPEC file"""
......@@ -68,12 +72,7 @@ class Index(XmlFile):
urlfile = file(pisi.util.join_path(tmpdir, 'uri'), 'w')
urlfile.write(filename) # uri
if filename.endswith(".bz2"):
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
compress=File.bz2, sign=File.detached, copylocal = True)
else:
self.read(filename, tmpDir=tmpdir, sha1sum=not force,
compress=None, sign=File.detached, copylocal = True)
self.read(filename, tmpdir)
if not repo:
repo = self.distribution.name()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment