Add pre, preun and postun scripts to recipes
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 4 Jun 2014 14:13:44 +0000 (16:13 +0200)
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 4 Jun 2014 14:15:29 +0000 (16:15 +0200)
Note that only the first reference to a section found in spec files are
treated, the other ones are ignored. This issue should be taken care of.

Signed-off-by: Kévin THIERRY <kevin.thierry@open.eurogiciel.org>
tools/spec2yocto.py

index a871291..ba384e3 100755 (executable)
@@ -1654,13 +1654,14 @@ class MetaSpec:
         file_d.write( "}\n" )
         file_d.write( "\n" )
 
-    def __create_script_file( self ,file_d):
+    def __create_script_file_section( self, spec_section):
         '''
-        generate script file.
+        Returns the command executed in one of the %pre, %post, %preun
+        or %postun section of a spec file with the necessary Yocto
+        prefix "${D}".
         '''
-        #pkg_preinst, pkg_postinst, pkg_prerm, and pkg_postrm
 
-        code = self.__spec_parser.get_script_section_key("%post")
+        code = self.__spec_parser.get_script_section_key(spec_section)
         command_list = code.split("\n")
         formated_code = ""
         for line in command_list:
@@ -1671,11 +1672,43 @@ class MetaSpec:
         formated_code = formated_code.replace(" /lib", " ${D}/lib")
         formated_code = formated_code.replace(" /sbin", " ${D}/sbin")
 
-        file_d.write("pkg_postinst_${PN}() {\n")
-        file_d.write("%s\n" % formated_code)
+        return formated_code
+
+    def __create_script_file_write( self, file_d, code, recipe_section):
+        '''
+        Writes the pre/post (un)install sections of the recipe.
+        '''
+
+        file_d.write("%s() {\n" % recipe_section)
+        file_d.write("    #!/bin/sh -e\n")
+        file_d.write("%s\n" % code)
         file_d.write("}\n")
         file_d.write("\n")
 
+    def __create_script_file( self, file_d):
+        '''
+        Add the pre/post install/uninstall sections of a spec file to
+        the recipe.
+        '''
+
+        #pkg_preinst, pkg_postinst, pkg_prerm, and pkg_postrm
+
+        code = self.__create_script_file_section("%pre")
+        if code != "":
+            self.__create_script_file_write(file_d, code, "pkg_preinst_${PN}")
+
+        code = self.__create_script_file_section("%post")
+        if code != "":
+            self.__create_script_file_write(file_d, code, "pkg_postinst_${PN}")
+
+        code = self.__create_script_file_section("%preun")
+        if code != "":
+            self.__create_script_file_write(file_d, code, "pkg_prerm_${PN}")
+
+        code = self.__create_script_file_section("%postun")
+        if code != "":
+            self.__create_script_file_write(file_d, code, "pkg_postrm_${PN}")
+
     def __create_provides_file( self ,file_d):
         '''
         generate provide file.