From: Artem Bityutskiy Date: Fri, 21 Jun 2013 06:02:04 +0000 (+0300) Subject: baseimager: export a number of helful environment variables X-Git-Tag: 0.20~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5271a99f7607276114b85fc0f04986229cb7110;p=tools%2Fmic.git baseimager: export a number of helful environment variables Make the MIC export a number of environment variables for the %post section of the KickStart file. Signed-off-by: Artem Bityutskiy --- diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 7a765c3..39bb6dd 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -73,6 +73,7 @@ class BaseImageCreator(object): self.cachedir = "/var/tmp/mic/cache" self.workdir = "/var/tmp/mic/build" self.destdir = "." + self.installerfw_prefix = "INSTALLERFW_" self.target_arch = "noarch" self._local_pkgs_path = None self.pack_to = None @@ -401,6 +402,25 @@ class BaseImageCreator(object): s += "sysfs /sys sysfs defaults 0 0\n" return s + def _set_part_env(self, pnum, prop, value): + """ This is a helper function which generates an environment variable + for a property "prop" with value "value" of a partition number "pnum". + + The naming convention is: + * Variables start with INSTALLERFW_PART + * Then goes the partition number, the order is the same as + specified in the KS file + * Then goes the property name + """ + + if value == None: + value = "" + else: + value = str(value) + + name = self.installerfw_prefix + ("PART%d_" % pnum) + prop + return { name : value } + def _get_post_scripts_env(self, in_chroot): """Return an environment dict for %post scripts. @@ -408,13 +428,42 @@ class BaseImageCreator(object): variables for %post scripts by return a dict containing the desired environment. - By default, this returns an empty dict. - in_chroot -- whether this %post script is to be executed chroot()ed into _instroot. - """ - return {} + + env = {} + pnum = 0 + + for p in kickstart.get_partitions(self.ks): + env.update(self._set_part_env(pnum, "SIZE", p.size)) + env.update(self._set_part_env(pnum, "MOUNTPOINT", p.mountpoint)) + env.update(self._set_part_env(pnum, "FSTYPE", p.fstype)) + env.update(self._set_part_env(pnum, "LABEL", p.label)) + env.update(self._set_part_env(pnum, "FSOPTS", p.fsopts)) + env.update(self._set_part_env(pnum, "BOOTFLAG", p.active)) + env.update(self._set_part_env(pnum, "ALIGN", p.align)) + env.update(self._set_part_env(pnum, "TYPE_ID", p.part_type)) + pnum += 1 + + # Count of paritions + env[self.installerfw_prefix + "PART_COUNT"] = str(pnum) + + # Partition table format + ptable_format = self.ks.handler.bootloader.ptable + env[self.installerfw_prefix + "PTABLE_FORMAT"] = ptable_format + + # The kerned boot parameters + kernel_opts = self.ks.handler.bootloader.appendLine + env[self.installerfw_prefix + "KERNEL_OPTS"] = kernel_opts + + # Name of the distribution + env[self.installerfw_prefix + "DISTRO_NAME"] = self.distro_name + + # Name of the image creation tool + env[self.installerfw_prefix + "INSTALLER_NAME"] = "mic" + + return env def __get_imgname(self): return self.name diff --git a/mic/imager/raw.py b/mic/imager/raw.py index c9c145a..2ac8e46 100644 --- a/mic/imager/raw.py +++ b/mic/imager/raw.py @@ -355,6 +355,14 @@ class RawImageCreator(BaseImageCreator): def _resparse(self, size = None): return self.__instloop.resparse(size) + def _get_post_scripts_env(self, in_chroot): + env = BaseImageCreator._get_post_scripts_env(self, in_chroot) + + for p in self.__instloop.partitions: + env.update(self._set_part_env(p['ks_pnum'], "PARTUUID", p['partuuid'])) + + return env + def _stage_final_image(self): """Stage the final system image in _outdir. write meta data