diff --git a/image_creator/dialog_menu.py b/image_creator/dialog_menu.py index 71ffec74f479f17dde1ee43aab843399d476c7b7..d4da713c1d04cd9c0f0a45e67c8e7be377921a57 100644 --- a/image_creator/dialog_menu.py +++ b/image_creator/dialog_menu.py @@ -504,12 +504,8 @@ def sysprep(session): help_title = "System Preperation Tasks" sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title)) - if 'exec_syspreps' not in session: - session['exec_syspreps'] = [] - all_syspreps = image.os.list_syspreps() - # Only give the user the choice between syspreps that have not ran yet - syspreps = [s for s in all_syspreps if s not in session['exec_syspreps']] + syspreps = image.os.list_syspreps() if len(syspreps) == 0: d.msgbox("No system preparation task available to run!", @@ -544,28 +540,31 @@ def sysprep(session): for i in range(len(syspreps)): if str(i + 1) in tags: image.os.enable_sysprep(syspreps[i]) - session['exec_syspreps'].append(syspreps[i]) else: image.os.disable_sysprep(syspreps[i]) + if len([s for s in image.os.list_syspreps() if s.enabled]) == 0: + d.msgbox("No system preperation task is selected!", + title="System Preperation", width=SMALL_WIDTH) + continue + infobox = InfoBoxOutput(d, "Image Configuration") try: image.out.add(infobox) try: image.mount(readonly=False) try: - err_msg = \ - "Unable to execute the system preparation tasks." + err = "Unable to execute the system preparation " \ + "tasks. Couldn't mount the media%s." if not image.mounted: - d.msgbox( - "%s Couldn't mount the media." % err_msg, - title="System Preperation", width=SMALL_WIDTH) + d.msgbox(err % "", title="System Preperation", + width=SMALL_WIDTH) return elif image.mounted_ro: d.msgbox( - "%s Couldn't mount the media read-write." - % err_msg, title="System Preperation", - width=SMALL_WIDTH) + err % " read-write",title="System Preperation", + width=SMALL_WIDTH + ) return # The checksum is invalid. We have mounted the image rw @@ -577,9 +576,6 @@ def sysprep(session): image.os.do_sysprep() infobox.finalize() - # Disable syspreps that have ran - for sysprep in session['exec_syspreps']: - image.os.disable_sysprep(sysprep) finally: image.umount() finally: diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index 181bf5d9bcf67b14c7d81540a66acaa57efd0e92..cea08a32a8ac43575f4c0e167a858674ca5e8fc7 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -65,6 +65,7 @@ def sysprep(enabled=True): def wrapper(func): func.sysprep = True func.enabled = enabled + func.executed = False return func return wrapper @@ -94,7 +95,7 @@ class OSBase(object): objs = [getattr(self, name) for name in dir(self) if not name.startswith('_')] - return [x for x in objs if self._is_sysprep(x)] + return [x for x in objs if self._is_sysprep(x) and x.executed is False] def sysprep_info(self, obj): assert self._is_sysprep(obj), "Object is not a sysprep" @@ -222,6 +223,7 @@ class OSBase(object): cnt += 1 self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False) task() + setattr(task.im_func, 'executed', True) self.out.output() # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :