2021-09-10 14:27:50 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
|
|
|
|
|
|
|
# jc.parsers.ls_s
|
|
|
|
jc - JSON CLI output utility `ls` and `vdir` command output streaming parser
|
|
|
|
|
2021-09-27 10:35:08 -07:00
|
|
|
> This streaming parser outputs JSON Lines
|
|
|
|
|
|
|
|
Requires the `-l` option to be used on `ls`. If there are newline characters in the filename, then make sure to use the `-b` option on `ls`.
|
2021-09-10 14:27:50 -07:00
|
|
|
|
2021-09-26 20:22:16 -07:00
|
|
|
The `jc` `-qq` option can be used to ignore parsing errors. (e.g. filenames with newline characters, but `-b` was not used)
|
2021-09-10 14:27:50 -07:00
|
|
|
|
|
|
|
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
|
|
|
|
|
|
|
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
|
|
|
|
|
|
|
Usage (cli):
|
|
|
|
|
|
|
|
$ ls | jc --ls-s
|
|
|
|
|
|
|
|
Usage (module):
|
|
|
|
|
|
|
|
import jc.parsers.ls_s
|
2021-09-21 12:32:34 -07:00
|
|
|
result = jc.parsers.ls_s.parse(ls_command_output.splitlines()) # result is an iterable object
|
2021-09-10 14:27:50 -07:00
|
|
|
for item in result:
|
|
|
|
# do something
|
|
|
|
|
|
|
|
Schema:
|
|
|
|
|
|
|
|
{
|
2021-09-10 15:01:02 -07:00
|
|
|
"filename": string,
|
|
|
|
"flags": string,
|
|
|
|
"links": integer,
|
2021-09-13 21:15:08 -07:00
|
|
|
"parent": string,
|
2021-09-10 15:01:02 -07:00
|
|
|
"owner": string,
|
|
|
|
"group": string,
|
|
|
|
"size": integer,
|
|
|
|
"date": string,
|
|
|
|
"epoch": integer, # naive timestamp if date field exists and can be converted
|
|
|
|
"epoch_utc": integer, # timezone aware timestamp if date field is in UTC and can be converted
|
2021-09-24 09:24:30 -07:00
|
|
|
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
|
2021-09-10 14:27:50 -07:00
|
|
|
{
|
2021-09-10 15:02:15 -07:00
|
|
|
"success": booean, # true if successfully parsed, false if error
|
2021-09-17 10:26:47 -07:00
|
|
|
"error": string, # exists if "success" is false
|
2021-09-10 15:02:15 -07:00
|
|
|
"line": string # exists if "success" is false
|
2021-09-10 14:27:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ ls -l /usr/bin | jc --ls-s
|
2021-09-13 21:15:08 -07:00
|
|
|
{"filename":"2to3-","flags":"-rwxr-xr-x","links":4,"owner":"root","group":"wheel","size":925,"date":"Feb 22 2019"}
|
|
|
|
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/2to3-2.7","flags":"lrwxr-xr-x","links":1,"owner":"root","group":"wheel","size":74,"date":"May 4 2019"}
|
|
|
|
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":1,"owner":"root","group":"wheel","size":55152,"date":"May 3 2019"}
|
2021-09-10 14:27:50 -07:00
|
|
|
...
|
|
|
|
|
|
|
|
$ ls -l /usr/bin | jc --ls-s -r
|
2021-09-13 21:15:08 -07:00
|
|
|
{"filename":"2to3-","flags":"-rwxr-xr-x","links":"4","owner":"root","group":"wheel","size":"925","date":"Feb 22 2019"}
|
|
|
|
{"filename":"2to3-2.7","link_to":"../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/2to3-2.7","flags":"lrwxr-xr-x","links":"1","owner":"root","group":"wheel","size":"74","date":"May 4 2019"}
|
|
|
|
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":"1","owner":"root","group":"wheel","size":"55152","date":"May 3 2019"}
|
2021-09-10 14:27:50 -07:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
## info
|
|
|
|
```python
|
|
|
|
info()
|
|
|
|
```
|
|
|
|
Provides parser metadata (version, author, etc.)
|
|
|
|
|
|
|
|
## parse
|
|
|
|
```python
|
2021-09-23 11:48:39 -07:00
|
|
|
parse(data, raw=False, quiet=False, ignore_exceptions=False)
|
2021-09-10 14:27:50 -07:00
|
|
|
```
|
|
|
|
|
2021-09-21 16:03:00 -07:00
|
|
|
Main text parsing generator function. Returns an iterator object.
|
2021-09-10 14:27:50 -07:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
2021-09-23 11:48:39 -07:00
|
|
|
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
|
|
|
|
raw: (boolean) output preprocessed JSON if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
ignore_exceptions: (boolean) ignore parsing exceptions if True
|
2021-09-10 14:27:50 -07:00
|
|
|
|
2021-09-13 21:15:08 -07:00
|
|
|
Yields:
|
2021-09-10 14:27:50 -07:00
|
|
|
|
2021-09-13 21:15:08 -07:00
|
|
|
Dictionary. Raw or processed structured data.
|
2021-09-10 14:27:50 -07:00
|
|
|
|
2021-09-21 16:03:00 -07:00
|
|
|
Returns:
|
|
|
|
|
|
|
|
Iterator object
|
|
|
|
|
2021-09-10 14:27:50 -07:00
|
|
|
## Parser Information
|
|
|
|
Compatibility: linux, darwin, cygwin, aix, freebsd
|
|
|
|
|
2021-09-13 21:15:08 -07:00
|
|
|
Version 0.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|