From: Gui Chen Date: Thu, 27 Oct 2011 06:08:12 +0000 (+0800) Subject: Fix convert livecd/liveusb cannot work X-Git-Tag: 0.1~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e68694eb4216b11aed4e43eb4613acac77d4f343;p=tools%2Fmic.git Fix convert livecd/liveusb cannot work Signed-off-by: Gui Chen --- diff --git a/mic/imager/loop.py b/mic/imager/loop.py index d16eff7..2b003bd 100644 --- a/mic/imager/loop.py +++ b/mic/imager/loop.py @@ -216,8 +216,8 @@ class LoopImageCreator(BaseImageCreator): return minsize - def _base_on(self, base_on): - if base_on is not None: + def _base_on(self, base_on=None): + if base_on and self._image != base_on: shutil.copyfile(base_on, self._image) def _check_imgdir(self): @@ -228,8 +228,22 @@ class LoopImageCreator(BaseImageCreator): # Actual implementation # def _mount_instroot(self, base_on = None): + + if base_on and os.path.isfile(base_on): + self.__imgdir = os.path.dirname(base_on) + imgname = os.path.basename(base_on) + self._base_on(base_on) + self._set_image_size(misc.get_file_size(self._image)) + self._instloops.append({ + "mountpoint": "/", + "label": self.name, + "name": imgname, + "size": self.__image_size or 4096L * 1024 * 1024, + "fstype": self.__fstype or "ext3", + "loop": None + }) + self._check_imgdir() - self._base_on(base_on) for loop in self._instloops: fstype = loop['fstype'] diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 43622cc..a253023 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -159,13 +159,10 @@ class LiveCDPlugin(ImagerPlugin): raise errors.CreatorError("Failed to run post cleanups: %s" % msg) convertor = livecd.LiveCDImageCreator() - srcimgsize = (misc.get_file_size(base_on)) * 1024L * 1024L - base_on_dir = os.path.dirname(base_on) - convertor._LoopImageCreator__imgdir = base_on_dir + convertor.name = os.path.splitext(os.path.basename(base_on))[0] convertor._set_fstype("ext3") - convertor._set_image_size(srcimgsize) try: - convertor.mount() + convertor.mount(base_on) __mkinitrd(convertor) convertor._create_bootconfig() __run_post_cleanups(convertor) @@ -173,7 +170,7 @@ class LiveCDPlugin(ImagerPlugin): convertor.package() convertor.print_outimage_info() finally: - shutil.rmtree(base_on_dir, ignore_errors = True) + shutil.rmtree(os.path.dirname(base_on), ignore_errors = True) @classmethod def do_unpack(cls, srcimg): @@ -208,7 +205,8 @@ class LiveCDPlugin(ImagerPlugin): raise errors.CreatorError("'%s' is not a valid live CD ISO : neither " "LiveOS/ext3fs.img nor os.img exist" %img) - rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "target.img") + imgname = os.path.basename(srcimg) + rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname) shutil.copyfile(os_image, rtimage) finally: diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 70659a0..71833fc 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -161,13 +161,10 @@ class LiveUSBPlugin(ImagerPlugin): raise errors.CreatorError("Failed to run post cleanups: %s" % msg) convertor = liveusb.LiveUSBImageCreator() - srcimgsize = (misc.get_file_size(base_on)) * 1024L * 1024L + convertor.name = os.path.splitext(os.path.basename(base_on))[0] convertor._set_fstype("ext3") - convertor._set_image_size(srcimgsize) - base_on_dir = os.path.dirname(base_on) - convertor._LoopImageCreator__imgdir = base_on_dir try: - convertor.mount() + convertor.mount(base_on) __mkinitrd(convertor) convertor._create_bootconfig() __run_post_cleanups(convertor) @@ -175,7 +172,7 @@ class LiveUSBPlugin(ImagerPlugin): convertor.package() convertor.print_outimage_info() finally: - shutil.rmtree(base_on_dir, ignore_errors = True) + shutil.rmtree(os.path.dirname(base_on), ignore_errors = True) @classmethod def do_unpack(cls, srcimg): @@ -212,7 +209,8 @@ class LiveUSBPlugin(ImagerPlugin): if not os.path.exists(os_image): raise errors.CreatorError("'%s' is not a valid live CD ISO : neither " "LiveOS/ext3fs.img nor os.img exist" %img) - rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "target.img") + imgname = os.path.basename(srcimg) + rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname) shutil.copyfile(os_image, rtimage) finally: