Correct parsing error
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 11 Jun 2014 07:09:39 +0000 (09:09 +0200)
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Wed, 11 Jun 2014 07:09:39 +0000 (09:09 +0200)
While processing the pre/post install/uninstall scripts, in the case of
a one-line script of the form "%post -n <package_name> -p <command>",
if the package name or the command contains "-p" or "-n", parsing is
wrong. Usig " -p " and " -n " corrects this error in our cases. The
only package found with this error is pkmgr-info-parser. If a command
would happen to have a "-p" or "-n" option, parsing would fail, even
with this patch. Another solution would need to be found.

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

index 17ff3a2..92632ee 100755 (executable)
@@ -1705,9 +1705,9 @@ class MetaSpec:
         for section in script_sections:
             code = ""
             # If %section is a one line script such as: "%post -p /sbin/ldconfig"
-            if "-p" in section:
+            if " -p " in section:
                 # Remove the package name if present to only keep the command
-                section_split = section.split("-p")[1].split("-n")
+                section_split = section.split(" -p ")[1].split(" -n ")
                 code = "    " + section_split[0].strip()
             else:
                 code = self.__create_script_file_section_code(section)
@@ -1715,9 +1715,9 @@ class MetaSpec:
                 # Set the package name
                 package_name = "${PN}"
                 # If the package name is not the project name
-                if "-n" in section:
+                if " -n " in section:
                     # Remove the command if any to only keep the package name
-                    section_split = section.split("-n")[1].split("-p")
+                    section_split = section.split(" -n ")[1].split(" -p ")
                     package_name = section_split[0].strip()
                 self.__create_script_file_write(file_d, code, script_name, package_name)