Skip to content

Commit

Permalink
Merge pull request #213 from kellyjonbrazil/dev
Browse files Browse the repository at this point in the history
Dev v1.18.6
  • Loading branch information
kellyjonbrazil authored Mar 25, 2022
2 parents ac61e9a + 789f073 commit e05be3f
Show file tree
Hide file tree
Showing 237 changed files with 4,289 additions and 1,242 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
jc changelog

20220325 v1.18.6
- Add pidstat command parser tested on linux
- Add pidstat command streaming parser tested on linux
- Add mpstat command parser tested on linux
- Add mpstat command streaming parser tested on linux
- Add single-line ASCII and Unicode table parser
- Add multi-line ASCII and Unicode table parser
- Add documentation option to parser_info() and all_parser_info()

20220305 v1.18.5
- Fix date parser to ensure AM/PM period string is always uppercase

Expand Down
64 changes: 64 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,29 @@ mount | jc --mount -p # or: jc -p mount
}
]
```
### mpstat
```bash
mpstat | jc --mpstat -p # or jc -p mpstat
```
```json
[
{
"cpu": "all",
"percent_usr": 12.94,
"percent_nice": 0.0,
"percent_sys": 26.42,
"percent_iowait": 0.43,
"percent_irq": 0.0,
"percent_soft": 0.16,
"percent_steal": 0.0,
"percent_guest": 0.0,
"percent_gnice": 0.0,
"percent_idle": 60.05,
"type": "cpu",
"time": "01:58:14 PM"
}
]
```
### netstat
```bash
netstat -apee | jc --netstat -p # or: jc -p netstat -apee
Expand Down Expand Up @@ -2497,6 +2520,47 @@ cat /etc/passwd | jc --passwd -p
}
]
```
### pidstat
```bash
pidstat -hl | jc --pidstat -p # or jc -p pidstat -hl
```
```json
[
{
"time": 1646859134,
"uid": 0,
"pid": 1,
"percent_usr": 0.0,
"percent_system": 0.03,
"percent_guest": 0.0,
"percent_cpu": 0.03,
"cpu": 0,
"command": "/usr/lib/systemd/systemd --switched-root --system..."
},
{
"time": 1646859134,
"uid": 0,
"pid": 6,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "ksoftirqd/0"
},
{
"time": 1646859134,
"uid": 0,
"pid": 2263,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "kworker/0:0"
}
]
```
### ping
```bash
ping 8.8.8.8 -c 3 | jc --ping -p # or: jc -p ping 8.8.8.8 -c 3
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ option.
- `--airport` enables the `airport -I` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/airport))
- `--airport-s` enables the `airport -s` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s))
- `--arp` enables the `arp` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/arp))
- `--asciitable` enables the ASCII and Unicode table parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable))
- `--asciitable-m` enables the multi-line ASCII and Unicode table parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable_m))
- `--blkid` enables the `blkid` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/blkid))
- `--cksum` enables the `cksum` and `sum` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/cksum))
- `--crontab` enables the `crontab` command and file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/crontab))
Expand Down Expand Up @@ -190,10 +192,14 @@ option.
- `--lsof` enables the `lsof` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsof))
- `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb))
- `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount))
- `--mpstat` enables the `mpstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat))
- `--mpstat-s` enables the `mpstat` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat_s))
- `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat))
- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli))
- `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq))
- `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd))
- `--pidstat` enables the `pidstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat))
- `--pidstat-s` enables the `pidstat` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat_s))
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
- `--ping-s` enables the `ping` and `ping6` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping_s))
- `--pip-list` enables the `pip list` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_list))
Expand Down
26 changes: 18 additions & 8 deletions docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

# jc.lib

jc - JSON Convert
JC lib module
jc - JSON Convert lib module

<a id="jc.lib.parse"></a>

Expand Down Expand Up @@ -133,23 +132,34 @@ subset of `parser_mod_list()`.
### parser\_info

```python
def parser_info(parser_mod_name: str) -> Dict
def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict
```

Returns a dictionary that includes the module metadata.
Returns a dictionary that includes the parser module metadata.

This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.
Parameters:

parser_mod_name: (string) name of the parser module. This
function will accept module_name,
cli-name, and --argument-name
variants of the module name.

documentation: (boolean) include parser docstring if True

<a id="jc.lib.all_parser_info"></a>

### all\_parser\_info

```python
def all_parser_info() -> List[Dict]
def all_parser_info(documentation: bool = False) -> List[Dict]
```

Returns a list of dictionaries that includes metadata for all modules.
Returns a list of dictionaries that includes metadata for all parser
modules.

Parameters:

documentation: (boolean) include parser docstrings if True

<a id="jc.lib.get_help"></a>

Expand Down
5 changes: 0 additions & 5 deletions docs/parsers/acpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ Usage (module):
import jc
result = jc.parse('acpi', acpi_command_output)

or

import jc.parsers.acpi
result = jc.parsers.acpi.parse(acpi_command_output)

Schema:

[
Expand Down
5 changes: 0 additions & 5 deletions docs/parsers/airport.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ Usage (module):
import jc
result = jc.parse('airport', airport_command_output)

or

import jc.parsers.airport
result = jc.parsers.airport.parse(airport_command_output)

Schema:

{
Expand Down
5 changes: 0 additions & 5 deletions docs/parsers/airport_s.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ Usage (module):
import jc
result = jc.parse('airport_s', airport_s_command_output)

or

import jc.parsers.airport_s
result = jc.parsers.airport_s.parse(airport_s_command_output)

Schema:

[
Expand Down
9 changes: 2 additions & 7 deletions docs/parsers/arp.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ Usage (module):
import jc
result = jc.parse('arp', arp_command_output)

or

import jc.parsers.arp
result = jc.parsers.arp.parse(arp_command_output)

Schema:

[
Expand Down Expand Up @@ -127,7 +122,7 @@ Examples:
### parse

```python
def parse(data, raw=False, quiet=False)
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
```

Main text parsing function
Expand All @@ -145,4 +140,4 @@ Returns:
### Parser Information
Compatibility: linux, aix, freebsd, darwin

Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com)
139 changes: 139 additions & 0 deletions docs/parsers/asciitable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.asciitable"></a>

# jc.parsers.asciitable

jc - JSON Convert `asciitable` parser

This parser converts ASCII and Unicode text tables with single-line rows.

Column headers must be at least two spaces apart from each other and must
be unique.

For example:

╒══════════╤═════════╤════════╕
│ foo │ bar │ baz │
╞══════════╪═════════╪════════╡
│ good day │ │ 12345 │
├──────────┼─────────┼────────┤
│ hi there │ abc def │ 3.14 │
╘══════════╧═════════╧════════╛

or

+-----------------------------+
| foo bar baz |
+-----------------------------+
| good day 12345 |
| hi there abc def 3.14 |
+-----------------------------+

or

| foo | bar | baz |
|----------|---------|--------|
| good day | | 12345 |
| hi there | abc def | 3.14 |

or

foo bar baz
--------- -------- ------
good day 12345
hi there abc def 3.14

or

foo bar baz
good day 12345
hi there abc def 3.14

etc...

Headers (keys) are converted to snake-case. All values are returned as
strings, except empty strings, which are converted to None/null.

Usage (cli):

$ cat table.txt | jc --asciitable

Usage (module):

import jc
result = jc.parse('asciitable', asciitable_string)

Schema:

[
{
"column_name1": string, # empty string is null
"column_name2": string # empty string is null
}
]

Examples:

$ echo '
> ╒══════════╤═════════╤════════╕
> │ foo │ bar │ baz │
> ╞══════════╪═════════╪════════╡
> │ good day │ │ 12345 │
> ├──────────┼─────────┼────────┤
> │ hi there │ abc def │ 3.14 │
> ╘══════════╧═════════╧════════╛' | jc --asciitable -p
[
{
"foo": "good day",
"bar": null,
"baz": "12345"
},
{
"foo": "hi there",
"bar": "abc def",
"baz": "3.14"
}
]

$ echo '
> foo bar baz
> --------- -------- ------
> good day 12345
> hi there abc def 3.14' | jc --asciitable -p
[
{
"foo": "good day",
"bar": null,
"baz": "12345"
},
{
"foo": "hi there",
"bar": "abc def",
"baz": "3.14"
}
]

<a id="jc.parsers.asciitable.parse"></a>

### parse

```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
```

Main text parsing function

Parameters:

data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True

Returns:

List of Dictionaries. Raw or processed structured data.

### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd

Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
Loading

0 comments on commit e05be3f

Please sign in to comment.