6 def add_prefix(target):
7 def wrapper(self, *args):
9 return map(lambda x: prefix + x, target(self, *args))
14 """Basic operating system class"""
15 def __init__(self, rootdev, ghandler):
20 def ls(self, directory):
21 """List the name of all files under a directory"""
22 return self.g.ls(directory)
25 def find(self, directory):
26 """List the name of all files recursively under a directory"""
27 return self.g.find(directory)
29 def foreach_file(self, directory, action, **kargs):
30 """Perform an action recursively on all files under a directory.
32 The following options are allowed:
34 * maxdepth: If defined the action will not be performed on
35 files that are below this level of directories under the
38 * ftype: The action will only be performed on files of this
39 type. For a list of all allowed filetypes, see here:
40 http://libguestfs.org/guestfs.3.html#guestfs_readdir
42 * exclude: Exclude all files that follow this pattern.
44 maxdepth = None if 'maxdepth' not in kargs else kargs['maxdepth']
49 maxdepth = None if maxdepth is None else maxdepth - 1
50 kargs['maxdepth'] = maxdepth
52 exclude = None if 'exclude' not in kargs else kargs['exclude']
53 ftype = None if 'ftype' not in kargs else kargs['ftype']
54 has_ftype = lambda x, y: y is None and True or x['ftyp'] == y
56 for f in self.g.readdir(directory):
57 if f['name'] in ('.', '..'):
60 full_path = "%s/%s" % (directory, f['name'])
62 if exclude and re.match(exclude, full_path):
66 self.foreach_file(full_path, action, **kargs)
68 if has_ftype(f, ftype):
71 def get_metadata(self):
72 """Returns some descriptive metadata about the OS."""
74 meta['ROOT_PARTITION'] = "%d" % self.g.part_to_partnum(self.root)
75 meta['OSFAMILY'] = self.g.inspect_get_type(self.root)
76 meta['OS'] = self.g.inspect_get_distro(self.root)
77 meta['description'] = self.g.inspect_get_product_name(self.root)
81 def data_cleanup(self):
82 """Cleanup sensitive data out of the OS image."""
83 raise NotImplementedError
86 """Prepere system for image creation."""
87 raise NotImplementedError
89 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :