* add xmill support to File class
* implement xmill compression for index read/write, tested with a remote repo * start writing an option to force update of a repo
This commit is contained in:
+6
-2
@@ -42,6 +42,7 @@ from pisi.build import build_until
|
||||
from pisi.atomicoperations import resurrect_package, build
|
||||
from pisi.metadata import MetaData
|
||||
from pisi.files import Files
|
||||
from pisi.file import File
|
||||
import pisi.search
|
||||
import pisi.lockeddbshelve as shelve
|
||||
|
||||
@@ -299,7 +300,7 @@ def index(dirs, output = 'pisi-index.xml', skip_sources=False):
|
||||
for repo_dir in dirs:
|
||||
ctx.ui.info(_('* Building index of PISI files under %s') % repo_dir)
|
||||
index.index(repo_dir, skip_sources)
|
||||
index.write(output, sha1sum=True)
|
||||
index.write(output, sha1sum=True, compress=File.xmill)
|
||||
ctx.ui.info(_('* Index file written'))
|
||||
|
||||
def add_repo(name, indexuri):
|
||||
@@ -315,7 +316,7 @@ def remove_repo(name):
|
||||
ctx.ui.error(_('Repository %s does not exist. Cannot remove.')
|
||||
% name)
|
||||
|
||||
def update_repo(repo):
|
||||
def update_repo(repo, force=False):
|
||||
ctx.ui.info(_('* Updating repository: %s') % repo)
|
||||
index = Index()
|
||||
if ctx.repodb.has_repo(repo):
|
||||
@@ -325,6 +326,9 @@ def update_repo(repo):
|
||||
ctx.ui.info(_('* Package database updated.'))
|
||||
except pisi.file.AlreadyHaveException, e:
|
||||
ctx.ui.info(_('No updates available for repository %s.' % repo))
|
||||
if force:
|
||||
ctx.ui.info(_('Updating database at any rate as requested'))
|
||||
raise Error(_('OPTION NOT IMPLEMENTED YET'))
|
||||
else:
|
||||
raise Error(_('No repository named %s found.') % repo)
|
||||
|
||||
|
||||
@@ -801,6 +801,11 @@ If no repository is given, all repositories are updated.
|
||||
|
||||
name = ("update-repo", "ur")
|
||||
|
||||
def options(self):
|
||||
self.parser.add_option("-f", "--force", action="store_true",
|
||||
default=False,
|
||||
help=_("update database in any case"))
|
||||
|
||||
def run(self):
|
||||
self.init(database = True)
|
||||
|
||||
@@ -810,7 +815,7 @@ If no repository is given, all repositories are updated.
|
||||
repos = ctx.repodb.list()
|
||||
|
||||
for repo in repos:
|
||||
pisi.api.update_repo(repo)
|
||||
pisi.api.update_repo(repo, ctx.get_option('force'))
|
||||
self.finalize()
|
||||
|
||||
|
||||
|
||||
+22
-3
@@ -54,6 +54,17 @@ class File:
|
||||
raise Error(_("uri must have type either URI or string"))
|
||||
return uri
|
||||
|
||||
@staticmethod
|
||||
def decompress(localfile, compress):
|
||||
if compress == File.xmill:
|
||||
pisi.util.run_batch('xdemill -f ' + localfile)
|
||||
if not localfile.endswith('.xmi'):
|
||||
raise Error(_("xmill compressed filename must end with '.xmi'"))
|
||||
localfile = localfile[:-4] + '.xml'
|
||||
elif compress == File.sevenzip:
|
||||
raise Error(_("sevenzip compression not supported yet"))
|
||||
return localfile
|
||||
|
||||
@staticmethod
|
||||
def download(uri, transfer_dir = "/tmp",
|
||||
sha1sum = False, compress = None, sign = None):
|
||||
@@ -81,18 +92,23 @@ class File:
|
||||
fetch_url(uri, transfer_dir)
|
||||
else:
|
||||
localfile = uri.get_uri() #TODO: use a special function here?
|
||||
localfile = File.decompress(localfile, self.compress)
|
||||
|
||||
if sha1sum:
|
||||
|
||||
if (pisi.util.sha1_file(localfile) != newsha1):
|
||||
raise Error(_("File integrity of %s compromised.") % uri)
|
||||
|
||||
localfile = File.decompress(localfile, compress)
|
||||
|
||||
return localfile
|
||||
|
||||
|
||||
def __init__(self, uri, mode, transfer_dir = "/tmp",
|
||||
sha1sum = False, compress = None, sign = None):
|
||||
"it is pointless to open a file without a URI and a mode"
|
||||
self.sha1sum = sha1sum
|
||||
self.compress = compress
|
||||
uri = File.make_uri(uri)
|
||||
if mode==File.read or mode==File.write:
|
||||
self.mode = mode
|
||||
@@ -100,9 +116,7 @@ class File:
|
||||
raise Error(_("File mode must be either File.read or File.write"))
|
||||
if uri.is_remote_file():
|
||||
if self.mode == File.read:
|
||||
ctx.ui.info(_("Fetching %s") % uri.get_uri())
|
||||
localfile = join(transfer_dir, uri.filename())
|
||||
fetch_url(uri, transfer_dir) # FIXME: localfile would look better for fetch iface?
|
||||
localfile = File.download(uri, transfer_dir, sha1sum, compress, sign)
|
||||
else:
|
||||
raise Error(_("Remote write not implemented"))
|
||||
else:
|
||||
@@ -122,6 +136,11 @@ class File:
|
||||
def close(self, delete_transfer = False):
|
||||
"this method must be called at the end of operation"
|
||||
self.__file__.close()
|
||||
if self.compress == File.xmill:
|
||||
pisi.util.run_batch('xcmill -9 -d -f ' + self.localfile)
|
||||
self.localfile = self.localfile[:-4] + '.xmi'
|
||||
elif self.compress == File.sevenzip:
|
||||
raise Error(_("sevenzip compression not supported yet"))
|
||||
if self.mode == File.write:
|
||||
if self.sha1sum:
|
||||
sha1 = pisi.util.sha1_file(self.localfile)
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ import pisi.sourcedb as sourcedb
|
||||
import pisi.util as util
|
||||
from pisi.package import Package
|
||||
from pisi.pxml.xmlfile import XmlFile
|
||||
from pisi.file import File
|
||||
import pisi.pxml.autoxml as autoxml
|
||||
from pisi.uri import URI
|
||||
import pisi.component as component
|
||||
@@ -52,7 +53,7 @@ class Index(XmlFile):
|
||||
def read_uri(self, filename, repo = None):
|
||||
"""Read PSPEC file"""
|
||||
tmpdir = os.path.join(ctx.config.index_dir(), repo)
|
||||
self.read(filename, tmpDir=tmpdir, sha1sum=True)
|
||||
self.read(filename, tmpDir=tmpdir, sha1sum=True, compress=File.xmill)
|
||||
|
||||
def index(self, repo_uri, skip_sources=False):
|
||||
self.repo_dir = repo_uri
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ def human_readable_rate(size = 0):
|
||||
|
||||
def run_batch(cmd, realtime = False):
|
||||
"""run command non-interactively/realtime and report return value and output"""
|
||||
ctx.ui.info(_('running ') + cmd)
|
||||
ctx.ui.info(_('Running ') + cmd, verbose=True)
|
||||
p = os.popen(cmd)
|
||||
if realtime:
|
||||
while 1:
|
||||
|
||||
Reference in New Issue
Block a user