def package(self, destdir="."): """Prepares the created image for final delivery. In its simplest form, this method merely copies the install root to the supplied destination directory; other subclasses may choose to package the image by e.g. creating a bootable ISO containing the image and bootloader configuration. destdir -- the directory into which the final image should be moved; this defaults to the current directory. """ self._stage_final_image() if not os.path.exists(destdir): fs.makedirs(destdir) if self._recording_pkgs: self._save_recording_pkgs(destdir) # For image formats with two or multiple image files, it will be # better to put them under a directory if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"): destdir = os.path.join(destdir, "%s-%s" % (self.name, self.image_format)) msger.debug("creating destination dir: %s" % destdir) fs.makedirs(destdir) # Ensure all data is flushed to _outdir runner.quiet("sync") misc.check_space_pre_cp(self._outdir, destdir) for f in os.listdir(self._outdir): shutil.move(os.path.join(self._outdir, f), os.path.join(destdir, f)) self.outimage.append(os.path.join(destdir, f)) self.do_genchecksum(os.path.join(destdir, f))
def package(self, destdir = "."): ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr", "/etc/mtab"] if not os.path.exists(destdir): os.makedirs(destdir) if self._recording_pkgs: self._save_recording_pkgs(destdir) if self._img_compression_method == None: fsdir = os.path.join(destdir, self.name) misc.check_space_pre_cp(self._instroot, destdir) msger.info("Copying %s to %s ..." % (self._instroot, fsdir)) runner.show(['cp', "-af", self._instroot, fsdir]) for exclude in ignores: if os.path.exists(fsdir + exclude): os.unlink(fsdir + exclude) self.outimage.append(fsdir) elif self._img_compression_method == "tar.bz2": dst = "%s/%s.tar.bz2" % (destdir, self.name) msger.info("Creating %s (compressing %s with %s). Please wait..." \ % (dst, self._instroot, self._img_compression_method)) tar = find_binary_path('tar') tar_cmdline = [tar, "--numeric-owner", "--preserve-permissions", "--preserve-order", "--one-file-system", "--directory", self._instroot] for ignore_entry in ignores: if ignore_entry.startswith('/'): ignore_entry = ignore_entry[1:] tar_cmdline.append("--exclude=%s" % (ignore_entry)) tar_cmdline.extend(["-cjf", dst, "."]) rc = call(tar_cmdline) if rc: raise CreatorError("Failed compress image with tar.bz2. " "Cmdline: %s" % (" ".join(tar_cmdline))) self.outimage.append(dst) else: raise CreatorError("Compression method '%s' not supported for 'fs' " "image format." % (self._img_compression_method))
def package(self, destdir="."): """Prepares the created image for final delivery. In its simplest form, this method merely copies the install root to the supplied destination directory; other subclasses may choose to package the image by e.g. creating a bootable ISO containing the image and bootloader configuration. destdir -- the directory into which the final image should be moved; this defaults to the current directory. """ self._stage_final_image() if not os.path.exists(destdir): fs.makedirs(destdir) if self._recording_pkgs: self._save_recording_pkgs(destdir) # For image formats with two or multiple image files, it will be # better to put them under a directory if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"): destdir = os.path.join(destdir, "%s-%s" \ % (self.name, self.image_format)) msger.debug("creating destination dir: %s" % destdir) fs.makedirs(destdir) # Ensure all data is flushed to _outdir runner.quiet('sync') misc.check_space_pre_cp(self._outdir, destdir) for f in os.listdir(self._outdir): shutil.move(os.path.join(self._outdir, f), os.path.join(destdir, f)) self.outimage.append(os.path.join(destdir, f)) self.do_genchecksum(os.path.join(destdir, f))
def package(self, destdir = "."): ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr"] if not os.path.exists(destdir): os.makedirs(destdir) if self._recording_pkgs: self._save_recording_pkgs(destdir) if not self.pack_to: fsdir = os.path.join(destdir, self.name) misc.check_space_pre_cp(self._instroot, destdir) msger.info("Copying %s to %s ..." % (self._instroot, fsdir)) runner.show(['cp', "-af", self._instroot, fsdir]) for exclude in ignores: if os.path.exists(fsdir + exclude): os.unlink(fsdir + exclude) self.outimage.append(fsdir) else: (tar, comp) = os.path.splitext(self.pack_to) try: tarcreat = {'.tar': '-cf', '.gz': '-czf', '.bz2': '-cjf', '.tgz': '-czf', '.tbz': '-cjf'}[comp] except KeyError: raise CreatorError("Unsupported comression for this image type:" " '%s', try '.tar', '.tar.gz', etc" % comp) dst = os.path.join(destdir, self.pack_to) msger.info("Pack rootfs to %s. Please wait..." % dst) tar = find_binary_path('tar') tar_cmdline = [tar, "--numeric-owner", "--preserve-permissions", "--one-file-system", "--directory", self._instroot] for ignore_entry in ignores: if ignore_entry.startswith('/'): ignore_entry = ignore_entry[1:] tar_cmdline.append("--exclude=%s" % (ignore_entry)) tar_cmdline.extend([tarcreat, dst, "."]) rc = runner.show(tar_cmdline) if rc: raise CreatorError("Failed compress image with tar.bz2. " "Cmdline: %s" % (" ".join(tar_cmdline))) self.outimage.append(dst) self.post_package(destdir)
def package(self, destdir = "."): """Prepares the created image for final delivery. In its simplest form, this method merely copies the install root to the supplied destination directory; other subclasses may choose to package the image by e.g. creating a bootable ISO containing the image and bootloader configuration. destdir -- the directory into which the final image should be moved; this defaults to the current directory. """ self._stage_final_image() if not os.path.exists(destdir): fs.makedirs(destdir) if self._img_compression_method: if not self._img_name: raise CreatorError("Image name not set.") rc = None img_location = os.path.join(self._outdir,self._img_name) zipcmd = self.zips[self._img_compression_method] # confirm the existing of zip command fs.find_binary_path(zipcmd) msger.info("Compressing %s with %s. Please wait ..." \ % (img_location, zipcmd)) rc = runner.show([zipcmd, "-f", img_location]) if rc: raise CreatorError("Failed to compress image %s with %s." \ % (img_location, self._img_compression_method)) for bootimg in glob.glob(os.path.dirname(img_location) + \ "/*-boot.bin"): msger.info("Compressing %s with %s. Please wait..." \ % (bootimg, zipcmd)) rc = runner.show([zipcmd, "-f", bootimg]) if rc: raise CreatorError("Failed to compress image %s with " "%s." \ % (bootimg, self._img_compression_method)) if self._recording_pkgs: self._save_recording_pkgs(destdir) # For image formats with two or multiple image files, it will be # better to put them under a directory if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"): destdir = os.path.join(destdir, "%s-%s" \ % (self.name, self.image_format)) msger.debug("creating destination dir: %s" % destdir) fs.makedirs(destdir) # Ensure all data is flushed to _outdir runner.quiet('sync') misc.check_space_pre_cp(self._outdir, destdir) for f in os.listdir(self._outdir): shutil.move(os.path.join(self._outdir, f), os.path.join(destdir, f)) self.outimage.append(os.path.join(destdir, f)) self.do_genchecksum(os.path.join(destdir, f))
def package(self, destdir = "."): ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr"] if not os.path.exists(destdir): os.makedirs(destdir) if self._recording_pkgs: self._save_recording_pkgs(destdir) if not self.pack_to: fsdir = os.path.join(destdir, self.name) misc.check_space_pre_cp(self._instroot, destdir) msger.info("Copying %s to %s ..." % (self._instroot, fsdir)) runner.show(['cp', "-af", self._instroot, fsdir]) for exclude in ignores: if os.path.exists(fsdir + exclude): os.unlink(fsdir + exclude) self.outimage.append(fsdir) else: (tar, comp) = os.path.splitext(self.pack_to) try: tarcreat = {'.tar': '-cf', '.gz': '-czf', '.bz2': '-cjf', '.tgz': '-czf', '.tbz': '-cjf'}[comp] except KeyError: raise CreatorError("Unsupported comression for this image type:" " '%s', try '.tar', '.tar.gz', etc" % comp) dst = os.path.join(destdir, self.pack_to) msger.info("Pack rootfs to %s. Please wait..." % dst) tar = find_binary_path('tar') tar_cmdline = [tar, "--numeric-owner", "--preserve-permissions", "--preserve-order", "--one-file-system", "--directory", self._instroot] for ignore_entry in ignores: if ignore_entry.startswith('/'): ignore_entry = ignore_entry[1:] tar_cmdline.append("--exclude=%s" % (ignore_entry)) tar_cmdline.extend([tarcreat, dst, "."]) rc = runner.show(tar_cmdline) if rc: raise CreatorError("Failed compress image with tar.bz2. " "Cmdline: %s" % (" ".join(tar_cmdline))) self.outimage.append(dst)
def package(self, destdir="."): """Prepares the created image for final delivery. In its simplest form, this method merely copies the install root to the supplied destination directory; other subclasses may choose to package the image by e.g. creating a bootable ISO containing the image and bootloader configuration. destdir -- the directory into which the final image should be moved; this defaults to the current directory. """ self._stage_final_image() if not os.path.exists(destdir): fs.makedirs(destdir) if self._img_compression_method: if not self._img_name: raise CreatorError("Image name not set.") rc = None img_location = os.path.join(self._outdir, self._img_name) zipcmd = self.zips[self._img_compression_method] # confirm the existing of zip command fs.find_binary_path(zipcmd) msger.info("Compressing %s with %s. Please wait ..." \ % (img_location, zipcmd)) rc = runner.show([zipcmd, "-f", img_location]) if rc: raise CreatorError("Failed to compress image %s with %s." \ % (img_location, self._img_compression_method)) for bootimg in glob.glob(os.path.dirname(img_location) + \ "/*-boot.bin"): msger.info("Compressing %s with %s. Please wait..." \ % (bootimg, zipcmd)) rc = runner.show([zipcmd, "-f", bootimg]) if rc: raise CreatorError("Failed to compress image %s with " "%s." \ % (bootimg, self._img_compression_method)) if self._recording_pkgs: self._save_recording_pkgs(destdir) # For image formats with two or multiple image files, it will be # better to put them under a directory if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"): destdir = os.path.join(destdir, "%s-%s" \ % (self.name, self.image_format)) msger.debug("creating destination dir: %s" % destdir) fs.makedirs(destdir) # Ensure all data is flushed to _outdir runner.quiet('sync') misc.check_space_pre_cp(self._outdir, destdir) for f in os.listdir(self._outdir): shutil.move(os.path.join(self._outdir, f), os.path.join(destdir, f)) self.outimage.append(os.path.join(destdir, f)) self.do_genchecksum(os.path.join(destdir, f))