Commit da281d3c authored by Seblu's avatar Seblu
Browse files

Image download from repository is now handled by repository class

This is a better way of doing things. This help to have a better display of
where is causing latency
parent 973c22f2
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ import ConfigParser
import subprocess
import tarfile
import re
import cStringIO
import shutil
import gzipstream #until python support gzip not seekable
import installsystems.template as istemplate
@@ -345,29 +344,25 @@ class PackageImage(Image):
    Packaged image manipulation class
    '''

    def __init__(self, path, md5name=False):
    def __init__(self, path, fileobj=None, md5name=False):
        '''
        Initialize a package image

        fileobj must be a seekable fileobj
        '''
        Image.__init__(self)
        self.path = istools.abspath(path)
        self.base_path = os.path.dirname(self.path)
        # tarball are named by md5 and not by real name
        self.md5name = md5name
        # load image in memory
        arrow("Loading image %s" % path)
        memfile = cStringIO.StringIO()
        fo = istools.uopen(self.path)
        (self.size, self.md5) = istools.copyfileobj(fo, memfile)
        fo.close()
        # set tarball fo
        memfile.seek(0)
        self._tarball = Tarball.open(fileobj=memfile, mode='r:gz')
        if fileobj is None:
            fileobj = istools.uopen(self.path)
        self._tarball = Tarball.open(fileobj=fileobj, mode='r:gz')
        self._metadata = self.read_metadata()
        # print info
        arrow("Image %s v%s by %s, %s" % (self.name,
                                                self.version,
                                                self.author,
                                                time.ctime(self.date)
                                                ),
              1)
        arrow("Image %s v%s loaded" % (self.name, self.version))
        arrow("Author: %s" % self.author, 1)
        arrow("Date: %s" % time.ctime(self.date), 1)
        # build payloads
        self.payload = {}
        for pname, pval in self._metadata["payload"].items():
+15 −8
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import pwd
import grp
import tempfile
import fnmatch
import cStringIO
import installsystems
import installsystems.tools as istools
from installsystems.printer import *
@@ -270,18 +271,24 @@ class Repository(object):
        if version is None:
            version = self.last(name)
            if version < 0:
                raise Exception("Unable to find last version of %s in %s" % (name,
                raise Exception("Unable to find image %s in %s" % (name,
                                                                   self.config.name))
        # get file md5 from db
        r = self.db.ask("select md5 from image where name = ? and version = ? limit 1",
                        (name, version)).fetchone()
        if r is None:
            raise Exception("No such image %s version %s" % (name, version))
            raise Exception("Unable to find image %s version %s" % (name, version))
        path = os.path.join(self.config.path, r[0])
        debug("Getting %s v%s from %s (%s)" % (name, version,
                                               self.config.name,
                                               self.config.path))
        pkg = PackageImage(path, md5name=True)
        # getting the file
        arrow("Loading image %s v%s from repository %s" % (name,
                                                           version,
                                                           self.config.name))
        memfile = cStringIO.StringIO()
        fo = istools.uopen(path)
        (self.size, self.md5) = istools.copyfileobj(fo, memfile)
        fo.close()
        memfile.seek(0)
        pkg = PackageImage(path, fileobj=memfile, md5name=True)
        pkg.md5 = r[0]
        return pkg