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

122 lines
3.7 KiB
Markdown
Raw Normal View History

2022-01-06 11:00:53 -08:00
[Home](https://kellyjonbrazil.github.io/jc/)
# jc.parsers.stat_s
jc - JSON CLI output utility `stat` command output streaming parser
> This streaming parser outputs JSON Lines
2022-01-19 17:30:14 -08:00
The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the
local time of the system the parser is run on).
2022-01-06 11:00:53 -08:00
2022-01-19 17:30:14 -08:00
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are
only available if the timezone field is UTC.
2022-01-06 11:00:53 -08:00
Usage (cli):
$ stat * | jc --stat-s
Usage (module):
2022-01-18 15:38:03 -08:00
import jc
2022-01-19 17:30:14 -08:00
# result is an iterable object (generator)
result = jc.parse('stat_s', stat_command_output.splitlines())
2022-01-18 15:38:03 -08:00
for item in result:
# do something
or
2022-01-06 11:00:53 -08:00
import jc.parsers.stat_s
2022-01-19 17:30:14 -08:00
# result is an iterable object (generator)
result = jc.parsers.stat_s.parse(stat_command_output.splitlines())
2022-01-06 11:00:53 -08:00
for item in result:
# do something
Schema:
{
"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,
"access_time": string, # - = null
"access_time_epoch": integer, # naive timestamp
"access_time_epoch_utc": integer, # timezone-aware timestamp
"modify_time": string, # - = null
"modify_time_epoch": integer, # naive timestamp
"modify_time_epoch_utc": integer, # timezone-aware timestamp
"change_time": string, # - = null
"change_time_epoch": integer, # naive timestamp
"change_time_epoch_utc": integer, # timezone-aware timestamp
"birth_time": string, # - = null
"birth_time_epoch": integer, # naive timestamp
"birth_time_epoch_utc": integer, # timezone-aware timestamp
"unix_device": integer,
"rdev": integer,
"block_size": integer,
2022-01-08 20:22:53 -08:00
"unix_flags": string,
2022-01-19 17:30:14 -08:00
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
2022-01-06 11:00:53 -08:00
{
2022-01-19 17:30:14 -08:00
"success": boolean, # false if error parsing
2022-01-06 11:03:49 -08:00
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
2022-01-06 11:00:53 -08:00
}
}
Examples:
$ stat | jc --stat-s
2022-01-19 17:30:14 -08:00
{"file":"(stdin)","unix_device":1027739696,"inode":1155,"flags":"cr...}
2022-01-06 11:00:53 -08:00
$ stat | jc --stat-s -r
2022-01-19 17:30:14 -08:00
{"file":"(stdin)","unix_device":"1027739696","inode":"1155","flag...}
2022-01-06 11:00:53 -08:00
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
## parse
```python
parse(data, raw=False, quiet=False, ignore_exceptions=False)
```
Main text parsing generator function. Returns an iterator object.
Parameters:
2022-01-19 17:30:14 -08:00
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
2022-01-21 07:42:03 -08:00
raw: (boolean) unprocessed output if True
2022-01-06 11:00:53 -08:00
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
Yields:
Dictionary. Raw or processed structured data.
Returns:
Iterator object
## Parser Information
Compatibility: linux, darwin, freebsd
Version 0.5 by Kelly Brazil (kellyjonbrazil@gmail.com)