From 1832daa1d247a546069f901427995f0b9f2addf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Tue, 15 Dec 2015 14:36:41 +0100 Subject: [PATCH 1/2] Add rpm.minimal_info, fix rpm.info rpm.info: report epoch (if present) and architecture add rpm.minimal_info to just report name, epoch, version, release, architecture, and installtime --- salt/modules/rpm.py | 97 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/salt/modules/rpm.py b/salt/modules/rpm.py index 032f8dadc87a..9fb89c994d9b 100644 --- a/salt/modules/rpm.py +++ b/salt/modules/rpm.py @@ -413,43 +413,15 @@ def _pkg_time_to_iso(pkg_time): return datetime.datetime(ptime.tm_year, ptime.tm_mon, ptime.tm_mday, ptime.tm_hour, ptime.tm_min, ptime.tm_sec).isoformat() + "Z" - -def info(*packages): +def query_rpm(queryformat, *packages): ''' - Return a detailed package(s) summary information. - If no packages specified, all packages will be returned. - - :param packages: - :return: - - CLI example: - - .. code-block:: bash - - salt '*' lowpkg.info apache2 bash + Internal function for info() and minimal_info() to query rpm and parse it's output ''' cmd = packages and "rpm -q {0}".format(' '.join(packages)) or "rpm -qa" # Locale needs to be en_US instead of C, because RPM otherwise will yank the timezone from the timestamps - call = __salt__['cmd.run_all'](cmd + (" --queryformat 'Name: %{NAME}\n" - "Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocatable)}|\n" - "Version: %{VERSION}\n" - "Vendor: %{VENDOR}\n" - "Release: %{RELEASE}\n" - "Build Date: %{BUILDTIME:date}\n" - "Install Date: %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n" - "Build Host: %{BUILDHOST}\n" - "Group: %{GROUP}\n" - "Source RPM: %{SOURCERPM}\n" - "Size: %{LONGSIZE}\n" - "%|LICENSE?{License: %{LICENSE}\n}|" - "Signature: %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\n" - "%|PACKAGER?{Packager: %{PACKAGER}\n}|" - "%|URL?{URL: %{URL}\n}|" - "Summary: %{SUMMARY}\n" - "Description:\n%{DESCRIPTION}\n" - "-----\n'"), + call = __salt__['cmd.run_all'](cmd + queryformat, output_loglevel='trace', env={'LC_ALL': 'en_US', 'TZ': 'UTC'}, clean_env=True) if call['retcode'] != 0: comment = '' @@ -490,8 +462,69 @@ def info(*packages): value = _pkg_time_to_iso(value) if key != 'description' and value: pkg_data[key] = value - pkg_data['description'] = os.linesep.join(descr) + if len(descr) > 0: + pkg_data['description'] = os.linesep.join(descr) if pkg_name: ret[pkg_name] = pkg_data return ret + +def info(*packages): + ''' + Return a detailed package(s) summary information. + If no packages specified, all packages will be returned. + + :param packages: + :return: + + CLI example: + + .. code-block:: bash + + salt '*' lowpkg.info apache2 bash + ''' + + return query_rpm(" --queryformat 'Name: %{NAME}\n" + "Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocatable)}|\n" + "%|EPOCH?{Epoch: %{EPOCH}\n}|" + "Version: %{VERSION}\n" + "Vendor: %{VENDOR}\n" + "Release: %{RELEASE}\n" + "Architecture: %{ARCH}\n" + "Build Date: %{BUILDTIME:date}\n" + "Install Date: %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n" + "Build Host: %{BUILDHOST}\n" + "Group: %{GROUP}\n" + "Source RPM: %{SOURCERPM}\n" + "Size: %{LONGSIZE}\n" + "%|LICENSE?{License: %{LICENSE}\n}|" + "Signature: %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\n" + "%|PACKAGER?{Packager: %{PACKAGER}\n}|" + "%|URL?{URL: %{URL}\n}|" + "Summary: %{SUMMARY}\n" + "Description:\n%{DESCRIPTION}\n" + "-----\n'", *packages) + +def minimal_info(*packages): + ''' + Return a minimal package(s) information (name, epoch, version, release, arch, installtime). + If no packages specified, all packages will be returned. + + :param packages: + :return: + + CLI example: + + .. code-block:: bash + + salt '*' lowpkg.minimal_info apache2 bash + ''' + + return query_rpm(" --queryformat 'Name: %{NAME}\n" + "%|EPOCH?{Epoch: %{EPOCH}\n}|" + "Version: %{VERSION}\n" + "Release: %{RELEASE}\n" + "Architecture: %{ARCH}\n" + "Install Date: %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n" + "-----\n'", *packages) + \ No newline at end of file -- 2.6.3