osclass = get_os_class(dev.distro, dev.ostype)
image_os = osclass(dev.root, dev.g)
- metadata = image_os.get_metadata()
output()
for sysprep in options.disabled_syspreps:
if options.sysprep:
image_os.do_sysprep()
+ metadata = image_os.meta
dev.umount()
size = options.shrink and dev.shrink() or dev.size
self.root = rootdev
self.g = ghandler
+ # Collect metadata about the OS
+ self.meta = {}
+ self.meta['ROOT_PARTITION'] = "%d" % self.g.part_to_partnum(self.root)
+ self.meta['OSFAMILY'] = self.g.inspect_get_type(self.root)
+ self.meta['OS'] = self.g.inspect_get_distro(self.root)
+ self.meta['DESCRIPTION'] = self.g.inspect_get_product_name(self.root)
+
def _is_sysprep(self, obj):
return getattr(obj, 'sysprep', False) and callable(obj)
if has_ftype(f, ftype):
action(full_path)
- def get_metadata(self):
- """Returns some descriptive metadata about the OS."""
- meta = {}
- meta['ROOT_PARTITION'] = "%d" % self.g.part_to_partnum(self.root)
- meta['OSFAMILY'] = self.g.inspect_get_type(self.root)
- meta['OS'] = self.g.inspect_get_distro(self.root)
- meta['DESCRIPTION'] = self.g.inspect_get_product_name(self.root)
-
- return meta
-
def do_sysprep(self):
"""Prepere system for image creation."""
class Ubuntu(Linux):
- def get_metadata(self):
- meta = super(Ubuntu, self).get_metadata()
+ def __init__(self, rootdev, ghandler):
+ super(Ubuntu, self).__init__(rootdev, ghandler)
+
apps = self.g.inspect_list_applications(self.root)
for app in apps:
if app['app_name'] == 'kubuntu-desktop':
- meta['OS'] = 'kubuntu'
- meta['DESCRIPTION'] = \
- meta['DESCRIPTION'].replace('Ubuntu', 'Kubuntu')
+ self.meta['OS'] = 'kubuntu'
+ self.meta['DESCRIPTION'] = \
+ self.meta['DESCRIPTION'].replace('Ubuntu', 'Kubuntu')
break
- return meta
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
'.thunderbird'
]
- def get_metadata(self):
- meta = super(Unix, self).get_metadata()
- meta["USERS"] = " ".join(self.get_passworded_users())
- return meta
+ def __init__(self, rootdev, ghandler):
+ super(Unix, self).__init__(rootdev, ghandler)
- def get_passworded_users(self):
+ self.meta["USERS"] = " ".join(self._get_passworded_users())
+
+ def _get_passworded_users(self):
users = []
regexp = re.compile('(\S+):((?:!\S+)|(?:[^!*]\S+)|):(?:\S*:){6}')
# Remove users from /etc/passwd
passwd = []
removed_users = {}
+ metadata_users = self.meta['USERS'].split()
for line in self.g.cat('/etc/passwd').splitlines():
fields = line.split(':')
if int(fields[2]) > 1000:
removed_users[fields[0]] = fields
+ # remove it from the USERS metadata too
+ if fields[0] in metadata_users:
+ metadata_users.remove(fields[0])
else:
passwd.append(':'.join(fields))
+ self.meta['USERS'] = " ".join(metadata_users)
self.g.write('/etc/passwd', '\n'.join(passwd) + '\n')
# Remove the corresponding /etc/shadow entries