def __init__(self, creatoropts=None, pkgmgr=None,
compress_image=None,
- shrink_image=False):
+ shrink_image=False,
+ reuse_environment=False):
"""Initialize a LoopImageCreator instance.
This method takes the same arguments as ImageCreator.__init__()
self.compress_image = compress_image
self.shrink_image = shrink_image
+ self.reuse_environment = reuse_environment
self.__fslabel = None
self.fslabel = self.name
if self._imgdir is None:
self._imgdir = self._mkdtemp()
+ def _get_instroot_cache(self):
+ return os.path.join(self.get_cachedir(), "instroot")
+
+ def _check_instroot_cache(self):
+ cachedir = self._get_instroot_cache()
+ if not os.path.exists(cachedir):
+ return False
+
+ for loop in self._instloops:
+ image = os.path.join(cachedir, loop['name'])
+ if not os.path.exists(image):
+ return False
+
+ return True
+
+ def save_install_root(self):
+ if self._imgdir is None:
+ raise CreatorError("image dir is invalid while save install root")
+
+ cachedir = self._get_instroot_cache()
+ if os.path.exists(cachedir):
+ if os.path.isdir(cachedir):
+ shutil.rmtree(cachedir)
+ else:
+ os.unlink(cachedir)
+
+ try:
+ shutil.copytree(self._imgdir, cachedir)
+ except (OSError, IOError) as e:
+ shutil.rmtree(cachedir, ignore_errors=True)
+ raise CreatorError("Cannot save install root : %s" % str(e))
#
# Actual implementation
self._check_imgdir()
+ if self.reuse_environment and self._check_instroot_cache():
+ cachedir = self._get_instroot_cache()
+ for file in os.listdir(cachedir):
+ shutil.move(os.path.join(cachedir, file), self._imgdir)
+ else:
+ self.reuse_environment = False
+
for loop in self._instloops:
fstype = loop['fstype']
fsopt = loop['fsopts']
creator = LoopImageCreator(creatoropts,
pkgmgr,
args.compress_image,
- args.shrink)
+ args.shrink,
+ args.reuse_environment)
if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
try:
creator.check_depend_tools()
creator.mount(None, creatoropts["cachedir"])
- creator.install()
- creator.tpkinstall()
+ if creator.reuse_environment:
+ msger.info("Re-install the packages which are modified")
+ else:
+ creator.install()
+ creator.tpkinstall()
+ creator.save_install_root()
creator.configure(creatoropts["repomd"])
creator.copy_kernel()
creator.create_cpio_image()
help="Compress all loop images with 'gz' or 'bz2'")
loop_parser.add_argument("--shrink", action='store_true', default=False,
help="Whether to shrink loop images to minimal size")
+ loop_parser.add_argument('--reuse-environment', action='store_true', default=False,
+ help='Reuse the image creator environment of mic')
+ group = loop_parser.add_argument_group('only for reuse create environment option')
+ group.add_argument('--reinsrall-pkgs', action='store', dest='reinstall_pkgs', default=[],
+ help='Reinstall the given packages to re-create image, '
+ 'packages should be separated by comma')
qcow_parser = subparsers.add_parser('qcow', parents=[parent_parser], help='create qcow image')