mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
ls fixes
This commit is contained in:
@ -1,13 +1,10 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
2019xxxx v0.5.0
|
20191018 v0.5.4
|
||||||
- Fix netstat -p parsing for Ubuntu
|
- Fix netstat -p parsing for Ubuntu
|
||||||
- Add ps parser
|
- Add ps parser
|
||||||
- Add route parser
|
- Add route parser
|
||||||
+ Change some ifconfig fields to integers
|
- ls parser fixes
|
||||||
+ Use maxsplit option in split in ls.py line 109... otherwise filenames with multiple spaces
|
|
||||||
between words can be incorrectly represented with the .join operation
|
|
||||||
+ Use list(filter(None, cleandata)) or list comprehension to clean any blank entries in ls.py line 98
|
|
||||||
|
|
||||||
20191017 v0.2.0
|
20191017 v0.2.0
|
||||||
- ifconfig, ls, and netstat support
|
- ifconfig, ls, and netstat support
|
||||||
|
@ -89,43 +89,43 @@ import re
|
|||||||
def parse(data):
|
def parse(data):
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
cleandata = data.splitlines()
|
linedata = data.splitlines()
|
||||||
|
|
||||||
# Delete first line if it starts with 'total'
|
# Delete first line if it starts with 'total'
|
||||||
if cleandata[0].find('total') == 0:
|
if linedata[0].find('total') == 0:
|
||||||
cleandata.pop(0)
|
linedata.pop(0)
|
||||||
|
|
||||||
# Delete last line if it is blank
|
# Clear any blank lines
|
||||||
if cleandata[-1] == '':
|
cleandata = list(filter(None, linedata))
|
||||||
cleandata.pop(-1)
|
|
||||||
|
|
||||||
# Check if -l was used to parse extra data
|
if cleandata:
|
||||||
if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', cleandata[0]):
|
# Check if -l was used to parse extra data
|
||||||
for entry in cleandata:
|
if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', cleandata[0]):
|
||||||
output_line = {}
|
for entry in cleandata:
|
||||||
|
output_line = {}
|
||||||
|
|
||||||
parsed_line = entry.split()
|
parsed_line = entry.split(maxsplit=8)
|
||||||
|
|
||||||
# split filenames and links
|
# split filenames and links
|
||||||
filename_field = ' '.join(parsed_line[8:]).split(' -> ')
|
filename_field = parsed_line[8].split(' -> ')
|
||||||
|
|
||||||
# create list of dictionaries
|
# create list of dictionaries
|
||||||
output_line['filename'] = filename_field[0]
|
output_line['filename'] = filename_field[0]
|
||||||
|
|
||||||
if len(filename_field) > 1:
|
if len(filename_field) > 1:
|
||||||
output_line['link_to'] = filename_field[1]
|
output_line['link_to'] = filename_field[1]
|
||||||
|
|
||||||
output_line['flags'] = parsed_line[0]
|
output_line['flags'] = parsed_line[0]
|
||||||
output_line['links'] = int(parsed_line[1])
|
output_line['links'] = int(parsed_line[1])
|
||||||
output_line['owner'] = parsed_line[2]
|
output_line['owner'] = parsed_line[2]
|
||||||
output_line['group'] = parsed_line[3]
|
output_line['group'] = parsed_line[3]
|
||||||
output_line['bytes'] = int(parsed_line[4])
|
output_line['bytes'] = int(parsed_line[4])
|
||||||
output_line['date'] = ' '.join(parsed_line[5:8])
|
output_line['date'] = ' '.join(parsed_line[5:8])
|
||||||
output.append(output_line)
|
output.append(output_line)
|
||||||
else:
|
else:
|
||||||
for entry in cleandata:
|
for entry in cleandata:
|
||||||
output_line = {}
|
output_line = {}
|
||||||
output_line['filename'] = entry
|
output_line['filename'] = entry
|
||||||
output.append(output_line)
|
output.append(output_line)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='jc',
|
name='jc',
|
||||||
version='0.5.3',
|
version='0.5.4',
|
||||||
author='Kelly Brazil',
|
author='Kelly Brazil',
|
||||||
author_email='kellyjonbrazil@gmail.com',
|
author_email='kellyjonbrazil@gmail.com',
|
||||||
description='This tool serializes the output of popular command line tools to structured JSON output.',
|
description='This tool serializes the output of popular command line tools to structured JSON output.',
|
||||||
|
Reference in New Issue
Block a user