default=None, action="callback", callback=check_writable_dir,
help="dump image to FILE", metavar="FILE")
+ parser.add_option("--print-sysprep", dest="print_sysprep", default=False,
+ help="Print the enabled and disable sysprep actions for this image",
+ action="store_true")
+
+ parser.add_option("--print-data-cleanup", dest="print_data_cleanup",
+ default=False, help="Print the enabled and disable data cleanup "
+ "operations actions for this source", action="store_true")
+
parser.add_option("-s", "--silent", dest="silent", default=False,
help="silent mode, only output error", action="store_true")
if options.register:
options.upload = True
- if options.outfile is None and not options.upload:
- parser.error('either outfile (-o) or upload (-u) must be set.')
-
return options
if options.silent:
util.silent = True
+ if options.outfile is None and not options.upload \
+ and not options.print_sysprep and not options.print_data_cleanup:
+ FatalError("At least one of the following: `-o', `-u', "
+ "`--print-sysprep' `--print-data-cleanup' must be set")
+
output('snf-image-creator %s\n' % version)
if os.geteuid() != 0:
output()
+ if options.print_sysprep:
+ image_os.print_sysprep()
+ output()
+
+ if options.print_data_cleanup:
+ image_os.print_data_cleanup()
+ output()
+
+ if options.outfile is None and not options.upload:
+ return 0
+
if options.sysprep:
image_os.sysprep()
self.root = rootdev
self.g = ghandler
+ self.sysprep_regexp = re.compile('^sysprep_')
+ self.data_cleanup_regexp = re.compile('^data_cleanup_')
+
+ def _print_task(self, task):
+ name = task.__name__
+
+ if self.sysprep_regexp.match(name):
+ name = self.sysprep_regexp.sub("", name)
+ elif self.data_cleanup_regexp.match(name):
+ name = self.data_cleanup_regexp.sub("", name)
+ else:
+ raise FatalError("%s is not a task" % name)
+
+ name = name.replace('_', '-')
+
+ output(" %s:\n %s" % (name, task.__doc__))
+
@add_prefix
def ls(self, directory):
"""List the name of all files under a directory"""
return meta
+ def list_sysprep(self):
+ """List all sysprep actions"""
+
+ is_sysprep = lambda x: x.startswith('sysprep_') and \
+ callable(getattr(self, x))
+ tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)]
+
+ included = [t for t in tasks if not getattr(t, "excluded", False)]
+ excluded = [t for t in tasks if getattr(t, "excluded", False)]
+
+ return included, excluded
+
+ def list_data_cleanup(self):
+ """List all data_cleanup actions"""
+
+ is_cleanup = lambda x: x.startswith('data_cleanup_') and \
+ callable(getattr(self, x))
+ tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)]
+
+ included = [t for t in tasks if not getattr(t, "excluded", False)]
+ excluded = [t for t in tasks if getattr(t, "excluded", False)]
+
+ return included, excluded
+
def data_cleanup(self):
"""Cleanup sensitive data out of the OS image."""
task()
output()
- def list_sysprep(self):
- """List all sysprep actions"""
-
- is_sysprep = lambda x: x.startswith('sysprep_') and \
- callable(getattr(self, x))
- tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)]
-
- included = [t for t in tasks if not getattr(t, "excluded", False)]
- excluded = [t for t in tasks if getattr(t, "excluded", False)]
-
- return included, excluded
-
- def list_data_cleanup(self):
- """List all data_cleanup actions"""
-
- is_cleanup = lambda x: x.startswith('data_cleanup_') and \
- callable(getattr(self, x))
- tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)]
-
- included = [t for t in tasks if not getattr(t, "excluded", False)]
- excluded = [t for t in tasks if getattr(t, "excluded", False)]
-
- return included, excluded
+ def print_task(self, task):
+ name = task.__name__
+
+ if self.sysprep_regexp.match(name):
+ name = self.sysprep_regexp.sub("", name)
+ elif self.data_cleanup_regexp.match(name):
+ name = self.data_cleanup_regexp.sub("", name)
+ else:
+ raise FatalError("%s is not a task" % name)
+
+ name = name.replace('_', '-')
+
+ output(" %s:\n %s" % (name, task.__doc__))
+
+ def print_data_cleanup(self):
+ included, excluded = self.list_data_cleanup()
+
+ output("Included data cleanup operations:")
+ if len(included) == 0:
+ ouput("(none)")
+ else:
+ for task in included:
+ self._print_task(task)
+ output("Ommited data cleanup operations:")
+ if len(excluded) == 0:
+ ouput("(none)")
+ else:
+ for task in excluded:
+ self._print_task(task)
+
+ def print_sysprep(self):
+ included, excluded = self.list_sysprep()
+
+ output("Included sysprep operations:")
+ if len(included) == 0:
+ ouput("(none)")
+ else:
+ for task in included:
+ self._print_task(task)
+ output("Ommited sysprep operations:")
+ if len(excluded) == 0:
+ output("(none)")
+ else:
+ for task in excluded:
+ self._print_task(task)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :