1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00
Files
jc/docs/parsers/stat.md

182 lines
4.1 KiB
Markdown
Raw Normal View History

2020-07-30 16:20:24 -07:00
2019-11-14 17:23:44 -08:00
# jc.parsers.stat
2020-08-05 16:51:58 -07:00
jc - JSON CLI output utility `stat` command output parser
2019-11-14 17:23:44 -08:00
2020-08-05 13:32:59 -07:00
Usage (cli):
2019-12-12 09:47:14 -08:00
2020-08-05 16:51:58 -07:00
$ stat * | jc --stat
or
$ jc stat *
2019-12-12 09:35:42 -08:00
2020-08-05 13:32:59 -07:00
Usage (module):
import jc.parsers.stat
result = jc.parsers.stat.parse(stat_command_output)
2019-12-12 09:35:42 -08:00
Compatibility:
2019-12-12 09:47:14 -08:00
2020-05-30 15:51:54 -07:00
'linux', 'darwin', 'freebsd'
2019-11-14 17:23:44 -08:00
Examples:
$ stat /bin/* | jc --stat -p
[
{
"file": "/bin/bash",
"size": 1113504,
"blocks": 2176,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131099,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
2019-11-14 20:57:49 -08:00
"birth_time": null
2019-11-14 17:23:44 -08:00
},
{
"file": "/bin/btrfs",
"size": 716464,
"blocks": 1400,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131100,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
2019-11-14 17:36:29 -08:00
"birth_time": null
2019-11-14 17:23:44 -08:00
},
...
]
$ stat /bin/* | jc --stat -p -r
[
{
"file": "/bin/bash",
"size": "1113504",
"blocks": "2176",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131099",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
2019-11-14 20:57:49 -08:00
"birth_time": null
2019-11-14 17:23:44 -08:00
},
{
"file": "/bin/btrfs",
"size": "716464",
"blocks": "1400",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131100",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
2019-11-14 17:36:29 -08:00
"birth_time": null
2019-11-14 17:23:44 -08:00
},
..
]
2020-07-30 16:20:24 -07:00
2019-12-14 23:35:42 -08:00
## info
```python
2020-07-30 16:20:24 -07:00
info()
2019-12-14 23:35:42 -08:00
```
2020-07-30 16:20:24 -07:00
2019-11-14 17:23:44 -08:00
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
2021-01-04 18:01:16 -08:00
proc_data: (List of Dictionaries) raw structured data to process
2019-11-14 17:23:44 -08:00
Returns:
2021-01-04 18:01:16 -08:00
List of Dictionaries. Structured data with the following schema:
2019-11-14 17:23:44 -08:00
[
{
"file": string,
"link_to" string,
"size": integer,
"blocks": integer,
"io_blocks": integer,
"type": string,
"device": string,
"inode": integer,
"links": integer,
"access": string,
"flags": string,
"uid": integer,
"user": string,
"gid": integer,
"group": string,
2019-11-14 17:36:29 -08:00
"access_time": string, # - = null
"modify_time": string, # - = null
"change_time": string, # - = null
2020-05-22 16:21:40 -07:00
"birth_time": string, # - = null
2020-05-30 20:33:00 -07:00
"unix_device": integer,
2020-05-22 16:21:40 -07:00
"rdev": integer,
"block_size": integer,
2020-05-30 20:33:00 -07:00
"unix_flags": string
2019-11-14 17:23:44 -08:00
}
]
2020-07-30 16:20:24 -07:00
2019-11-14 17:23:44 -08:00
## 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:
2021-01-04 18:01:16 -08:00
List of Dictionaries. Raw or processed structured data.
2019-11-14 17:23:44 -08:00