Commit 857521b8 authored by Aurélien Dunand's avatar Aurélien Dunand Committed by Sébastien Luttringer
Browse files

Allow to build images without unneeded content



The setup and payload directories and description file are the strict minimum
to build an image.
Payload directory is needed because build scripts can edit or create payloads.

Signed-off-by: default avatarSébastien Luttringer <sebastien.luttringer@smartjog.com>
parent c2af3951
Loading
Loading
Loading
Loading
+22 −16
Original line number Diff line number Diff line
@@ -283,10 +283,13 @@ class SourceImage(Image):
        '''
        Check if we are a valid SourceImage directories
        '''
        for d in (self.base_path, self.build_path, self.parser_path,
                  self.setup_path, self.payload_path, self.lib_path):
        # setup and payload are the only needed dirs
        for d in (self.setup_path, self.payload_path):
            if not os.path.exists(d):
                raise ISError(u"Invalid source image: directory %s is missing" % d)
        for d in (self.base_path, self.build_path, self.parser_path,
                  self.setup_path, self.payload_path, self.lib_path):
            if os.path.exists(d):
                if not os.path.isdir(d):
                    raise ISError(u"Invalid source image: %s is not a directory" % d)
                if not os.access(d, os.R_OK|os.X_OK):
@@ -305,13 +308,16 @@ class SourceImage(Image):
        t0 = time.time()
        # check python scripts
        if check:
            for d in (self.build_path, self.parser_path, self.setup_path):
            for d in (self.build_path, self.parser_path, self.setup_path,
                      self.lib_path):
                if os.path.exists(d) or d == self.setup_path:
                    self.check_scripts(d)
        # load modules
        self.load_modules(lambda: self.select_scripts(self.lib_path))
        # remove list
        rl = set()
        # run build script
        if os.path.exists(self.build_path):
            if script:
                rl |= set(self.run_build())
        if force_payload:
@@ -350,14 +356,12 @@ class SourceImage(Image):
            # add format
            arrow("Add format")
            tarball.add_str("format", self.format, tarfile.REGTYPE, 0644)
            # add build scripts
            self.add_scripts(tarball, self.build_path)
            # add parser scripts
            self.add_scripts(tarball, self.parser_path)
            # add setup scripts
            self.add_scripts(tarball, self.setup_path)
            # add lib scripts
            self.add_scripts(tarball, self.lib_path)
            for d in (self.build_path, self.parser_path, self.lib_path):
                if os.path.exists(d):
                    # add scripts
                    self.add_scripts(tarball, d)
            # closing tarball file
            tarball.close()
        except (SystemExit, KeyboardInterrupt):
@@ -505,6 +509,8 @@ class SourceImage(Image):
        # ensure directory is unicode to have fn and fp in unicode
        if not isinstance(directory, unicode):
            directory = unicode(directory, locale.getpreferredencoding())
        if not os.path.exists(directory):
            return
        for fn in sorted(os.listdir(directory)):
            fp = os.path.join(directory, fn)
            # check name