Correct post/pre scripts extraction
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 4 Jun 2014 12:13:18 +0000 (14:13 +0200)
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 4 Jun 2014 12:13:18 +0000 (14:13 +0200)
Methods get_*_section_key() only return the first line of the pre/post
sections of spec files. This patch corrects that so the whole section
is returned instead.

Also factorize the code by replace the get_*_section_key() methods with
a unique one: get_script_section_key().

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

index 0327f9c..9543312 100755 (executable)
@@ -1189,50 +1189,17 @@ Group: devel
         #self.__preun_flag = "%preun"
         #self.__postun_flag = "%postun"
         #self.__pre_flag = "%pre"
-    def get_post_section_key( self ):
-        '''
-        return the list of file section of the spec file.
-        '''
-        res_file_list = []
-        for section_key in self.__spect_dico.keys():
-            # should use re.
-            if section_key.startswith( "%post " ):
-                res_file_list.append( section_key )
-        return res_file_list
-
-    def get_preun_section_key( self ):
-        '''
-        return the list of file section of the spec file.
-        '''
-        res_file_list = []
-        for section_key in self.__spect_dico.keys():
-            # should use re.
-            if section_key.startswith( "%preun " ):
-                res_file_list.append( section_key )
-        return res_file_list
-
-    def get_postun_section_key( self ):
-        '''
-        return the list of file section of the spec file.
-        '''
-        res_file_list = []
-        for section_key in self.__spect_dico.keys():
-            # should use re.
-            if section_key.startswith( "%postun " ):
-                res_file_list.append( section_key )
-        return res_file_list
 
-    def get_pre_section_key( self ):
+    def get_script_section_key( self, __flag ):
         '''
         return the list of file section of the spec file.
         '''
-        res_file_list = []
-        for section_key in self.__spect_dico.keys():
-            # should use re.
-            if section_key.startswith( "%pre " ):
-                res_file_list.append( section_key )
-        return res_file_list
+        res_script_section = ""
+        if __flag in self.__spect_dico.keys():
+            for line in self.__spect_dico[__flag][1:]:
+                res_script_section += line + "\n"
 
+        return res_script_section
 
     def get_files_list_from_section( self, package_section_name ):
         '''
@@ -1692,14 +1659,11 @@ class MetaSpec:
         generate script file.
         '''
         #pkg_preinst, pkg_postinst, pkg_prerm, and pkg_postrm
-        #self.__post_flag = "%post"
-        #self.__preun_flag = "%preun"
-        #self.__postun_flag = "%postun"
-        #self.__pre_flag = "%pre"
-        #print "post",self.__spec_parser.get_post_section_key(  )
-        #print "preun",self.__spec_parser.get_preun_section_key(  )
-        #print "postun",self.__spec_parser.get_postun_section_key(  )
-        #print "pre",self.__spec_parser.get_pre_section_key(  )
+
+        #print "pre", self.__spec_parser.get_script_section_key("%pre")
+        #print "post", self.__spec_parser.get_script_section_key("%post")
+        #print "preun", self.__spec_parser.get_script_section_key("%preun")
+        #print "postun", self.__spec_parser.get_script_section_key("%postun")
 
     def __create_provides_file( self ,file_d):
         '''