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
|
||||
|
||||
2019xxxx v0.5.0
|
||||
20191018 v0.5.4
|
||||
- Fix netstat -p parsing for Ubuntu
|
||||
- Add ps parser
|
||||
- Add route parser
|
||||
+ Change some ifconfig fields to integers
|
||||
+ 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
|
||||
- ls parser fixes
|
||||
|
||||
20191017 v0.2.0
|
||||
- ifconfig, ls, and netstat support
|
||||
|
@ -89,43 +89,43 @@ import re
|
||||
def parse(data):
|
||||
output = []
|
||||
|
||||
cleandata = data.splitlines()
|
||||
linedata = data.splitlines()
|
||||
|
||||
# Delete first line if it starts with 'total'
|
||||
if cleandata[0].find('total') == 0:
|
||||
cleandata.pop(0)
|
||||
if linedata[0].find('total') == 0:
|
||||
linedata.pop(0)
|
||||
|
||||
# Delete last line if it is blank
|
||||
if cleandata[-1] == '':
|
||||
cleandata.pop(-1)
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, linedata))
|
||||
|
||||
# Check if -l was used to parse extra data
|
||||
if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', cleandata[0]):
|
||||
for entry in cleandata:
|
||||
output_line = {}
|
||||
if cleandata:
|
||||
# Check if -l was used to parse extra data
|
||||
if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', cleandata[0]):
|
||||
for entry in cleandata:
|
||||
output_line = {}
|
||||
|
||||
parsed_line = entry.split()
|
||||
parsed_line = entry.split(maxsplit=8)
|
||||
|
||||
# split filenames and links
|
||||
filename_field = ' '.join(parsed_line[8:]).split(' -> ')
|
||||
# split filenames and links
|
||||
filename_field = parsed_line[8].split(' -> ')
|
||||
|
||||
# create list of dictionaries
|
||||
output_line['filename'] = filename_field[0]
|
||||
# create list of dictionaries
|
||||
output_line['filename'] = filename_field[0]
|
||||
|
||||
if len(filename_field) > 1:
|
||||
output_line['link_to'] = filename_field[1]
|
||||
if len(filename_field) > 1:
|
||||
output_line['link_to'] = filename_field[1]
|
||||
|
||||
output_line['flags'] = parsed_line[0]
|
||||
output_line['links'] = int(parsed_line[1])
|
||||
output_line['owner'] = parsed_line[2]
|
||||
output_line['group'] = parsed_line[3]
|
||||
output_line['bytes'] = int(parsed_line[4])
|
||||
output_line['date'] = ' '.join(parsed_line[5:8])
|
||||
output.append(output_line)
|
||||
else:
|
||||
for entry in cleandata:
|
||||
output_line = {}
|
||||
output_line['filename'] = entry
|
||||
output.append(output_line)
|
||||
output_line['flags'] = parsed_line[0]
|
||||
output_line['links'] = int(parsed_line[1])
|
||||
output_line['owner'] = parsed_line[2]
|
||||
output_line['group'] = parsed_line[3]
|
||||
output_line['bytes'] = int(parsed_line[4])
|
||||
output_line['date'] = ' '.join(parsed_line[5:8])
|
||||
output.append(output_line)
|
||||
else:
|
||||
for entry in cleandata:
|
||||
output_line = {}
|
||||
output_line['filename'] = entry
|
||||
output.append(output_line)
|
||||
|
||||
return output
|
||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name='jc',
|
||||
version='0.5.3',
|
||||
version='0.5.4',
|
||||
author='Kelly Brazil',
|
||||
author_email='kellyjonbrazil@gmail.com',
|
||||
description='This tool serializes the output of popular command line tools to structured JSON output.',
|
||||
|
Reference in New Issue
Block a user