Commit 4b6d82ec authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add a new "directory" type for sysprep params

parent 4ed15903
......@@ -648,9 +648,13 @@ def update_sysprep_param(session, name):
param = image.os.sysprep_params[name]
while 1:
if param.type == "file":
title = "Please select a file to use for the `%s' parameter" % name
value = select_file(d, ftype="br", title=title)
if param.type in ("file", "dir"):
title = "Please select a %s to use for the `%s' parameter" % \
(name, 'file' if param.type == 'file' else 'directory')
ftype = "br" if param.type == 'file' else 'd'
value = select_file(d, ftype=ftype, title=title)
if value is None:
return False
......@@ -88,7 +88,8 @@ class SysprepParam(object):
type_checker = {"posint": self._check_posint,
"string": self._check_string,
"file": self._check_fname}
"file": self._check_fname,
"dir": self._check_dname}
assert type in type_checker.keys(), "Invalid parameter type: %s" % type
......@@ -101,6 +102,7 @@ class SysprepParam(object):
self._checker = type_checker[type]
def set_value(self, value):
"""Update the value of the parameter"""
self.value = self._checker(value)
except ValueError as e:
......@@ -144,6 +146,19 @@ class SysprepParam(object):
raise ValueError("Invalid filename")
def _check_dname(self, value):
"""Check if the value is a valid directory"""
value = str(value)
if len(value) == 0:
return ""
import os
if os.path.isdir(value):
return value
raise ValueError("Invalid dirname")
def add_sysprep_param(name, type, default, descr):
"""Decorator for __init__ that adds the definition for a system preparation
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