From 57cc9639ddb4052285847c307da86e4a832c3706 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Thu, 22 Jun 2023 16:31:51 +0530 Subject: [PATCH] system packages to use common splitter --- .../data/image_introspect.py | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/ansible_navigator/data/image_introspect.py b/src/ansible_navigator/data/image_introspect.py index bd458a03a..7ab91447b 100644 --- a/src/ansible_navigator/data/image_introspect.py +++ b/src/ansible_navigator/data/image_introspect.py @@ -179,7 +179,6 @@ def splitter(self, lines, line_split, section_delim=None): """ results = [] result = {} - value = "" current_key = "" while lines: line = lines.pop(0) @@ -189,14 +188,25 @@ def splitter(self, lines, line_split, section_delim=None): results.append(result) result = {} continue - if not delim: - if value and current_key: - value = value + " " + content - result[current_key] = value + if not delim and current_key: + result[current_key] += f" {content}" continue current_key = key.lower().replace("_", "-").strip() - value = content - result[current_key] = value + # system_packages description field needs special handling + if current_key == "description": + description = [] + while lines: + line = lines.pop(0) + if line == section_delim: + break + description.append(line) + if description: + result[current_key] = " ".join(description) + else: + result[current_key] = "No description available" + results.append(result) + return result + result[current_key] = content if result: results.append(result) @@ -370,28 +380,8 @@ def parse(self, command): parsed = [] for package in packages: - entry = {} - while package: - line = package.pop(0) - left, _delim, right = self.re_partition(line, ":") - key = left.lower().replace("_", "-").strip() - - # Description is at the end of the package section - # read until package is empty - if key == "description": - description = [] - while package: - description.append(package.pop(0)) - # Normalize the data, in the case description is totally empty - if description: - entry[key] = "\n".join(description) - else: - entry[key] = "No description available" - parsed.append(entry) - # other package details are 1 line each - else: - value = self._strip(right) - entry[key] = value + result = self.splitter(package, line_split=":", section_delim="---") + parsed.append(result) command.details = parsed