mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-07 00:57:22 +02:00
fix for pip-show parser with multi-line fields starting with a blank line
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
jc changelog
|
||||
|
||||
20240429 v1.25.3
|
||||
20240502 v1.25.3
|
||||
- Add `battery_percentage` field to `bluetoothctl` parser output
|
||||
- Fix `pci-ids` parser to correctly handle multiple subdevices
|
||||
- Fix `pip-show` parser to handle multi-line fields with a beginning blank line
|
||||
- Fix `top` parsers to quiet uptime info parsing
|
||||
- Fix `traceroute` parser to correctly handle hops with multiple IPs
|
||||
- Optimize some tests by removing timezone settings and using quiet=True
|
||||
|
@ -90,4 +90,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Source: [`jc/parsers/pip_show.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/pip_show.py)
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
@ -66,7 +66,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
version = '1.5'
|
||||
description = '`pip show` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -144,6 +144,8 @@ def parse(
|
||||
item_value = None
|
||||
|
||||
if last_key_data and last_key != item_key:
|
||||
if not isinstance(package[last_key], str):
|
||||
package[last_key] = ''
|
||||
package[last_key] = package[last_key] + '\n' + '\n'.join(last_key_data)
|
||||
last_key_data = []
|
||||
|
||||
|
2
man/jc.1
2
man/jc.1
@ -1,4 +1,4 @@
|
||||
.TH jc 1 2024-04-29 1.25.3 "JSON Convert"
|
||||
.TH jc 1 2024-05-02 1.25.3 "JSON Convert"
|
||||
.SH NAME
|
||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
|
||||
and strings
|
||||
|
1
tests/fixtures/generic/pip-show-multiline-license-first-blank.json
vendored
Normal file
1
tests/fixtures/generic/pip-show-multiline-license-first-blank.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"name":"setuptools","version":"39.2.0","summary":"Easily download, build, install, upgrade, and uninstall Python packages","home_page":"https://github.com/pypa/setuptools","author":"Python Packaging Authority","author_email":"distutils-sig@python.org","license":"UNKNOWN","location":"/usr/lib/python3.6/site-packages","requires":null,"required_by":"twine"},{"name":"pkginfo","version":"1.5.0.1","summary":"Query metadatdata from sdists / bdists / installed packages.","home_page":"https://code.launchpad.net/~tseaver/pkginfo/trunk","author":"Tres Seaver, Agendaless Consulting","author_email":"tseaver@agendaless.com","license":"MIT","location":"/home/kbrazil/.local/lib/python3.6/site-packages","requires":null,"required_by":"twine"},{"name":"cppy","version":"1.2.1","summary":"UNKNOWN","home_page":"https://github.com/nucleic/cppy","author":"None","author_email":"The Nucleic Development Team <sccolbert@gmail.com>","license":"\nCopyright (c) 2014, Nucleic\nAll rights reserved.\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n* Redistributions of source code must retain the above copyright notice, this\nlist of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n* Neither the name of the copyright holder nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","location":"/usr/home/bryder/.local/lib/python3.7/site-packages","requires":null,"required_by":null},{"name":"six","version":"1.12.0","summary":"Python 2 and 3 compatibility utilities","home_page":"https://github.com/benjaminp/six","author":"Benjamin Peterson","author_email":"benjamin@python.org","license":"MIT","location":"/home/kbrazil/.local/lib/python3.6/site-packages","requires":null,"required_by":"readme-renderer, bleach"},{"name":"cppy","version":"1.2.1","summary":"UNKNOWN","home_page":"https://github.com/nucleic/cppy","author":"None","author_email":"The Nucleic Development Team <sccolbert@gmail.com>","license":"\n\nCopyright (c) 2014, Nucleic\nAll rights reserved.\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n* Redistributions of source code must retain the above copyright notice, this\nlist of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n* Neither the name of the copyright holder nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","location":"/usr/home/bryder/.local/lib/python3.7/site-packages","requires":null,"required_by":null}]
|
99
tests/fixtures/generic/pip-show-multiline-license-first-blank.out
vendored
Normal file
99
tests/fixtures/generic/pip-show-multiline-license-first-blank.out
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
Name: setuptools
|
||||
Version: 39.2.0
|
||||
Summary: Easily download, build, install, upgrade, and uninstall Python packages
|
||||
Home-page: https://github.com/pypa/setuptools
|
||||
Author: Python Packaging Authority
|
||||
Author-email: distutils-sig@python.org
|
||||
License: UNKNOWN
|
||||
Location: /usr/lib/python3.6/site-packages
|
||||
Requires:
|
||||
Required-by: twine
|
||||
---
|
||||
Name: pkginfo
|
||||
Version: 1.5.0.1
|
||||
Summary: Query metadatdata from sdists / bdists / installed packages.
|
||||
Home-page: https://code.launchpad.net/~tseaver/pkginfo/trunk
|
||||
Author: Tres Seaver, Agendaless Consulting
|
||||
Author-email: tseaver@agendaless.com
|
||||
License: MIT
|
||||
Location: /home/kbrazil/.local/lib/python3.6/site-packages
|
||||
Requires:
|
||||
Required-by: twine
|
||||
---
|
||||
Name: cppy
|
||||
Version: 1.2.1
|
||||
Summary: UNKNOWN
|
||||
Home-page: https://github.com/nucleic/cppy
|
||||
Author: None
|
||||
Author-email: The Nucleic Development Team <sccolbert@gmail.com>
|
||||
License:
|
||||
Copyright (c) 2014, Nucleic
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Location: /usr/home/bryder/.local/lib/python3.7/site-packages
|
||||
Requires:
|
||||
Required-by:
|
||||
---
|
||||
Name: six
|
||||
Version: 1.12.0
|
||||
Summary: Python 2 and 3 compatibility utilities
|
||||
Home-page: https://github.com/benjaminp/six
|
||||
Author: Benjamin Peterson
|
||||
Author-email: benjamin@python.org
|
||||
License: MIT
|
||||
Location: /home/kbrazil/.local/lib/python3.6/site-packages
|
||||
Requires:
|
||||
Required-by: readme-renderer, bleach
|
||||
---
|
||||
Name: cppy
|
||||
Version: 1.2.1
|
||||
Summary: UNKNOWN
|
||||
Home-page: https://github.com/nucleic/cppy
|
||||
Author: None
|
||||
Author-email: The Nucleic Development Team <sccolbert@gmail.com>
|
||||
License:
|
||||
|
||||
Copyright (c) 2014, Nucleic
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Location: /usr/home/bryder/.local/lib/python3.7/site-packages
|
||||
Requires:
|
||||
Required-by:
|
@ -24,6 +24,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license.out'), 'r', encoding='utf-8') as f:
|
||||
generic_pip_show_multiline_license = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license-first-blank.out'), 'r', encoding='utf-8') as f:
|
||||
generic_pip_show_multiline_license_first_blank = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/pip-show.json'), 'r', encoding='utf-8') as f:
|
||||
centos_7_7_pip_show_json = json.loads(f.read())
|
||||
@ -40,6 +43,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license.json'), 'r', encoding='utf-8') as f:
|
||||
generic_pip_show_multiline_license_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license-first-blank.json'), 'r', encoding='utf-8') as f:
|
||||
generic_pip_show_multiline_license_first_blank_json = json.loads(f.read())
|
||||
|
||||
|
||||
def test_pip_show_nodata(self):
|
||||
"""
|
||||
@ -77,6 +83,12 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.pip_show.parse(self.generic_pip_show_multiline_license, quiet=True), self.generic_pip_show_multiline_license_json)
|
||||
|
||||
def test_pip_show_multiline_license_first_blank(self):
|
||||
"""
|
||||
Test 'pip show' with a multiline license where the first line is blank
|
||||
"""
|
||||
self.assertEqual(jc.parsers.pip_show.parse(self.generic_pip_show_multiline_license_first_blank, quiet=True), self.generic_pip_show_multiline_license_first_blank_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user