Commit fa65eda1 authored by Nikos Skalkotos's avatar Nikos Skalkotos

Monitor executed syspreps in os_type/__init__.py

Syspreps that have already been executed shouldn't get returned by
list_syspreps
parent f9153c84
......@@ -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:
......
......@@ -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 :
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment