mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
16
CHANGELOG
16
CHANGELOG
@ -1,5 +1,21 @@
|
||||
jc changelog
|
||||
|
||||
20210720 v1.16.0
|
||||
- Note to Package Maintainers:
|
||||
TL;DR: `/man/jc.1.gz` and `/jc/man/jc.1.gz` are deprecated and only `/man/jc.1` should be used.
|
||||
|
||||
The Man page in the PyPi source packages will be moving from `/jc/man/jc.1.gz` to `/man/jc.1`
|
||||
in version 1.17.0. For now the Man pages will be available in both locations, but be aware that
|
||||
the Man page at `/jc/man/jc.1.gz` is now considered deprecated.
|
||||
|
||||
Also, starting in v1.17.0, the Man page will no longer be compressed in the source package,
|
||||
therefore `/man/jc.1.gz` should also be considered deprecated and will no longer be available
|
||||
after v1.17.0. Please use `/man/jc.1` and compress downstream if you would like.
|
||||
- Include CHANGELOG in source distribution
|
||||
- Fix Man page location in source packages
|
||||
- Add sfdisk command parser tested on linux
|
||||
- Update unit test files to change the timezone when needed (POSIX only)
|
||||
|
||||
20210628 v1.15.6
|
||||
- Fix issue to only load local plugin parsers that have filenames that end in .py
|
||||
|
||||
|
69
EXAMPLES.md
69
EXAMPLES.md
@ -2556,6 +2556,75 @@ rpm_qia | jc --rpm_qi -p # or: jc -p rpm -qia
|
||||
}
|
||||
]
|
||||
```
|
||||
### sfdisk
|
||||
```bash
|
||||
sfdisk -l | jc --sfdisk -p # or jc -p sfdisk
|
||||
```
|
||||
```json
|
||||
[
|
||||
{
|
||||
"disk": "/dev/sda",
|
||||
"cylinders": 2610,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63,
|
||||
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
|
||||
"partitions": [
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"boot": true,
|
||||
"start": 0,
|
||||
"end": 130,
|
||||
"cyls": 131,
|
||||
"blocks": 1048576,
|
||||
"id": "83",
|
||||
"system": "Linux"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"boot": false,
|
||||
"start": 130,
|
||||
"end": 2610,
|
||||
"cyls": 2481,
|
||||
"blocks": 19921920,
|
||||
"id": "8e",
|
||||
"system": "Linux LVM"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda3",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda4",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-root",
|
||||
"cylinders": 2218,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-swap",
|
||||
"cylinders": 261,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
}
|
||||
]
|
||||
```
|
||||
### /etc/shadow file
|
||||
```bash
|
||||
cat /etc/shadow | jc --shadow -p
|
||||
|
@ -1 +1,3 @@
|
||||
include jc/man/jc.1.gz
|
||||
include man/jc.1
|
||||
include CHANGELOG
|
||||
|
@ -169,6 +169,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
|
||||
- `--ps` enables the `ps` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ps))
|
||||
- `--route` enables the `route` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/route))
|
||||
- `--rpm-qi` enables the `rpm -qi` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi))
|
||||
- `--sfdisk` enables the `sfdisk` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/sfdisk))
|
||||
- `--shadow` enables the `/etc/shadow` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/shadow))
|
||||
- `--ss` enables the `ss` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ss))
|
||||
- `--stat` enables the `stat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/stat))
|
||||
|
@ -25,7 +25,7 @@ Schema:
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"flags_pretty": [
|
||||
string,
|
||||
string
|
||||
]
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
@ -76,7 +76,6 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
$ route -ee | jc --route -p -r
|
||||
[
|
||||
{
|
||||
@ -108,7 +107,6 @@ Examples:
|
||||
]
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
|
213
docs/parsers/sfdisk.md
Normal file
213
docs/parsers/sfdisk.md
Normal file
@ -0,0 +1,213 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.sfdisk
|
||||
jc - JSON CLI output utility `sfdisk` command output parser
|
||||
|
||||
Supports the following `sfdisk` options:
|
||||
- `-l`
|
||||
- `-d`
|
||||
- `-uM`
|
||||
- `-uC`
|
||||
- `-uS`
|
||||
- `-uB`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
# sfdisk -l | jc --sfdisk
|
||||
|
||||
or
|
||||
|
||||
# jc sfdisk -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.sfdisk
|
||||
result = jc.parsers.sfdisk.parse(sfdisk_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"disk": string,
|
||||
"cylinders": integer,
|
||||
"heads": integer,
|
||||
"sectors_per_track": integer,
|
||||
"units": string,
|
||||
"partitions": [
|
||||
{
|
||||
"device": string,
|
||||
"boot": boolean,
|
||||
"start": integer,
|
||||
"end": integer,
|
||||
"size": integer,
|
||||
"cyls": integer,
|
||||
"mib": integer,
|
||||
"blocks": integer,
|
||||
"sectors": integer,
|
||||
"id": string,
|
||||
"system": string
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
# sfdisk -l | jc --sfdisk -p
|
||||
[
|
||||
{
|
||||
"disk": "/dev/sda",
|
||||
"cylinders": 2610,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63,
|
||||
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
|
||||
"partitions": [
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"boot": true,
|
||||
"start": 0,
|
||||
"end": 130,
|
||||
"cyls": 131,
|
||||
"blocks": 1048576,
|
||||
"id": "83",
|
||||
"system": "Linux"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"boot": false,
|
||||
"start": 130,
|
||||
"end": 2610,
|
||||
"cyls": 2481,
|
||||
"blocks": 19921920,
|
||||
"id": "8e",
|
||||
"system": "Linux LVM"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda3",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda4",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-root",
|
||||
"cylinders": 2218,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-swap",
|
||||
"cylinders": 261,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
}
|
||||
]
|
||||
|
||||
# sfdisk | jc --sfdisk -p -r
|
||||
[
|
||||
{
|
||||
"disk": "/dev/sda",
|
||||
"cylinders": "2610",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63",
|
||||
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
|
||||
"partitions": [
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"boot": "*",
|
||||
"start": "0+",
|
||||
"end": "130-",
|
||||
"cyls": "131-",
|
||||
"blocks": "1048576",
|
||||
"id": "83",
|
||||
"system": "Linux"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"boot": null,
|
||||
"start": "130+",
|
||||
"end": "2610-",
|
||||
"cyls": "2481-",
|
||||
"blocks": "19921920",
|
||||
"id": "8e",
|
||||
"system": "Linux LVM"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda3",
|
||||
"boot": null,
|
||||
"start": "0",
|
||||
"end": "-",
|
||||
"cyls": "0",
|
||||
"blocks": "0",
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda4",
|
||||
"boot": null,
|
||||
"start": "0",
|
||||
"end": "-",
|
||||
"cyls": "0",
|
||||
"blocks": "0",
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-root",
|
||||
"cylinders": "2218",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63"
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-swap",
|
||||
"cylinders": "261",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
```
|
||||
|
||||
Main text parsing function
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (string) text data to parse
|
||||
raw: (boolean) output preprocessed JSON if True
|
||||
quiet: (boolean) suppress warning messages if True
|
||||
|
||||
Returns:
|
||||
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
@ -86,4 +86,4 @@ Module Example:
|
||||
"""
|
||||
|
||||
name = 'jc'
|
||||
__version__ = '1.15.6'
|
||||
__version__ = '1.16.0'
|
||||
|
@ -94,6 +94,7 @@ parsers = [
|
||||
'ps',
|
||||
'route',
|
||||
'rpm-qi',
|
||||
'sfdisk',
|
||||
'shadow',
|
||||
'ss',
|
||||
'stat',
|
||||
|
BIN
jc/man/jc.1.gz
BIN
jc/man/jc.1.gz
Binary file not shown.
@ -22,7 +22,7 @@ Schema:
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"flags_pretty": [
|
||||
string,
|
||||
string
|
||||
]
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
@ -73,7 +73,6 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
$ route -ee | jc --route -p -r
|
||||
[
|
||||
{
|
||||
@ -103,7 +102,6 @@ Examples:
|
||||
"irtt": "0"
|
||||
}
|
||||
]
|
||||
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
325
jc/parsers/sfdisk.py
Normal file
325
jc/parsers/sfdisk.py
Normal file
@ -0,0 +1,325 @@
|
||||
"""jc - JSON CLI output utility `sfdisk` command output parser
|
||||
|
||||
Supports the following `sfdisk` options:
|
||||
- `-l`
|
||||
- `-d`
|
||||
- `-uM`
|
||||
- `-uC`
|
||||
- `-uS`
|
||||
- `-uB`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
# sfdisk -l | jc --sfdisk
|
||||
|
||||
or
|
||||
|
||||
# jc sfdisk -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.sfdisk
|
||||
result = jc.parsers.sfdisk.parse(sfdisk_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"disk": string,
|
||||
"cylinders": integer,
|
||||
"heads": integer,
|
||||
"sectors_per_track": integer,
|
||||
"units": string,
|
||||
"partitions": [
|
||||
{
|
||||
"device": string,
|
||||
"boot": boolean,
|
||||
"start": integer,
|
||||
"end": integer,
|
||||
"size": integer,
|
||||
"cyls": integer,
|
||||
"mib": integer,
|
||||
"blocks": integer,
|
||||
"sectors": integer,
|
||||
"id": string,
|
||||
"system": string
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
# sfdisk -l | jc --sfdisk -p
|
||||
[
|
||||
{
|
||||
"disk": "/dev/sda",
|
||||
"cylinders": 2610,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63,
|
||||
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
|
||||
"partitions": [
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"boot": true,
|
||||
"start": 0,
|
||||
"end": 130,
|
||||
"cyls": 131,
|
||||
"blocks": 1048576,
|
||||
"id": "83",
|
||||
"system": "Linux"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"boot": false,
|
||||
"start": 130,
|
||||
"end": 2610,
|
||||
"cyls": 2481,
|
||||
"blocks": 19921920,
|
||||
"id": "8e",
|
||||
"system": "Linux LVM"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda3",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda4",
|
||||
"boot": false,
|
||||
"start": 0,
|
||||
"end": null,
|
||||
"cyls": 0,
|
||||
"blocks": 0,
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-root",
|
||||
"cylinders": 2218,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-swap",
|
||||
"cylinders": 261,
|
||||
"heads": 255,
|
||||
"sectors_per_track": 63
|
||||
}
|
||||
]
|
||||
|
||||
# sfdisk | jc --sfdisk -p -r
|
||||
[
|
||||
{
|
||||
"disk": "/dev/sda",
|
||||
"cylinders": "2610",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63",
|
||||
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0",
|
||||
"partitions": [
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"boot": "*",
|
||||
"start": "0+",
|
||||
"end": "130-",
|
||||
"cyls": "131-",
|
||||
"blocks": "1048576",
|
||||
"id": "83",
|
||||
"system": "Linux"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"boot": null,
|
||||
"start": "130+",
|
||||
"end": "2610-",
|
||||
"cyls": "2481-",
|
||||
"blocks": "19921920",
|
||||
"id": "8e",
|
||||
"system": "Linux LVM"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda3",
|
||||
"boot": null,
|
||||
"start": "0",
|
||||
"end": "-",
|
||||
"cyls": "0",
|
||||
"blocks": "0",
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda4",
|
||||
"boot": null,
|
||||
"start": "0",
|
||||
"end": "-",
|
||||
"cyls": "0",
|
||||
"blocks": "0",
|
||||
"id": "0",
|
||||
"system": "Empty"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-root",
|
||||
"cylinders": "2218",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63"
|
||||
},
|
||||
{
|
||||
"disk": "/dev/mapper/centos-swap",
|
||||
"cylinders": "261",
|
||||
"heads": "255",
|
||||
"sectors_per_track": "63"
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.0'
|
||||
description = '`sfdisk` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
compatible = ['linux']
|
||||
magic_commands = ['sfdisk']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def _process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (List of Dictionaries) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of Dictionaries. Structured to conform to the schema.
|
||||
"""
|
||||
int_list = ['cylinders', 'heads', 'sectors_per_track', 'start', 'end', 'size', 'cyls', 'mib',
|
||||
'blocks', 'sectors']
|
||||
bool_list = ['boot']
|
||||
|
||||
for entry in proc_data:
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key].replace('-', ''))
|
||||
|
||||
if 'partitions' in entry:
|
||||
for p in entry['partitions']:
|
||||
for key in p:
|
||||
if key in int_list:
|
||||
p[key] = jc.utils.convert_to_int(p[key].replace('-', ''))
|
||||
if key in bool_list:
|
||||
p[key] = jc.utils.convert_to_bool(p[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def parse(data, raw=False, quiet=False):
|
||||
"""
|
||||
Main text parsing function
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (string) text data to parse
|
||||
raw: (boolean) output preprocessed JSON if True
|
||||
quiet: (boolean) suppress warning messages if True
|
||||
|
||||
Returns:
|
||||
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
item = {}
|
||||
partitions = []
|
||||
option = ''
|
||||
section = ''
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in data.splitlines():
|
||||
if line.startswith('# partition table of'):
|
||||
if item:
|
||||
raw_output.append(item)
|
||||
|
||||
item = {}
|
||||
partitions = []
|
||||
option = 'd'
|
||||
item['disk'] = line.split()[4]
|
||||
continue
|
||||
|
||||
if option == 'd':
|
||||
if line.startswith('unit: '):
|
||||
item['units'] = line.split()[1]
|
||||
section = 'partitions'
|
||||
continue
|
||||
|
||||
if section == 'partitions' and line:
|
||||
part = {}
|
||||
part['device'] = line.split()[0]
|
||||
line = line.replace(',', ' ').replace('=', ' ')
|
||||
part['start'] = line.split()[3]
|
||||
part['size'] = line.split()[5]
|
||||
part['id'] = line.split()[7]
|
||||
part['boot'] = '*' if 'bootable' in line else None
|
||||
partitions.append(part)
|
||||
item['partitions'] = partitions
|
||||
continue
|
||||
|
||||
else:
|
||||
if line.startswith('Disk '):
|
||||
if item:
|
||||
raw_output.append(item)
|
||||
|
||||
item = {}
|
||||
partitions = []
|
||||
line = line.replace(':', '').replace(',', '')
|
||||
item['disk'] = line.split()[1]
|
||||
item['cylinders'] = line.split()[2]
|
||||
item['heads'] = line.split()[4]
|
||||
item['sectors_per_track'] = line.split()[6]
|
||||
continue
|
||||
|
||||
if line.startswith('Units: '):
|
||||
item['units'] = line.split(':')[1].strip()
|
||||
continue
|
||||
|
||||
if 'Device' in line and 'Boot' in line and 'Start' in line and 'End' in line:
|
||||
section = 'partitions'
|
||||
partitions.append(line.lower().replace('#', ' '))
|
||||
continue
|
||||
|
||||
if section == 'partitions' and line:
|
||||
partitions.append(line)
|
||||
continue
|
||||
|
||||
if section == 'partitions' and line == '':
|
||||
item['partitions'] = jc.parsers.universal.sparse_table_parse(partitions)
|
||||
section = ''
|
||||
partitions = []
|
||||
continue
|
||||
|
||||
if item:
|
||||
raw_output.append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return _process(raw_output)
|
@ -154,7 +154,7 @@ def convert_to_bool(value):
|
||||
# if float converts, then bool the result
|
||||
# if float does not convert then look for truthy string and bool True
|
||||
# else False
|
||||
truthy = ['y', 'yes', 'true']
|
||||
truthy = ['y', 'yes', 'true', '*']
|
||||
|
||||
if isinstance(value, (int, float)):
|
||||
return bool(value)
|
||||
|
515
man/jc.1
Normal file
515
man/jc.1
Normal file
@ -0,0 +1,515 @@
|
||||
.TH jc 1 2021-07-20 1.16.0 "JSON CLI output utility"
|
||||
.SH NAME
|
||||
jc \- JSONifies the output of many CLI tools and file-types
|
||||
.SH SYNOPSIS
|
||||
COMMAND | jc PARSER [OPTIONS]
|
||||
|
||||
or "Magic" syntax:
|
||||
|
||||
jc [OPTIONS] COMMAND
|
||||
|
||||
.SH DESCRIPTION
|
||||
jc JSONifies the output of many CLI tools and file-types for easier parsing in scripts. jc accepts piped input from \fBSTDIN\fP and outputs a JSON representation of the previous command's output to \fBSTDOUT\fP. Alternatively, the "Magic" syntax can be used by prepending jc to the command to be converted. Options can be passed to jc immediately before the command is given. (Note: "Magic" syntax does not support shell builtins or command aliases)
|
||||
|
||||
.SH OPTIONS
|
||||
.B
|
||||
Parsers:
|
||||
.RS
|
||||
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--acpi\fP
|
||||
`acpi` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--airport\fP
|
||||
`airport -I` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--airport-s\fP
|
||||
`airport -s` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--arp\fP
|
||||
`arp` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--blkid\fP
|
||||
`blkid` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--cksum\fP
|
||||
`cksum` and `sum` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--crontab\fP
|
||||
`crontab` command and file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--crontab-u\fP
|
||||
`crontab` file parser with user support
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--csv\fP
|
||||
CSV file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--date\fP
|
||||
`date` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--df\fP
|
||||
`df` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--dig\fP
|
||||
`dig` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--dir\fP
|
||||
`dir` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--dmidecode\fP
|
||||
`dmidecode` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--dpkg-l\fP
|
||||
`dpkg -l` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--du\fP
|
||||
`du` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--env\fP
|
||||
`env` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--file\fP
|
||||
`file` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--finger\fP
|
||||
`finger` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--free\fP
|
||||
`free` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--fstab\fP
|
||||
`/etc/fstab` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--group\fP
|
||||
`/etc/group` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--gshadow\fP
|
||||
`/etc/gshadow` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--hash\fP
|
||||
`hash` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--hashsum\fP
|
||||
hashsum command parser (`md5sum`, `shasum`, etc.)
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--hciconfig\fP
|
||||
`hciconfig` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--history\fP
|
||||
`history` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--hosts\fP
|
||||
`/etc/hosts` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--id\fP
|
||||
`id` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ifconfig\fP
|
||||
`ifconfig` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ini\fP
|
||||
INI file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--iptables\fP
|
||||
`iptables` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--iw-scan\fP
|
||||
`iw dev [device] scan` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--jobs\fP
|
||||
`jobs` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--kv\fP
|
||||
Key/Value file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--last\fP
|
||||
`last` and `lastb` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ls\fP
|
||||
`ls` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--lsblk\fP
|
||||
`lsblk` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--lsmod\fP
|
||||
`lsmod` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--lsof\fP
|
||||
`lsof` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--mount\fP
|
||||
`mount` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--netstat\fP
|
||||
`netstat` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ntpq\fP
|
||||
`ntpq -p` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--passwd\fP
|
||||
`/etc/passwd` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ping\fP
|
||||
`ping` and `ping6` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--pip-list\fP
|
||||
`pip list` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--pip-show\fP
|
||||
`pip show` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ps\fP
|
||||
`ps` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--route\fP
|
||||
`route` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--rpm-qi\fP
|
||||
`rpm -qi` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--sfdisk\fP
|
||||
`sfdisk` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--shadow\fP
|
||||
`/etc/shadow` file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ss\fP
|
||||
`ss` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--stat\fP
|
||||
`stat` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--sysctl\fP
|
||||
`sysctl` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--systemctl\fP
|
||||
`systemctl` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--systemctl-lj\fP
|
||||
`systemctl list-jobs` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--systemctl-ls\fP
|
||||
`systemctl list-sockets` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--systemctl-luf\fP
|
||||
`systemctl list-unit-files` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--systeminfo\fP
|
||||
`systeminfo` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--time\fP
|
||||
`/usr/bin/time` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--timedatectl\fP
|
||||
`timedatectl status` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--tracepath\fP
|
||||
`tracepath` and `tracepath6` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--traceroute\fP
|
||||
`traceroute` and `traceroute6` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ufw\fP
|
||||
`ufw status` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ufw-appinfo\fP
|
||||
`ufw app info [application]` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--uname\fP
|
||||
`uname -a` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--upower\fP
|
||||
`upower` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--uptime\fP
|
||||
`uptime` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--w\fP
|
||||
`w` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--wc\fP
|
||||
`wc` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--who\fP
|
||||
`who` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--xml\fP
|
||||
XML file parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--yaml\fP
|
||||
YAML file parser
|
||||
|
||||
|
||||
.RE
|
||||
.PP
|
||||
.B
|
||||
Options:
|
||||
.RS
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB-a\fP
|
||||
about jc (JSON output)
|
||||
.TP
|
||||
.B
|
||||
\fB-d\fP
|
||||
debug - show traceback (\fB-dd\fP for verbose traceback)
|
||||
.TP
|
||||
.B
|
||||
\fB-h\fP
|
||||
help (\fB-h --parser_name\fP for parser documentation)
|
||||
.TP
|
||||
.B
|
||||
\fB-m\fP
|
||||
monochrome output
|
||||
.TP
|
||||
.B
|
||||
\fB-p\fP
|
||||
pretty print output
|
||||
.TP
|
||||
.B
|
||||
\fB-q\fP
|
||||
quiet - suppress warnings
|
||||
.TP
|
||||
.B
|
||||
\fB-r\fP
|
||||
raw JSON output
|
||||
.TP
|
||||
.B
|
||||
\fB-v\fP
|
||||
version information
|
||||
|
||||
.SH EXIT CODES
|
||||
Any fatal errors within jc will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP. When using the "Magic" syntax (e.g. \fBjc ifconfig eth0\fP), jc will store the exit code of the program being parsed and add it to the jc exit code. This way it is easier to determine if an error was from the parsed program or jc.
|
||||
|
||||
Consider the following examples using `ifconfig`:
|
||||
|
||||
.RS
|
||||
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
|
||||
|
||||
ifconfig exit code = \fB1\fP, jc exit code = \fB0\fP, combined exit code = \fB1\fP (error in ifconfig)
|
||||
|
||||
ifconfig exit code = \fB0\fP, jc exit code = \fB100\fP, combined exit code = \fB100\fP (error in jc)
|
||||
|
||||
ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB101\fP (error in both ifconfig and jc)
|
||||
.RE
|
||||
|
||||
.SH ENVIRONMENT
|
||||
You can specify custom colors via the \fBJC_COLORS\fP environment variable. The \fBJC_COLORS\fP environment variable takes four comma separated string values in the following format:
|
||||
|
||||
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
|
||||
|
||||
Where colors are: \fBblack\fP, \fBred\fP, \fBgreen\fP, \fByellow\fP, \fBblue\fP, \fBmagenta\fP, \fBcyan\fP, \fBgray\fP, \fBbrightblack\fP, \fBbrightred\fP, \fBbrightgreen\fP, \fBbrightyellow\fP, \fBbrightblue\fP, \fBbrightmagenta\fP, \fBbrightcyan\fP, \fBwhite\fP, or \fBdefault\fP
|
||||
|
||||
For example, to set to the default colors:
|
||||
|
||||
.RS
|
||||
JC_COLORS=blue,brightblack,magenta,green
|
||||
|
||||
or
|
||||
|
||||
JC_COLORS=default,default,default,default
|
||||
.RE
|
||||
|
||||
.SH CUSTOM PARSERS
|
||||
Custom local parser plugins may be placed in a \fBjc/jcparsers\fP folder in your local "App data directory":
|
||||
|
||||
.RS
|
||||
- Linux/unix: \fB$HOME/.local/share/jc/jcparsers\fP
|
||||
|
||||
- macOS: \fB$HOME/Library/Application Support/jc/jcparsers\fP
|
||||
|
||||
- Windows: \fB$LOCALAPPDATA\\jc\\jc\\jcparsers\fP
|
||||
.RE
|
||||
|
||||
Local parser plugins are standard python module files. Use the \fBjc/parsers/foo.py\fP parser as a template and simply place a \fB.py\fP file in the \fBjcparsers\fP subfolder.
|
||||
|
||||
Local plugin filenames must be valid python module names, therefore must consist entirely of alphanumerics and start with a letter. Local plugins may override default plugins.
|
||||
|
||||
Note: The application data directory follows the XDG Base Directory Specification
|
||||
|
||||
.SH CAVEATS
|
||||
\fBLocale:\fP For best results set the \fBLANG\fP locale environment variable to \fBC\fP or \fBen_US.UTF-8\fP. For example, either by setting directly on the command-line:
|
||||
|
||||
\fB$ LANG=C date | jc --date\fP
|
||||
|
||||
or by exporting to the environment before running commands:
|
||||
|
||||
\fB$ export LANG=C\fP
|
||||
|
||||
\fBTimezones:\fP Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a \fB_utc\fP suffix it is considered naive. (i.e. based on the local timezone of the system the \fBjc\fP parser was run on).
|
||||
|
||||
If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a \fB_utc\fP suffix on the key name. (e.g. \fBepoch_utc\fP) No other timezones are supported for aware timestamps.
|
||||
|
||||
.SH EXAMPLES
|
||||
Standard Syntax:
|
||||
.RS
|
||||
$ dig www.google.com | jc \fB--dig\fP \fB-p\fP
|
||||
.RE
|
||||
|
||||
Magic Syntax:
|
||||
.RS
|
||||
$ jc \fB-p\fP dig www.google.com
|
||||
.RE
|
||||
|
||||
For parser documentation:
|
||||
.RS
|
||||
$ jc \fB-h\fP \fB--dig\fP
|
||||
.RE
|
||||
.SH AUTHOR
|
||||
Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
https://github.com/kellyjonbrazil/jc
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright (c) 2019-2021 Kelly Brazil
|
||||
|
||||
License: MIT License
|
BIN
man/jc.1.gz
BIN
man/jc.1.gz
Binary file not shown.
@ -22,4 +22,4 @@ with open('man/jc.1', 'rb') as f_in:
|
||||
|
||||
shutil.copyfile('man/jc.1.gz', 'jc/man/jc.1.gz')
|
||||
|
||||
os.remove('man/jc.1')
|
||||
# os.remove('man/jc.1')
|
||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name='jc',
|
||||
version='1.15.6',
|
||||
version='1.16.0',
|
||||
author='Kelly Brazil',
|
||||
author_email='kellyjonbrazil@gmail.com',
|
||||
description='Converts the output of popular command-line tools and file-types to JSON.',
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-d-multi.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-d-multi.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","units":"sectors","partitions":[{"device":"/dev/sda1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sda2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sda3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sda4","start":0,"size":0,"id":"0","boot":false}]},{"disk":"/dev/sdb","units":"sectors","partitions":[{"device":"/dev/sdb1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sdb2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sdb3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sdb4","start":0,"size":0,"id":"0","boot":false}]}]
|
16
tests/fixtures/centos-7.7/sfdisk-d-multi.out
vendored
Normal file
16
tests/fixtures/centos-7.7/sfdisk-d-multi.out
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# partition table of /dev/sda
|
||||
unit: sectors
|
||||
|
||||
/dev/sda1 : start= 2048, size= 2097152, Id=83, bootable
|
||||
/dev/sda2 : start= 2099200, size= 39843840, Id=8e
|
||||
/dev/sda3 : start= 0, size= 0, Id= 0
|
||||
/dev/sda4 : start= 0, size= 0, Id= 0
|
||||
|
||||
# partition table of /dev/sdb
|
||||
unit: sectors
|
||||
|
||||
/dev/sdb1 : start= 2048, size= 2097152, Id=83, bootable
|
||||
/dev/sdb2 : start= 2099200, size= 39843840, Id=8e
|
||||
/dev/sdb3 : start= 0, size= 0, Id= 0
|
||||
/dev/sdb4 : start= 0, size= 0, Id= 0
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-d.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-d.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","units":"sectors","partitions":[{"device":"/dev/sda1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sda2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sda3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sda4","start":0,"size":0,"id":"0","boot":false}]}]
|
7
tests/fixtures/centos-7.7/sfdisk-d.out
vendored
Normal file
7
tests/fixtures/centos-7.7/sfdisk-d.out
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# partition table of /dev/sda
|
||||
unit: sectors
|
||||
|
||||
/dev/sda1 : start= 2048, size= 2097152, Id=83, bootable
|
||||
/dev/sda2 : start= 2099200, size= 39843840, Id=8e
|
||||
/dev/sda3 : start= 0, size= 0, Id= 0
|
||||
/dev/sda4 : start= 0, size= 0, Id= 0
|
1
tests/fixtures/centos-7.7/sfdisk-l-multi.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-l-multi.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]}]
|
21
tests/fixtures/centos-7.7/sfdisk-l-multi.out
vendored
Normal file
21
tests/fixtures/centos-7.7/sfdisk-l-multi.out
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
|
||||
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
|
||||
|
||||
Device Boot Start End #cyls #blocks Id System
|
||||
/dev/sda1 * 0+ 130- 131- 1048576 83 Linux
|
||||
/dev/sda2 130+ 2610- 2481- 19921920 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 0 Empty
|
||||
|
||||
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
|
||||
|
||||
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
|
||||
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
|
||||
|
||||
Device Boot Start End #cyls #blocks Id System
|
||||
/dev/sda1 * 0+ 130- 131- 1048576 83 Linux
|
||||
/dev/sda2 130+ 2610- 2481- 19921920 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 0 Empty
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-l.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-l.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]
|
14
tests/fixtures/centos-7.7/sfdisk-l.out
vendored
Normal file
14
tests/fixtures/centos-7.7/sfdisk-l.out
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
|
||||
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
|
||||
|
||||
Device Boot Start End #cyls #blocks Id System
|
||||
/dev/sda1 * 0+ 130- 131- 1048576 83 Linux
|
||||
/dev/sda2 130+ 2610- 2481- 19921920 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 0 Empty
|
||||
|
||||
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
|
||||
|
||||
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-luB.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-luB.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":1024,"end":1049599,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":1049600,"end":20971519,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]
|
14
tests/fixtures/centos-7.7/sfdisk-luB.out
vendored
Normal file
14
tests/fixtures/centos-7.7/sfdisk-luB.out
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
|
||||
Units: blocks of 1024 bytes, counting from 0
|
||||
|
||||
Device Boot Start End #blocks Id System
|
||||
/dev/sda1 * 1024 1049599 1048576 83 Linux
|
||||
/dev/sda2 1049600 20971519 19921920 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 Empty
|
||||
|
||||
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
|
||||
|
||||
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-luM.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-luM.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"1MiB = 1024*1024 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":1,"end":1024,"mib":1024,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":1025,"end":20479,"mib":19455,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"mib":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"mib":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]
|
14
tests/fixtures/centos-7.7/sfdisk-luM.out
vendored
Normal file
14
tests/fixtures/centos-7.7/sfdisk-luM.out
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
|
||||
Units: 1MiB = 1024*1024 bytes, blocks of 1024 bytes, counting from 0
|
||||
|
||||
Device Boot Start End MiB #blocks Id System
|
||||
/dev/sda1 * 1 1024 1024 1048576 83 Linux
|
||||
/dev/sda2 1025 20479 19455 19921920 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 0 Empty
|
||||
|
||||
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
|
||||
|
||||
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
|
||||
|
1
tests/fixtures/centos-7.7/sfdisk-luS.json
vendored
Normal file
1
tests/fixtures/centos-7.7/sfdisk-luS.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"sectors of 512 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":2099199,"sectors":2097152,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":2099200,"end":41943039,"sectors":39843840,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"sectors":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"sectors":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]
|
14
tests/fixtures/centos-7.7/sfdisk-luS.out
vendored
Normal file
14
tests/fixtures/centos-7.7/sfdisk-luS.out
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
|
||||
Units: sectors of 512 bytes, counting from 0
|
||||
|
||||
Device Boot Start End #sectors Id System
|
||||
/dev/sda1 * 2048 2099199 2097152 83 Linux
|
||||
/dev/sda2 2099200 41943039 39843840 8e Linux LVM
|
||||
/dev/sda3 0 - 0 0 Empty
|
||||
/dev/sda4 0 - 0 0 Empty
|
||||
|
||||
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
|
||||
|
||||
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.date
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.dig
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.dir
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.last
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.ls
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import json
|
||||
import jc.parsers.rpm_qi
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
106
tests/test_sfdisk.py
Normal file
106
tests/test_sfdisk.py
Normal file
@ -0,0 +1,106 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.sfdisk
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# input
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_l = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l-multi.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_l_multi = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_d = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d-multi.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_d_multi = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luB.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luB = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luM.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luM = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luS.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luS = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_l_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l-multi.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_l_multi_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_d_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d-multi.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_d_multi_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luB.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luB_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luM.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luM_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luS.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_sfdisk_luS_json = json.loads(f.read())
|
||||
|
||||
def test_sfdisk_nodata(self):
|
||||
"""
|
||||
Test 'sfdisk' with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse('', quiet=True), [])
|
||||
|
||||
def test_sfdisk_l_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -l' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_l, quiet=True), self.centos_7_7_sfdisk_l_json)
|
||||
|
||||
def test_sfdisk_l_multi_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -l' with multiple disk data on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_l_multi, quiet=True), self.centos_7_7_sfdisk_l_multi_json)
|
||||
|
||||
def test_sfdisk_d_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -d' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_d, quiet=True), self.centos_7_7_sfdisk_d_json)
|
||||
|
||||
def test_sfdisk_d_multi_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -d' with multiple disk data on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_d_multi, quiet=True), self.centos_7_7_sfdisk_d_multi_json)
|
||||
|
||||
def test_sfdisk_luB_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -luB' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luB, quiet=True), self.centos_7_7_sfdisk_luB_json)
|
||||
|
||||
def test_sfdisk_luM_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -luM' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luM, quiet=True), self.centos_7_7_sfdisk_luM_json)
|
||||
|
||||
def test_sfdisk_luS_centos_7_7(self):
|
||||
"""
|
||||
Test 'sfdisk -luS' on Centos 7.7
|
||||
"""
|
||||
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luS, quiet=True), self.centos_7_7_sfdisk_luS_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.stat
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import jc.parsers.systeminfo
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
test_files = [
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.upower
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,6 +1,14 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import jc.utils
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.who
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||
if not sys.platform.startswith('win32'):
|
||||
os.environ['TZ'] = 'America/Los_Angeles'
|
||||
time.tzset()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
|
Reference in New Issue
Block a user