Revision 678b382b
b/image_creator/dialog_menu.py | ||
---|---|---|
648 | 648 |
|
649 | 649 |
for i in range(len(fields)): |
650 | 650 |
param = needed[names[i]] |
651 |
if param.validator(output[i]): |
|
652 |
image.os.sysprep_params[names[i]] = output[i] |
|
653 |
else: |
|
654 |
d.msgbox("The value you provided for parameter: %s is not valid" % |
|
655 |
names[i], width=SMALL_WIDTH) |
|
656 |
return False |
|
651 |
try: |
|
652 |
value = param.type(output[i]) |
|
653 |
if param.validate(value): |
|
654 |
image.os.sysprep_params[names[i]] = value |
|
655 |
continue |
|
656 |
except ValueError: |
|
657 |
pass |
|
658 |
|
|
659 |
d.msgbox("The value you provided for parameter: `%s' is not valid" % |
|
660 |
names[i], width=SMALL_WIDTH) |
|
661 |
return False |
|
657 | 662 |
|
658 | 663 |
return True |
659 | 664 |
|
b/image_creator/dialog_wizard.py | ||
---|---|---|
350 | 350 |
def sysprep_params_validate(answer): |
351 | 351 |
params = {} |
352 | 352 |
for i in range(len(answer)): |
353 |
if needed[param_names[i]].validator(answer): |
|
354 |
params[param_names[i]] = answer[i] |
|
355 |
else: |
|
356 |
session['dialog'].msgbox("Invalid value for parameter `%s'" % |
|
353 |
try: |
|
354 |
value = needed[param_names[i]].type(answer[i]) |
|
355 |
if needed[param_names[i]].validate(value): |
|
356 |
params[param_names[i]] = value |
|
357 |
continue |
|
358 |
except ValueError: |
|
359 |
pass |
|
360 |
|
|
361 |
session['dialog'].msgbox("Invalid value for parameter `%s'" % |
|
357 | 362 |
param_names[i]) |
358 |
raise WizardReloadPage
|
|
363 |
raise WizardReloadPage |
|
359 | 364 |
return params |
360 | 365 |
|
361 | 366 |
def sysprep_params_display(params): |
b/image_creator/os_type/__init__.py | ||
---|---|---|
88 | 88 |
return wrapper |
89 | 89 |
|
90 | 90 |
|
91 |
def add_sysprep_param(name, default, description, validator=lambda x: True):
|
|
91 |
def add_sysprep_param(name, type, default, descr, validate=lambda x: True):
|
|
92 | 92 |
"""Decorator for __init__ that adds the definition for a system preparation |
93 | 93 |
parameter in an instance of a os_type class |
94 | 94 |
""" |
... | ... | |
97 | 97 |
def inner(self, *args, **kwargs): |
98 | 98 |
init(self, *args, **kwargs) |
99 | 99 |
self.needed_sysprep_params[name] = \ |
100 |
self.SysprepParam(default, description, validator)
|
|
100 |
self.SysprepParam(type, default, descr, validate)
|
|
101 | 101 |
return inner |
102 | 102 |
return wrapper |
103 | 103 |
|
... | ... | |
118 | 118 |
class OSBase(object): |
119 | 119 |
"""Basic operating system class""" |
120 | 120 |
|
121 |
SysprepParam = namedtuple('SysprepParam', 'default description validator') |
|
121 |
SysprepParam = namedtuple('SysprepParam', |
|
122 |
['type', 'default', 'description', 'validate']) |
|
122 | 123 |
|
123 | 124 |
def __init__(self, image, **kargs): |
124 | 125 |
self.image = image |
b/image_creator/os_type/windows.py | ||
---|---|---|
108 | 108 |
class Windows(OSBase): |
109 | 109 |
"""OS class for Windows""" |
110 | 110 |
|
111 |
@add_sysprep_param('password', None, 'Image Administrator Password') |
|
111 |
@add_sysprep_param('password', str, None, 'Image Administrator Password')
|
|
112 | 112 |
def __init__(self, image, **kargs): |
113 | 113 |
super(Windows, self).__init__(image, **kargs) |
114 | 114 |
|
Also available in: Unified diff