3 # Copyright (c) 2011 Intel, Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 from mic.utils import runner, misc
22 from mic.utils.errors import CreatorError
23 from mic.utils.fs_related import find_binary_path
24 from mic.imager.baseimager import BaseImageCreator
26 class FsImageCreator(BaseImageCreator):
29 def __init__(self, cfgmgr = None, pkgmgr = None):
33 BaseImageCreator.__init__(self, cfgmgr, pkgmgr)
36 self._include_src = False
38 def package(self, destdir = "."):
46 if not os.path.exists(destdir):
49 if self._recording_pkgs:
50 self._save_recording_pkgs(destdir)
53 self.image_files = {'image_files': [self.name]}
54 fsdir = os.path.join(destdir, self.name)
56 misc.check_space_pre_cp(self._instroot, destdir)
57 msger.info("Copying %s to %s ..." % (self._instroot, fsdir))
58 runner.show(['cp', "-af", self._instroot, fsdir])
60 for exclude in ignores:
61 if os.path.exists(fsdir + exclude):
62 os.unlink(fsdir + exclude)
64 self.outimage.append(fsdir)
67 self.image_files = {'image_files': [self.pack_to]}
68 (tar, comp) = os.path.splitext(self.pack_to)
70 tarcreat = {'.tar': '-cf',
76 raise CreatorError("Unsupported comression for this image type:"
77 " '%s', try '.tar', '.tar.gz', etc" % comp)
79 dst = os.path.join(destdir, self.pack_to)
80 msger.info("Pack rootfs to %s. Please wait..." % dst)
82 tar = find_binary_path('tar')
83 tar_cmdline = [tar, "--numeric-owner",
84 "--preserve-permissions",
89 for ignore_entry in ignores:
90 if ignore_entry.startswith('/'):
91 ignore_entry = ignore_entry[1:]
93 tar_cmdline.append("--exclude=%s" % (ignore_entry))
95 tar_cmdline.extend([tarcreat, dst, "."])
97 rc = runner.show(tar_cmdline)
99 raise CreatorError("Failed compress image with tar.bz2. "
100 "Cmdline: %s" % (" ".join(tar_cmdline)))
102 self.outimage.append(dst)