mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
cleanup unused code
This commit is contained in:
@ -1,10 +1,6 @@
|
|||||||
"""jc - JSON CLI output utility `ls` and `vdir` command output streaming parser
|
"""jc - JSON CLI output utility `ls` and `vdir` command output streaming parser
|
||||||
|
|
||||||
Options supported:
|
This streaming parser requires the `-l` option to be used on `ls`. If there are newline characters in the filename, then make sure to use the `-b` or `-B` option on `ls`.
|
||||||
- `lbaR1`
|
|
||||||
- `--time-style=full-iso`
|
|
||||||
|
|
||||||
Note: The `-1`, `-l`, or `-b` option of `ls` should be used to correctly parse filenames that include newline characters. Since `ls` does not encode newlines in filenames when outputting to a pipe it will cause `jc` to see multiple files instead of a single file if `-1`, `-l`, or `-b` is not used. Alternatively, `vdir` can be used, which is the same as running `ls -lb`.
|
|
||||||
|
|
||||||
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||||
|
|
||||||
@ -45,20 +41,19 @@ Schema:
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ ls -l /usr/bin | jc --ls-s
|
$ ls -l /usr/bin | jc --ls-s
|
||||||
{"filename":"2to3-","flags":"-rwxr-xr-x","links":4,"owner":"root","group":"wheel","size":925,"date":"Feb 22 2019","_meta":{"success":true}}
|
{"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","_meta":{"success":true}}
|
{"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","_meta":{"success":true}}
|
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":1,"owner":"root","group":"wheel","size":55152,"date":"May 3 2019"}
|
||||||
...
|
...
|
||||||
|
|
||||||
$ ls -l /usr/bin | jc --ls-s -r
|
$ ls -l /usr/bin | jc --ls-s -r
|
||||||
{"filename":"2to3-","flags":"-rwxr-xr-x","links":"4","owner":"root","group":"wheel","size":"925","date":"Feb 22 2019","_meta":{"success":true}}
|
{"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","_meta":{"success":true}}
|
{"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","_meta":{"success":true}}
|
{"filename":"AssetCacheLocatorUtil","flags":"-rwxr-xr-x","links":"1","owner":"root","group":"wheel","size":"55152","date":"May 3 2019"}
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import jc.utils
|
import jc.utils
|
||||||
from jc.exceptions import ParseError
|
|
||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
@ -121,23 +116,16 @@ def parse(data, raw=False, quiet=False):
|
|||||||
jc.utils.compatibility(__name__, info.compatible)
|
jc.utils.compatibility(__name__, info.compatible)
|
||||||
|
|
||||||
parent = ''
|
parent = ''
|
||||||
new_section = False
|
|
||||||
# last_object = {}
|
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# skip line if it starts with 'total 1234'
|
# skip line if it starts with 'total 1234'
|
||||||
if re.match(r'total [0-9]+', line):
|
if re.match(r'total [0-9]+', line):
|
||||||
new_section = False
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# fix for OSX - doesn't print 'total xx' line if empty directory
|
# skip blank lines
|
||||||
if new_section and line.strip() == '':
|
if line.strip() == '':
|
||||||
new_section = False
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not new_section and line.strip() == '':
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Look for parent line if glob or -R is used
|
# Look for parent line if glob or -R is used
|
||||||
@ -149,28 +137,6 @@ def parse(data, raw=False, quiet=False):
|
|||||||
parsed_line = line.strip().split(maxsplit=8)
|
parsed_line = line.strip().split(maxsplit=8)
|
||||||
output_line = {}
|
output_line = {}
|
||||||
|
|
||||||
# no support for filenames with newline chars in streaming parser
|
|
||||||
# if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', line) \
|
|
||||||
# and line.endswith(':'):
|
|
||||||
# parent = line[:-1]
|
|
||||||
# new_section = True
|
|
||||||
|
|
||||||
# no support for filenames with newline chars in streaming parser
|
|
||||||
# fixup to remove trailing \n in previous entry
|
|
||||||
# raw_output[-1]['filename'] = raw_output[-1]['filename'][:-1]
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# no support for filenames with newline chars in streaming parser
|
|
||||||
# fixup for filenames with newlines
|
|
||||||
# if not new_section \
|
|
||||||
# and not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry):
|
|
||||||
# raw_output[-1]['filename'] = raw_output[-1]['filename'] + '\n' + entry
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# Only support -l option
|
|
||||||
# if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', line):
|
|
||||||
# raise ParseError(f'Unparsable line: {line.rstrip()[0:60]}')
|
|
||||||
|
|
||||||
# split filenames and links
|
# split filenames and links
|
||||||
if len(parsed_line) == 9:
|
if len(parsed_line) == 9:
|
||||||
filename_field = parsed_line[8].split(' -> ')
|
filename_field = parsed_line[8].split(' -> ')
|
||||||
|
Reference in New Issue
Block a user