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

121 lines
3.7 KiB
Markdown
Raw Normal View History

2022-01-06 11:00:53 -08:00
[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.stat_s"></a>
# jc.parsers.stat\_s
2022-01-06 11:00:53 -08:00
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):
2022-01-25 18:03:34 -08:00
$ stat * | jc --stat-s
2022-01-06 11:00:53 -08:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
# result is an iterable object (generator)
result = jc.parse('stat_s', stat_command_output.splitlines())
for item in result:
# do something
2022-01-18 15:38:03 -08:00
2022-01-25 18:03:34 -08:00
or
2022-01-18 15:38:03 -08:00
2022-01-25 18:03:34 -08:00
import jc.parsers.stat_s
# result is an iterable object (generator)
result = jc.parsers.stat_s.parse(stat_command_output.splitlines())
for item in result:
# do something
2022-01-06 11:00:53 -08:00
Schema:
2022-01-25 18:03:34 -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,
"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,
"unix_flags": string,
# Below object only exists if using -qq or ignore_exceptions=True
"_jc_meta":
{
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
}
Examples:
$ stat | jc --stat-s
{"file":"(stdin)","unix_device":1027739696,"inode":1155,"flags":"cr...}
$ stat | jc --stat-s -r
{"file":"(stdin)","unix_device":"1027739696","inode":"1155","flag...}
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.stat_s.parse"></a>
2022-01-25 19:18:54 -08:00
### parse
2022-01-25 17:07:47 -08:00
2022-01-06 11:00:53 -08:00
```python
2022-02-03 15:47:46 -08:00
@add_jc_meta
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
2022-01-06 11:00:53 -08:00
```
Main text parsing generator function. Returns an iterator object.
2022-01-25 18:03:34 -08:00
Parameters:
2022-01-19 17:30:14 -08:00
2022-01-25 18:03:34 -08:00
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
2022-01-06 11:00:53 -08:00
2022-01-25 18:03:34 -08:00
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
2022-02-04 12:14:16 -08:00
ignore_exceptions: (boolean) ignore parsing exceptions if True
2022-01-06 11:00:53 -08:00
2022-01-25 18:03:34 -08:00
Yields:
2022-01-06 11:00:53 -08:00
2022-01-25 18:03:34 -08:00
Dictionary. Raw or processed structured data.
2022-01-06 11:00:53 -08:00
2022-01-25 18:03:34 -08:00
Returns:
2022-02-14 10:31:41 -08:00
Iterator object (generator)
2022-01-06 11:00:53 -08:00
2022-01-25 19:18:54 -08:00
### Parser Information
2022-01-06 11:00:53 -08:00
Compatibility: linux, darwin, freebsd
2022-02-03 15:47:46 -08:00
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)