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>
|
|
|
|
|
2024-03-14 22:46:52 -07:00
|
|
|
# jc.parsers.stat_s
|
2022-01-06 11:00:53 -08:00
|
|
|
|
2022-03-04 13:27:39 -08:00
|
|
|
jc - JSON Convert `stat` command output streaming parser
|
2022-01-06 11:00:53 -08:00
|
|
|
|
2022-04-28 13:38:24 -07:00
|
|
|
> This streaming parser outputs JSON Lines (cli) or returns an Iterable of
|
2022-05-26 15:07:54 -07:00
|
|
|
> Dictionaries (module)
|
2022-01-06 11:00:53 -08:00
|
|
|
|
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
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2022-03-10 13:32:26 -08:00
|
|
|
result = jc.parse('stat_s', stat_command_output.splitlines())
|
2022-01-25 18:03:34 -08:00
|
|
|
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,
|
|
|
|
|
2022-03-10 10:10:57 -08:00
|
|
|
# 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
|
|
|
|
}
|
2022-01-25 18:03:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2022-01-06 11:00:53 -08:00
|
|
|
```python
|
2024-03-14 22:46:52 -07:00
|
|
|
def parse(
|
|
|
|
data: Iterable[str],
|
|
|
|
raw: bool = False,
|
|
|
|
quiet: bool = False,
|
|
|
|
ignore_exceptions: bool = False
|
|
|
|
) -> Iterator[Union[Dict[str, Any], Tuple[BaseException, str]]]
|
2022-01-06 11:00:53 -08:00
|
|
|
```
|
|
|
|
|
2022-04-28 13:30:11 -07:00
|
|
|
Main text parsing generator function. Returns an iterable object.
|
2022-01-06 11:00:53 -08:00
|
|
|
|
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
|
|
|
Returns:
|
|
|
|
|
2022-04-28 13:30:11 -07:00
|
|
|
Iterable of Dictionaries
|
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
|
|
|
|
|
2023-12-21 14:55:21 -08:00
|
|
|
Source: [`jc/parsers/stat_s.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/stat_s.py)
|
|
|
|
|
2022-11-22 13:11:41 -08:00
|
|
|
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|