From abee226591ed4ae37351efc995017d28b27827d9 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 6 Apr 2021 18:32:47 -0700 Subject: [PATCH] rename rpm_qia to rpm_qi --- README.md | 2 +- docs/parsers/rpm_qi.md | 191 +++++++++++++++++++++++++++ jc/cli.py | 2 +- jc/parsers/{rpm_qai.py => rpm_qi.py} | 20 +-- man/jc.1 | 4 +- 5 files changed, 205 insertions(+), 14 deletions(-) create mode 100644 docs/parsers/rpm_qi.md rename jc/parsers/{rpm_qai.py => rpm_qi.py} (94%) diff --git a/README.md b/README.md index ad1d4651..82f3b58e 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio - `--pip-show` enables the `pip show` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_show)) - `--ps` enables the `ps` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ps)) - `--route` enables the `route` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/route)) -- `--rpm_qai` enables the `rpm -qai` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qai)) +- `--rpm_qi` enables the `rpm -qi` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi)) - `--shadow` enables the `/etc/shadow` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/shadow)) - `--ss` enables the `ss` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ss)) - `--stat` enables the `stat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/stat)) diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md new file mode 100644 index 00000000..694ea151 --- /dev/null +++ b/docs/parsers/rpm_qi.md @@ -0,0 +1,191 @@ + +# jc.parsers.rpm_qi +jc - JSON CLI output utility `rpm -qi` command output parser + +Works with `rpm -qi [package]` or `rpm -qia`. + +The `build_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on) + +The `build_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC. + +Usage (cli): + + $ rpm -qia | jc --rpm_qi + + or + + $ jc rpm -qia + +Usage (module): + + import jc.parsers.rpm_qi + result = jc.parsers.rpm_qi.parse(rpm_qi_command_output) + +Compatibility: + + 'linux' + +Examples: + + $ rpm_qia | jc --rpm_qi -p + [ + { + "name": "make", + "epoch": 1, + "version": "3.82", + "release": "24.el7", + "architecture": "x86_64", + "install_date": "Wed 16 Oct 2019 09:21:42 AM PDT", + "group": "Development/Tools", + "size": 1160660, + "license": "GPLv2+", + "signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5", + "source_rpm": "make-3.82-24.el7.src.rpm", + "build_date": "Thu 08 Aug 2019 05:47:25 PM PDT", + "build_host": "x86-01.bsys.centos.org", + "relocations": "(not relocatable)", + "packager": "CentOS BuildSystem ", + "vendor": "CentOS", + "url": "http://www.gnu.org/software/make/", + "summary": "A GNU tool which simplifies the build process for users", + "description": "A GNU tool for controlling the generation of executables and other non-source...", + "build_epoch": 1565311645, + "build_epoch_utc": null + }, + { + "name": "kbd-legacy", + "version": "1.15.5", + "release": "15.el7", + "architecture": "noarch", + "install_date": "Thu 15 Aug 2019 10:53:08 AM PDT", + "group": "System Environment/Base", + "size": 503608, + "license": "GPLv2+", + "signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5", + "source_rpm": "kbd-1.15.5-15.el7.src.rpm", + "build_date": "Tue 30 Oct 2018 03:40:00 PM PDT", + "build_host": "x86-01.bsys.centos.org", + "relocations": "(not relocatable)", + "packager": "CentOS BuildSystem ", + "vendor": "CentOS", + "url": "http://ftp.altlinux.org/pub/people/legion/kbd", + "summary": "Legacy data for kbd package", + "description": "The kbd-legacy package contains original keymaps for kbd package. Please note...", + "build_epoch": 1540939200, + "build_epoch_utc": null + }, + ... + ] + + $ rpm -qia | jc --rpm_qi -p -r + [ + { + "name": "make", + "epoch": "1", + "version": "3.82", + "release": "24.el7", + "architecture": "x86_64", + "install_date": "Wed 16 Oct 2019 09:21:42 AM PDT", + "group": "Development/Tools", + "size": "1160660", + "license": "GPLv2+", + "signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5", + "source_rpm": "make-3.82-24.el7.src.rpm", + "build_date": "Thu 08 Aug 2019 05:47:25 PM PDT", + "build_host": "x86-01.bsys.centos.org", + "relocations": "(not relocatable)", + "packager": "CentOS BuildSystem ", + "vendor": "CentOS", + "url": "http://www.gnu.org/software/make/", + "summary": "A GNU tool which simplifies the build process for users", + "description": "A GNU tool for controlling the generation of executables and other..." + }, + { + "name": "kbd-legacy", + "version": "1.15.5", + "release": "15.el7", + "architecture": "noarch", + "install_date": "Thu 15 Aug 2019 10:53:08 AM PDT", + "group": "System Environment/Base", + "size": "503608", + "license": "GPLv2+", + "signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5", + "source_rpm": "kbd-1.15.5-15.el7.src.rpm", + "build_date": "Tue 30 Oct 2018 03:40:00 PM PDT", + "build_host": "x86-01.bsys.centos.org", + "relocations": "(not relocatable)", + "packager": "CentOS BuildSystem ", + "vendor": "CentOS", + "url": "http://ftp.altlinux.org/pub/people/legion/kbd", + "summary": "Legacy data for kbd package", + "description": "The kbd-legacy package contains original keymaps for kbd package..." + }, + ... + ] + + +## info +```python +info() +``` + + +## process +```python +process(proc_data) +``` + +Final processing to conform to the schema. + +Parameters: + + proc_data: (List of Dictionaries) raw structured data to process + +Returns: + + List of Dictionaries. Structured data with the following schema: + + [ + { + "name": string, + "epoch": integer, + "version": string, + "release": string, + "architecture": string, + "install_date": string, + "group": string, + "size": integer, + "license": string, + "signature": string, + "source_rpm": string, + "build_date": string, + "build_epoch": integer, # naive timestamp + "build_epoch_utc": integer, # Aware timestamp if timezone is UTC + "build_host": string, + "relocations": string, + "packager": string, + "vendor": string, + "url": string, + "summary": string, + "description": string + } + ] + + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + List of Dictionaries. Raw or processed structured data. + diff --git a/jc/cli.py b/jc/cli.py index c713672f..a7d6622a 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -88,7 +88,7 @@ parsers = [ 'pip-show', 'ps', 'route', - 'rpm_qai', + 'rpm_qi', 'shadow', 'ss', 'stat', diff --git a/jc/parsers/rpm_qai.py b/jc/parsers/rpm_qi.py similarity index 94% rename from jc/parsers/rpm_qai.py rename to jc/parsers/rpm_qi.py index 6fb2dbda..a5d4f5ec 100644 --- a/jc/parsers/rpm_qai.py +++ b/jc/parsers/rpm_qi.py @@ -1,6 +1,6 @@ -"""jc - JSON CLI output utility `rpm -qai` command output parser +"""jc - JSON CLI output utility `rpm -qi` command output parser -Works with `rpm -qi [package]` or `rpm -qai`. +Works with `rpm -qi [package]` or `rpm -qia`. The `build_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on) @@ -8,16 +8,16 @@ The `build_epoch_utc` calculated timestamp field is timezone-aware and is only a Usage (cli): - $ rpm -qai | jc --rpm_qai + $ rpm -qia | jc --rpm_qi or - $ jc rpm -qai + $ jc rpm -qia Usage (module): - import jc.parsers.rpm_qai - result = jc.parsers.rpm_qai.parse(rpm_qai_command_output) + import jc.parsers.rpm_qi + result = jc.parsers.rpm_qi.parse(rpm_qi_command_output) Compatibility: @@ -25,7 +25,7 @@ Compatibility: Examples: - $ rpm_qai | jc --rpm_qai -p + $ rpm_qia | jc --rpm_qi -p [ { "name": "make", @@ -75,7 +75,7 @@ Examples: ... ] - $ rpm -qai | jc --rpm_qai -p -r + $ rpm -qia | jc --rpm_qi -p -r [ { "name": "make", @@ -126,14 +126,14 @@ import jc.utils class info(): version = '1.0' - description = '`rpm -qai` command parser' + description = '`rpm -qi` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' # details = 'enter any other details here' # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] - magic_commands = ['rpm -qai', 'rpm -qia', 'rpm -qi'] + magic_commands = ['rpm -qi', 'rpm -qia', 'rpm -qai'] __version__ = info.version diff --git a/man/jc.1 b/man/jc.1 index a7008b72..e51b255d 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -264,8 +264,8 @@ Key/Value file parser .TP .B -\fB--rpm_qai\fP -`rpm -qai` command parser +\fB--rpm_qi\fP +`rpm -qi` command parser .TP .B