import textwrap
import re
+from collections import namedtuple
+from functools import wraps
def os_cls(distro, osfamily):
return wrapper
-def sysprep(enabled=True):
+def sysprep(message, enabled=True):
"""Decorator for system preparation tasks"""
- def wrapper(func):
+ def wrapper1(func):
func.sysprep = True
func.enabled = enabled
func.executed = False
- return func
- return wrapper
+
+ @wraps(func)
+ def wrapper2(self, print_message=True):
+ if print_message:
+ self.out.output(message)
+ return func(self)
+
+ return wrapper2
+
+ return wrapper1
class OSBase(object):
"""Basic operating system class"""
- def __init__(self, image):
+ SysprepParam = namedtuple('SysprepParam',
+ 'name description length validator')
+
+ def __init__(self, image, **kargs):
self.image = image
self.root = image.root
self.g = image.g
self.out = image.out
+ self.sysprep_params = \
+ kargs['sysprep_params'] if 'sysprep_params' in kargs else {}
+
self.meta = {}
def collect_metadata(self):
self.out.output()
+ def needed_sysprep_params(self):
+ """Returns a list of needed sysprep parameters. Each element in the
+ list is a SysprepParam object.
+ """
+ return []
+
def list_syspreps(self):
"""Returns a list of sysprep objects"""
objs = [getattr(self, name) for name in dir(self)
descr = wrapper.fill(textwrap.dedent(sysprep.__doc__))
self.out.output(' %s:\n%s\n' % (name, descr))
+ def print_sysprep_params(self):
+ """Print the system preparation parameter the user may use"""
+
+ self.out.output("Needed system preparation parameters:")
+
+ params = self.needed_sysprep_params()
+
+ if len(params) == 0:
+ self.out.output("(none)")
+ return
+
+ for param in params:
+ self.out.output("\t%s (%s): %s" %
+ (param.description, param.name,
+ self.sysprep_params[param.name] if param.name in
+ self.sysprep_params else "(none)"))
+
def do_sysprep(self):
"""Prepare system for image creation."""