mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-07 00:57:22 +02:00
update calculated fields
This commit is contained in:
@ -12,6 +12,9 @@ Supports the following `pacman` arguments:
|
||||
- `-Qi`
|
||||
- `-Qii`
|
||||
|
||||
The `*_epoch` calculated timestamp fields are naive. (i.e. based on the
|
||||
local time of the system the parser is run on)
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ pacman -Si <package> | jc --pacman
|
||||
@ -62,10 +65,15 @@ Schema:
|
||||
"replaces": [
|
||||
string
|
||||
],
|
||||
"download_size": integer, # in bytes
|
||||
"installed_size": integer, # in bytes
|
||||
"download_size": string,
|
||||
"download_size_bytes": integer [0]
|
||||
"installed_size": string,
|
||||
"installed_size_bytes": integer, [0]
|
||||
"packager": string,
|
||||
"build_date": string,
|
||||
"build_date_epoch": integer, [0]
|
||||
"install_date": string,
|
||||
"install_date_epoch": integer, [0]
|
||||
"validated_by": [
|
||||
string
|
||||
],
|
||||
@ -75,6 +83,8 @@ Schema:
|
||||
}
|
||||
]
|
||||
|
||||
[0] Field exists if conversion successful
|
||||
|
||||
Examples:
|
||||
|
||||
$ pacman -qii zstd | jc --pacman -p
|
||||
@ -113,10 +123,13 @@ Examples:
|
||||
],
|
||||
"conflicts_with": [],
|
||||
"replaces": [],
|
||||
"installed_size": "1563648",
|
||||
"installed_size": "1527.00 KiB",
|
||||
"installed_size_bytes": 1563648,
|
||||
"packager": "Levente Polyak <anthraxx@archlinux.org>",
|
||||
"build_date": "Sat 11 May 2024 06:14:19 AM +08",
|
||||
"build_date_epoch": 1715433259,
|
||||
"install_date": "Fri 24 May 2024 09:50:31 AM +08",
|
||||
"install_date_epoch": 1715663342,
|
||||
"install_reason": "Installed as a dependency for another package",
|
||||
"install_script": "No",
|
||||
"validated_by": [
|
||||
|
@ -7,6 +7,9 @@ Supports the following `pacman` arguments:
|
||||
- `-Qi`
|
||||
- `-Qii`
|
||||
|
||||
The `*_epoch` calculated timestamp fields are naive. (i.e. based on the
|
||||
local time of the system the parser is run on)
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ pacman -Si <package> | jc --pacman
|
||||
@ -57,10 +60,15 @@ Schema:
|
||||
"replaces": [
|
||||
string
|
||||
],
|
||||
"download_size": integer, # in bytes
|
||||
"installed_size": integer, # in bytes
|
||||
"download_size": string,
|
||||
"download_size_bytes": integer [0]
|
||||
"installed_size": string,
|
||||
"installed_size_bytes": integer, [0]
|
||||
"packager": string,
|
||||
"build_date": string,
|
||||
"build_date_epoch": integer, [0]
|
||||
"install_date": string,
|
||||
"install_date_epoch": integer, [0]
|
||||
"validated_by": [
|
||||
string
|
||||
],
|
||||
@ -70,6 +78,8 @@ Schema:
|
||||
}
|
||||
]
|
||||
|
||||
[0] Field exists if conversion successful
|
||||
|
||||
Examples:
|
||||
|
||||
$ pacman -qii zstd | jc --pacman -p
|
||||
@ -108,10 +118,13 @@ Examples:
|
||||
],
|
||||
"conflicts_with": [],
|
||||
"replaces": [],
|
||||
"installed_size": "1563648",
|
||||
"installed_size": "1527.00 KiB",
|
||||
"installed_size_bytes": 1563648,
|
||||
"packager": "Levente Polyak <anthraxx@archlinux.org>",
|
||||
"build_date": "Sat 11 May 2024 06:14:19 AM +08",
|
||||
"build_date_epoch": 1715433259,
|
||||
"install_date": "Fri 24 May 2024 09:50:31 AM +08",
|
||||
"install_date_epoch": 1715663342,
|
||||
"install_reason": "Installed as a dependency for another package",
|
||||
"install_script": "No",
|
||||
"validated_by": [
|
||||
@ -195,21 +208,18 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
|
||||
'licenses', 'groups', 'provides', 'depends_on', 'conflicts_with',
|
||||
'replaces', 'optional_for'
|
||||
}
|
||||
|
||||
space_split_fields = {
|
||||
'required_by', 'groups', 'provides', 'depends_on',
|
||||
'conflicts_with', 'replaces', 'validated_by'
|
||||
}
|
||||
|
||||
two_space_fields = {'licenses', 'validated_by'}
|
||||
|
||||
name_description_fields = {'optional_deps'}
|
||||
|
||||
size_fields = {'download_size', 'installed_size'}
|
||||
date_fields = {'build_date', 'install_date'}
|
||||
|
||||
# initial split for field lists
|
||||
for item in proc_data:
|
||||
for key, val in item.items():
|
||||
for key, val in item.copy().items():
|
||||
if key in split_fields:
|
||||
if val is None:
|
||||
item[key] = []
|
||||
@ -237,7 +247,20 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
|
||||
item[key] = new_list
|
||||
|
||||
if key in size_fields:
|
||||
item[key] = jc.utils.convert_size_to_int(val)
|
||||
bts = jc.utils.convert_size_to_int(val)
|
||||
if bts:
|
||||
item[key + '_bytes'] = bts
|
||||
|
||||
if key in date_fields:
|
||||
# need to append '00' to date for conversion
|
||||
ts = jc.utils.timestamp(val + '00', format_hint=(3100,))
|
||||
if ts.naive:
|
||||
item[key + '_epoch'] = ts.naive
|
||||
else:
|
||||
# try taking off the text TZ identifier
|
||||
ts = jc.utils.timestamp(val[:-4], format_hint=(3000,))
|
||||
if ts.naive:
|
||||
item[key + '_epoch'] = ts.naive
|
||||
|
||||
return proc_data
|
||||
|
||||
|
@ -703,6 +703,7 @@ class timestamp:
|
||||
{'id': 1800, 'format': '%d/%b/%Y:%H:%M:%S %z', 'locale': None}, # Common Log Format: 10/Oct/2000:13:55:36 -0700
|
||||
{'id': 2000, 'format': '%a %d %b %Y %I:%M:%S %p %Z', 'locale': None}, # en_US.UTF-8 local format (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM UTC
|
||||
{'id': 3000, 'format': '%a %d %b %Y %I:%M:%S %p', 'locale': None}, # en_US.UTF-8 local format with non-UTC tz (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM IST
|
||||
{'id': 3100, 'format': '%a %d %b %Y %I:%M:%S %p %z', 'locale': None}, # pacman format - append 00 to end to make it work: # Sat 11 May 2024 06:14:19 AM +0800
|
||||
{'id': 3500, 'format': '%a, %d %b %Y %H:%M:%S %Z', 'locale': None}, # HTTP header time format (always GMT so assume UTC): Wed, 31 Jan 2024 00:39:28 GMT
|
||||
{'id': 4000, 'format': '%A %d %B %Y %I:%M:%S %p %Z', 'locale': None}, # European-style local format (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM UTC
|
||||
{'id': 5000, 'format': '%A %d %B %Y %I:%M:%S %p', 'locale': None}, # European-style local format with non-UTC tz (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM IST
|
||||
|
2
man/jc.1
2
man/jc.1
@ -1,4 +1,4 @@
|
||||
.TH jc 1 2024-11-24 1.25.4 "JSON Convert"
|
||||
.TH jc 1 2024-11-25 1.25.4 "JSON Convert"
|
||||
.SH NAME
|
||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
|
||||
and strings
|
||||
|
2
tests/fixtures/generic/pacman--packages.json
vendored
2
tests/fixtures/generic/pacman--packages.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/generic/pacman--qii-zstd.json
vendored
2
tests/fixtures/generic/pacman--qii-zstd.json
vendored
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
[{"repository":"extra","name":"graphicsmagick","version":"1.3.43-1","description":"Image processing system","architecture":"x86_64","url":"http://www.graphicsmagick.org/","licenses":["MIT"],"groups":[],"provides":["Magick.so","libGraphicsMagickWand.so=2-64","libGraphicsMagick.so=3-64","libGraphicsMagick++-Q16.so"],"depends_on":["bzip2","freetype2","lcms2","libltdl","libpng","libsm","libtiff","libwebp","libxext","xz"],"optional_deps":[{"name":"jasper","description":"jp2 module"},{"name":"libwmf","description":"wmf module"},{"name":"libxml2","description":"msl, svg, url modules"},{"name":"ghostscript","description":"pdf, ps modules"},{"name":"libheif","description":"heic module"},{"name":"libjxl","description":"jpeg-xl module"}],"conflicts_with":[],"replaces":[],"download_size":2705326,"installed_size":14648606,"packager":"Caleb Maclennan <alerque@archlinux.org>","build_date":"Sat 23 Mar 2024 09:55:47 PM CET","validated_by":["MD5 Sum","SHA-256 Sum","Signature"]}]
|
||||
[{"repository":"extra","name":"graphicsmagick","version":"1.3.43-1","description":"Image processing system","architecture":"x86_64","url":"http://www.graphicsmagick.org/","licenses":["MIT"],"groups":[],"provides":["Magick.so","libGraphicsMagickWand.so=2-64","libGraphicsMagick.so=3-64","libGraphicsMagick++-Q16.so"],"depends_on":["bzip2","freetype2","lcms2","libltdl","libpng","libsm","libtiff","libwebp","libxext","xz"],"optional_deps":[{"name":"jasper","description":"jp2 module"},{"name":"libwmf","description":"wmf module"},{"name":"libxml2","description":"msl, svg, url modules"},{"name":"ghostscript","description":"pdf, ps modules"},{"name":"libheif","description":"heic module"},{"name":"libjxl","description":"jpeg-xl module"}],"conflicts_with":[],"replaces":[],"download_size":"2.58 MiB","installed_size":"13.97 MiB","packager":"Caleb Maclennan <alerque@archlinux.org>","build_date":"Sat 23 Mar 2024 09:55:47 PM CET","validated_by":["MD5 Sum","SHA-256 Sum","Signature"],"download_size_bytes":2705326,"installed_size_bytes":14648606,"build_date_epoch":1711256147}]
|
||||
|
Reference in New Issue
Block a user