mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2026-04-03 17:44:07 +02:00
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5627a4594 | ||
|
|
81ffdb2510 | ||
|
|
4c00a99850 | ||
|
|
2bfcb45b28 | ||
|
|
ab0c10e791 | ||
|
|
2c1935115d | ||
|
|
d98e43dc78 | ||
|
|
9348988d64 | ||
|
|
1285c66467 | ||
|
|
b7191bbc13 | ||
|
|
98b97509f7 | ||
|
|
2b2b570490 | ||
|
|
cce2d1ff29 | ||
|
|
b79600c572 | ||
|
|
140f1a8543 | ||
|
|
e34657cfde | ||
|
|
99070fa607 | ||
|
|
2b46785b1f | ||
|
|
c72562524b | ||
|
|
b7dd6441c7 | ||
|
|
31fcc2f755 | ||
|
|
b391aa14bc | ||
|
|
d3c45debbb | ||
|
|
5b08469b87 | ||
|
|
4a77ec63a4 | ||
|
|
d13606b6dc | ||
|
|
05291c93bb | ||
|
|
8cf00a208e | ||
|
|
06d73c8876 | ||
|
|
649c646ea2 | ||
|
|
b7756d9250 | ||
|
|
1cd2cd954c | ||
|
|
72020b8da9 | ||
|
|
cf9720b749 | ||
|
|
967b9db7f9 | ||
|
|
bb3acb1182 | ||
|
|
560c7f7e6d | ||
|
|
79b2841764 | ||
|
|
a06a89cbd1 | ||
|
|
431bd969eb | ||
|
|
c87b722aec | ||
|
|
3688b8b014 | ||
|
|
07b8d9e0c0 | ||
|
|
7454b53e39 | ||
|
|
3d6a76024d | ||
|
|
421b980957 | ||
|
|
4a22e27d6a | ||
|
|
99f7842dee |
0
LICENSE.md
Executable file → Normal file
0
LICENSE.md
Executable file → Normal file
@@ -1 +0,0 @@
|
||||
graft tests/fixtures
|
||||
29
README.md
Executable file → Normal file
29
README.md
Executable file → Normal file
@@ -69,10 +69,21 @@ Release notes can be found [here](https://blog.kellybrazil.com/category/jc-news/
|
||||
For more information on the motivations for this project, please see my [blog post](https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/).
|
||||
|
||||
## Installation
|
||||
There are several ways to get `jc`. You can install via `pip`, `brew`, DEB or RPM packages, or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
|
||||
|
||||
### Pip (macOS, linux, unix, Windows)
|
||||
```
|
||||
$ pip3 install --upgrade jc
|
||||
```
|
||||
|
||||
### Brew (macOS)
|
||||
```
|
||||
$ brew install jc
|
||||
```
|
||||
|
||||
### Packages and Binaries
|
||||
Please see https://kellyjonbrazil.github.io/jc-packaging/ for details.
|
||||
|
||||
## Usage
|
||||
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`.
|
||||
```
|
||||
@@ -142,7 +153,23 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
|
||||
- `-m` monochrome JSON output
|
||||
- `-p` pretty format the JSON output
|
||||
- `-q` quiet mode. Suppresses warning messages
|
||||
- `-r` raw output. Provides a more literal JSON output with all values as text and no additional sematic processing
|
||||
- `-r` raw output. Provides a more literal JSON output with all values as strings and no additional sematic processing
|
||||
|
||||
### Setting Custom Colors via Environment Variable
|
||||
You can specify custom colors via the `JC_COLORS` environment variable. The `JC_COLORS` 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: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`, `brightmagenta`, `brightcyan`, `white`, or `default`
|
||||
|
||||
For example, to set to the default colors:
|
||||
```
|
||||
JC_COLORS=blue,brightblack,magenta,green
|
||||
```
|
||||
or
|
||||
```
|
||||
JC_COLORS=default,default,default,default
|
||||
```
|
||||
|
||||
## Contributions
|
||||
Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and submit your parser with a pull request.
|
||||
|
||||
@@ -1,5 +1,38 @@
|
||||
jc changelog
|
||||
|
||||
20200511 v1.10.12
|
||||
- Remove shebang from jc/cli.py for Fedora packaging
|
||||
|
||||
20200511 v1.10.11
|
||||
- Change file permissions for Fedora packaging
|
||||
|
||||
20200509 v1.10.10
|
||||
- Fix ls parser issue where the first file was skipped for ls -R on some platforms
|
||||
- Update last parser to handle 'gone - no logout' condition
|
||||
- Update netstat parser to handle bluetooth section (ignore gracefully for now)
|
||||
|
||||
20200508 v1.10.9
|
||||
- Add license info to vendorized ifconfig-parser class
|
||||
|
||||
20200508 v1.10.8
|
||||
- Add license file to dist for Fedora RPM packaging requirements
|
||||
- Remove tests from package to keep from polluting the global site-packages
|
||||
|
||||
20200501 v1.10.7
|
||||
- Requirements modifications for Fedora RPM packaging requirements
|
||||
|
||||
20200420 v1.10.6
|
||||
- Remove homebrew shim references from du osx tests
|
||||
|
||||
20200414 v1.10.5
|
||||
- Minor change of using sys.exit(0) instead of exit()
|
||||
|
||||
20200412 v1.10.4
|
||||
- Add color customization via JC_COLORS env variable
|
||||
|
||||
20200409 v1.10.3
|
||||
- Fix break on pipe error
|
||||
|
||||
20200409 v1.10.2
|
||||
- Change colors to ansi and match jello colors
|
||||
|
||||
|
||||
@@ -147,6 +147,17 @@ Examples:
|
||||
info(self, /, *args, **kwargs)
|
||||
```
|
||||
|
||||
## IfconfigParser
|
||||
```python
|
||||
IfconfigParser(self, console_output)
|
||||
```
|
||||
|
||||
## InterfaceNotFound
|
||||
```python
|
||||
InterfaceNotFound(self, /, *args, **kwargs)
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
|
||||
70
jc/cli.py
70
jc/cli.py
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
"""jc - JSON CLI output utility
|
||||
JC cli module
|
||||
"""
|
||||
@@ -18,7 +17,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.10.2'
|
||||
version = '1.10.12'
|
||||
description = 'jc cli output JSON conversion tool'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -80,12 +79,52 @@ parsers = [
|
||||
]
|
||||
|
||||
|
||||
class JcStyle(Style):
|
||||
styles = {
|
||||
Name.Tag: 'bold ansiblue', # key names
|
||||
Keyword: 'ansibrightblack', # true, false, null
|
||||
Number: 'ansimagenta', # int, float
|
||||
String: 'ansigreen' # string
|
||||
def set_env_colors():
|
||||
"""
|
||||
Grab custom colors from JC_COLORS environment variable. JC_COLORS env variable takes 4 comma
|
||||
separated string values and should be in the format of:
|
||||
|
||||
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
|
||||
|
||||
Where colors are: black, red, green, yellow, blue, magenta, cyan, gray, brightblack, brightred,
|
||||
brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, white, default
|
||||
|
||||
Default colors:
|
||||
|
||||
JC_COLORS=blue,brightblack,magenta,green
|
||||
or
|
||||
JC_COLORS=default,default,default,default
|
||||
|
||||
"""
|
||||
env_colors = os.getenv('JC_COLORS')
|
||||
input_error = False
|
||||
|
||||
if env_colors:
|
||||
color_list = env_colors.split(',')
|
||||
else:
|
||||
input_error = True
|
||||
|
||||
if env_colors and len(color_list) != 4:
|
||||
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
|
||||
input_error = True
|
||||
|
||||
if env_colors:
|
||||
for color in color_list:
|
||||
if color not in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'gray', 'brightblack', 'brightred',
|
||||
'brightgreen', 'brightyellow', 'brightblue', 'brightmagenta', 'brightcyan', 'white', 'default']:
|
||||
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
|
||||
input_error = True
|
||||
|
||||
# if there is an issue with the env variable, just set all colors to default and move on
|
||||
if input_error:
|
||||
color_list = ['default', 'default', 'default', 'default']
|
||||
|
||||
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
|
||||
return {
|
||||
Name.Tag: f'bold ansi{color_list[0]}' if not color_list[0] == 'default' else f'bold ansiblue', # key names
|
||||
Keyword: f'ansi{color_list[1]}' if not color_list[1] == 'default' else f'ansibrightblack', # true, false, null
|
||||
Number: f'ansi{color_list[2]}' if not color_list[2] == 'default' else f'ansimagenta', # numbers
|
||||
String: f'ansi{color_list[3]}' if not color_list[3] == 'default' else f'ansigreen' # strings
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +244,11 @@ def helptext(message):
|
||||
|
||||
|
||||
def json_out(data, pretty=False, mono=False, piped_out=False):
|
||||
# set colors
|
||||
class JcStyle(Style):
|
||||
styles = set_env_colors()
|
||||
|
||||
|
||||
if not mono and not piped_out:
|
||||
if pretty:
|
||||
print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
@@ -277,7 +321,7 @@ def magic():
|
||||
valid_command, run_command = generate_magic_command(sys.argv)
|
||||
if valid_command:
|
||||
os.system(run_command)
|
||||
exit()
|
||||
sys.exit(0)
|
||||
elif run_command is None:
|
||||
return
|
||||
else:
|
||||
@@ -289,6 +333,12 @@ def main():
|
||||
# break on ctrl-c keyboard interrupt
|
||||
signal.signal(signal.SIGINT, ctrlc)
|
||||
|
||||
# break on pipe error. need try/except for windows compatibility
|
||||
try:
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# try magic syntax first: e.g. jc -p ls -al
|
||||
magic()
|
||||
|
||||
@@ -307,7 +357,7 @@ def main():
|
||||
|
||||
if 'a' in options:
|
||||
json_out(about_jc(), pretty=pretty, mono=mono, piped_out=piped_output())
|
||||
exit()
|
||||
sys.exit(0)
|
||||
|
||||
if sys.stdin.isatty():
|
||||
helptext('missing piped data')
|
||||
|
||||
@@ -141,16 +141,17 @@ Examples:
|
||||
}
|
||||
]
|
||||
"""
|
||||
import re
|
||||
from collections import namedtuple
|
||||
import jc.utils
|
||||
from ifconfigparser import IfconfigParser
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.6'
|
||||
version = '1.7'
|
||||
description = 'ifconfig command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Using ifconfig-parser package from https://github.com/KnightWhoSayNi/ifconfig-parser'
|
||||
details = 'Using ifconfig-parser from https://github.com/KnightWhoSayNi/ifconfig-parser'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd', 'darwin']
|
||||
@@ -160,6 +161,222 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
class IfconfigParser(object):
|
||||
# Author: threeheadedknight@protonmail.com
|
||||
# Date created: 30.06.2018 17:03
|
||||
# Python Version: 3.7
|
||||
|
||||
# MIT License
|
||||
|
||||
# Copyright (c) 2018 threeheadedknight@protonmail.com
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
attributes = ['name', 'type', 'mac_addr', 'ipv4_addr', 'ipv4_bcast', 'ipv4_mask', 'ipv6_addr', 'ipv6_mask',
|
||||
'ipv6_scope', 'state', 'mtu', 'metric', 'rx_packets', 'rx_errors', 'rx_dropped', 'rx_overruns',
|
||||
'rx_frame', 'tx_packets', 'tx_errors', 'tx_dropped', 'tx_overruns', 'tx_carrier', 'tx_collisions',
|
||||
'rx_bytes', 'tx_bytes']
|
||||
|
||||
def __init__(self, console_output):
|
||||
"""
|
||||
:param console_output:
|
||||
"""
|
||||
|
||||
if isinstance(console_output, list):
|
||||
source_data = " ".join(console_output)
|
||||
else:
|
||||
source_data = console_output.replace("\n", " ")
|
||||
self.interfaces = self.parser(source_data=source_data)
|
||||
|
||||
def list_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return sorted(self.interfaces.keys())
|
||||
|
||||
def count_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return len(self.interfaces.keys())
|
||||
|
||||
def filter_interfaces(self, **kwargs):
|
||||
"""
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
for attr in kwargs.keys():
|
||||
if attr not in IfconfigParser.attributes:
|
||||
raise ValueError("Attribute [{}] not supported.".format(attr))
|
||||
|
||||
filtered_interfaces = []
|
||||
for name, details in self.interfaces.items():
|
||||
|
||||
if all(getattr(details, attr) == kwargs[attr] for attr in kwargs.keys()):
|
||||
filtered_interfaces.append(name)
|
||||
|
||||
return sorted(filtered_interfaces)
|
||||
|
||||
def get_interface(self, name):
|
||||
"""
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
if name in self.list_interfaces():
|
||||
return self.interfaces[name]
|
||||
else:
|
||||
raise InterfaceNotFound("Interface [{}] not found.".format(name))
|
||||
|
||||
def get_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return self.interfaces
|
||||
|
||||
def is_available(self, name):
|
||||
"""
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
return name in self.interfaces
|
||||
|
||||
def parser(self, source_data):
|
||||
"""
|
||||
:param source_data:
|
||||
:return:
|
||||
"""
|
||||
|
||||
# Linux syntax
|
||||
re_linux_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+)\s+Link encap:(?P<type>\S+\s?\S+)(\s+HWaddr\s+\b"
|
||||
r"(?P<mac_addr>[0-9A-Fa-f:?]+))?",
|
||||
re.I)
|
||||
re_linux_ipv4 = re.compile(
|
||||
r"inet addr:(?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+Bcast:"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+Mask:(?P<ipv4_mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})",
|
||||
re.I)
|
||||
re_linux_ipv6 = re.compile(
|
||||
r"inet6 addr:\s+(?P<ipv6_addr>\S+)/(?P<ipv6_mask>[0-9]+)\s+Scope:(?P<ipv6_scope>Link|Host)",
|
||||
re.I)
|
||||
re_linux_state = re.compile(
|
||||
r"\W+(?P<state>(?:\w+\s)+)(?:\s+)?MTU:(?P<mtu>[0-9]+)\s+Metric:(?P<metric>[0-9]+)", re.I)
|
||||
re_linux_rx = re.compile(
|
||||
r"RX packets:(?P<rx_packets>[0-9]+)\s+errors:(?P<rx_errors>[0-9]+)\s+dropped:"
|
||||
r"(?P<rx_dropped>[0-9]+)\s+overruns:(?P<rx_overruns>[0-9]+)\s+frame:(?P<rx_frame>[0-9]+)",
|
||||
re.I)
|
||||
re_linux_tx = re.compile(
|
||||
r"TX packets:(?P<tx_packets>[0-9]+)\s+errors:(?P<tx_errors>[0-9]+)\s+dropped:"
|
||||
r"(?P<tx_dropped>[0-9]+)\s+overruns:(?P<tx_overruns>[0-9]+)\s+carrier:(?P<tx_carrier>[0-9]+)",
|
||||
re.I)
|
||||
re_linux_bytes = re.compile(r"\W+RX bytes:(?P<rx_bytes>\d+)\s+\(.*\)\s+TX bytes:(?P<tx_bytes>\d+)\s+\(.*\)", re.I)
|
||||
re_linux_tx_stats = re.compile(r"collisions:(?P<tx_collisions>[0-9]+)\s+txqueuelen:[0-9]+", re.I)
|
||||
re_linux = [re_linux_interface, re_linux_ipv4, re_linux_ipv6, re_linux_state, re_linux_rx, re_linux_tx,
|
||||
re_linux_bytes, re_linux_tx_stats]
|
||||
|
||||
# OpenBSD syntax
|
||||
re_openbsd_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)?>\s+mtu\s+(?P<mtu>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd_ipv4 = re.compile(
|
||||
r"inet (?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+"
|
||||
r"(?P<ipv4_mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
||||
re.I)
|
||||
re_openbsd_ipv6 = re.compile(
|
||||
r"inet6\s+(?P<ipv6_addr>\S+)\s+prefixlen\s+(?P<ipv6_mask>[0-9]+)\s+scopeid\s+(?P<ipv6_scope>\w+x\w+)<"
|
||||
r"(?:link|host)>",
|
||||
re.I)
|
||||
re_openbsd_details = re.compile(
|
||||
r"\S+\s+(?:(?P<mac_addr>[0-9A-Fa-f:?]+)\s+)?txqueuelen\s+[0-9]+\s+\((?P<type>\S+\s?\S+)\)", re.I)
|
||||
re_openbsd_rx = re.compile(r"RX packets (?P<rx_packets>[0-9]+)\s+bytes\s+(?P<rx_bytes>\d+)\s+.*", re.I)
|
||||
re_openbsd_rx_stats = re.compile(
|
||||
r"RX errors (?P<rx_errors>[0-9]+)\s+dropped\s+(?P<rx_dropped>[0-9]+)\s+overruns\s+"
|
||||
r"(?P<rx_overruns>[0-9]+)\s+frame\s+(?P<rx_frame>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd_tx = re.compile(r"TX packets (?P<tx_packets>[0-9]+)\s+bytes\s+(?P<tx_bytes>\d+)\s+.*", re.I)
|
||||
re_openbsd_tx_stats = re.compile(
|
||||
r"TX errors (?P<tx_errors>[0-9]+)\s+dropped\s+(?P<tx_dropped>[0-9]+)\s+overruns\s+"
|
||||
r"(?P<tx_overruns>[0-9]+)\s+carrier\s+(?P<tx_carrier>[0-9]+)\s+collisions\s+(?P<tx_collisions>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd = [re_openbsd_interface, re_openbsd_ipv4, re_openbsd_ipv6, re_openbsd_details, re_openbsd_rx,
|
||||
re_openbsd_rx_stats, re_openbsd_tx, re_openbsd_tx_stats]
|
||||
|
||||
# FreeBSD syntax
|
||||
re_freebsd_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)>\s+metric\s+"
|
||||
r"(?P<metric>[0-9]+)\s+mtu\s+(?P<mtu>[0-9]+)",
|
||||
re.I)
|
||||
re_freebsd_ipv4 = re.compile(
|
||||
r"inet (?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+(?P<ipv4_mask>0x\S+)(\s+broadcast\s+"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
||||
re.I)
|
||||
re_freebsd_ipv6 = re.compile(r"\s?inet6\s(?P<ipv6_addr>.*)(?:\%\w+\d+)\sprefixlen\s(?P<ipv6_mask>\d+)(?:\s\w+)?\sscopeid\s(?P<ipv6_scope>\w+x\w+)", re.I)
|
||||
re_freebsd_details = re.compile(r"ether\s+(?P<mac_addr>[0-9A-Fa-f:?]+)", re.I)
|
||||
re_freebsd = [re_freebsd_interface, re_freebsd_ipv4, re_freebsd_ipv6, re_freebsd_details]
|
||||
|
||||
available_interfaces = dict()
|
||||
|
||||
for pattern in [re_linux_interface, re_openbsd_interface, re_freebsd_interface]:
|
||||
network_interfaces = re.finditer(pattern, source_data)
|
||||
positions = []
|
||||
while True:
|
||||
try:
|
||||
pos = next(network_interfaces)
|
||||
positions.append(max(pos.start() - 1, 0))
|
||||
except StopIteration:
|
||||
break
|
||||
if positions:
|
||||
positions.append(len(source_data))
|
||||
break
|
||||
|
||||
if not positions:
|
||||
return available_interfaces
|
||||
|
||||
for l, r in zip(positions, positions[1:]):
|
||||
chunk = source_data[l:r]
|
||||
_interface = dict()
|
||||
for pattern in re_linux + re_openbsd + re_freebsd:
|
||||
match = re.search(pattern, chunk.replace('\t', '\n'))
|
||||
if match:
|
||||
details = match.groupdict()
|
||||
for k, v in details.items():
|
||||
if isinstance(v, str): details[k] = v.strip()
|
||||
_interface.update(details)
|
||||
if _interface is not None:
|
||||
available_interfaces[_interface['name']] = self.update_interface_details(_interface)
|
||||
|
||||
return available_interfaces
|
||||
|
||||
@staticmethod
|
||||
def update_interface_details(interface):
|
||||
for attr in IfconfigParser.attributes:
|
||||
if attr not in interface:
|
||||
interface[attr] = None
|
||||
return namedtuple('Interface', interface.keys())(**interface)
|
||||
|
||||
|
||||
class InterfaceNotFound(Exception):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
@@ -72,7 +72,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
version = '1.1'
|
||||
description = 'last and lastb command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -122,6 +122,9 @@ def process(proc_data):
|
||||
if 'logout' in entry and entry['logout'] == 'still_logged_in':
|
||||
entry['logout'] = 'still logged in'
|
||||
|
||||
if 'logout' in entry and entry['logout'] == 'gone_-_no_logout':
|
||||
entry['logout'] = 'gone - no logout'
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
@@ -157,6 +160,7 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
entry = entry.replace('system boot', 'system_boot')
|
||||
entry = entry.replace(' still logged in', '- still_logged_in')
|
||||
entry = entry.replace(' gone - no logout', '- gone_-_no_logout')
|
||||
|
||||
linedata = entry.split()
|
||||
if re.match(r'[MTWFS][ouerha][nedritnu] [JFMASOND][aepuco][nbrynlgptvc]', ' '.join(linedata[2:4])):
|
||||
|
||||
@@ -149,7 +149,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.3'
|
||||
version = '1.4'
|
||||
description = 'ls command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -235,8 +235,9 @@ def parse(data, raw=False, quiet=False):
|
||||
if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \
|
||||
and linedata[0].endswith(':'):
|
||||
parent = linedata.pop(0)[:-1]
|
||||
# Pop following total line
|
||||
linedata.pop(0)
|
||||
# Pop following total line if it exists
|
||||
if re.match(r'total [0-9]+', linedata[0]):
|
||||
linedata.pop(0)
|
||||
|
||||
if linedata:
|
||||
# Check if -l was used to parse extra data
|
||||
|
||||
@@ -313,7 +313,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.3'
|
||||
version = '1.4'
|
||||
description = 'netstat command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -536,6 +536,7 @@ def parse(data, raw=False, quiet=False):
|
||||
raw_output = []
|
||||
network = False
|
||||
socket = False
|
||||
bluetooth = False
|
||||
headers = ''
|
||||
network_list = []
|
||||
socket_list = []
|
||||
@@ -546,12 +547,20 @@ def parse(data, raw=False, quiet=False):
|
||||
network_list = []
|
||||
network = True
|
||||
socket = False
|
||||
bluetooth = False
|
||||
continue
|
||||
|
||||
if line.startswith('Active UNIX'):
|
||||
socket_list = []
|
||||
network = False
|
||||
socket = True
|
||||
bluetooth = False
|
||||
continue
|
||||
|
||||
if line.startswith('Active Bluetooth'):
|
||||
network = False
|
||||
socket = False
|
||||
bluetooth = True
|
||||
continue
|
||||
|
||||
if line.startswith('Proto'):
|
||||
@@ -567,6 +576,10 @@ def parse(data, raw=False, quiet=False):
|
||||
socket_list.append(parse_socket(header_text, headers, line))
|
||||
continue
|
||||
|
||||
if bluetooth:
|
||||
# maybe implement later if requested
|
||||
continue
|
||||
|
||||
for item in [network_list, socket_list]:
|
||||
for entry in item:
|
||||
raw_output.append(entry)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
ifconfig-parser>=0.0.5
|
||||
ruamel.yaml>=0.15.0
|
||||
xmltodict>=0.12.0
|
||||
Pygments>=2.5.2
|
||||
Pygments>=2.4.2
|
||||
|
||||
8
setup.py
8
setup.py
@@ -5,23 +5,21 @@ with open('README.md', 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name='jc',
|
||||
version='1.10.2',
|
||||
version='1.10.12',
|
||||
author='Kelly Brazil',
|
||||
author_email='kellyjonbrazil@gmail.com',
|
||||
description='This tool serializes the output of popular command line tools and filetypes to structured JSON output.',
|
||||
install_requires=[
|
||||
'ifconfig-parser>=0.0.5',
|
||||
'ruamel.yaml>=0.15.0',
|
||||
'xmltodict>=0.12.0',
|
||||
'Pygments>=2.5.2'
|
||||
'Pygments>=2.4.2'
|
||||
],
|
||||
license='MIT',
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/markdown',
|
||||
python_requires='>=3.6',
|
||||
url='https://github.com/kellyjonbrazil/jc',
|
||||
packages=setuptools.find_packages(),
|
||||
include_package_data=True,
|
||||
packages=setuptools.find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'jc=jc.cli:main'
|
||||
|
||||
2
tests/fixtures/centos-7.7/ls-R-newlines.json
vendored
2
tests/fixtures/centos-7.7/ls-R-newlines.json
vendored
@@ -1 +1 @@
|
||||
[{"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": "."}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": "."}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": "."}, {"filename": "tmp.CvALl2jE6u", "parent": "."}, {"filename": "tmp.e7AlxSxY5a", "parent": "."}, {"filename": "tmp.uXm9yegjwj", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]
|
||||
[{"filename": "lstest", "parent": "."}, {"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": "."}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": "."}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": "."}, {"filename": "tmp.CvALl2jE6u", "parent": "."}, {"filename": "tmp.e7AlxSxY5a", "parent": "."}, {"filename": "tmp.uXm9yegjwj", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]
|
||||
|
||||
2
tests/fixtures/centos-7.7/ls-R.json
vendored
2
tests/fixtures/centos-7.7/ls-R.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/centos-7.7/ls-glob.json
vendored
2
tests/fixtures/centos-7.7/ls-glob.json
vendored
File diff suppressed because one or more lines are too long
1
tests/fixtures/fedora32/last.json
vendored
Normal file
1
tests/fixtures/fedora32/last.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
[{"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Fri May 1 15:25", "logout": "gone - no logout"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Fri May 1 15:24", "logout": "gone - no logout"}, {"user": "reboot", "tty": "system boot", "hostname": "5.6.6-300.fc32.x", "login": "Fri May 1 15:24", "logout": "running"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Thu Apr 30 15:27", "logout": "15:22", "duration": "23:55"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Thu Apr 30 15:25", "logout": "down", "duration": "23:57"}, {"user": "reboot", "tty": "system boot", "hostname": "5.6.6-300.fc32.x", "login": "Thu Apr 30 15:22", "logout": "15:22", "duration": "1+00:00"}]
|
||||
8
tests/fixtures/fedora32/last.out
vendored
Normal file
8
tests/fixtures/fedora32/last.out
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
kbrazil pts/0 192.168.71.1 Fri May 1 15:25 gone - no logout
|
||||
kbrazil tty1 Fri May 1 15:24 gone - no logout
|
||||
reboot system boot 5.6.6-300.fc32.x Fri May 1 15:24 still running
|
||||
kbrazil pts/0 192.168.71.1 Thu Apr 30 15:27 - 15:22 (23:55)
|
||||
kbrazil tty1 Thu Apr 30 15:25 - down (23:57)
|
||||
reboot system boot 5.6.6-300.fc32.x Thu Apr 30 15:22 - 15:22 (1+00:00)
|
||||
|
||||
wtmp begins Thu Apr 30 15:22:02 2020
|
||||
1
tests/fixtures/fedora32/netstat.json
vendored
Normal file
1
tests/fixtures/fedora32/netstat.json
vendored
Normal file
File diff suppressed because one or more lines are too long
139
tests/fixtures/fedora32/netstat.out
vendored
Normal file
139
tests/fixtures/fedora32/netstat.out
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
Active Internet connections (w/o servers)
|
||||
Proto Recv-Q Send-Q Local Address Foreign Address State
|
||||
tcp 0 0 localhost.localdoma:ssh 192.168.71.1:52882 ESTABLISHED
|
||||
udp 0 0 localhost.locald:bootpc 192.168.71.254:bootps ESTABLISHED
|
||||
Active UNIX domain sockets (w/o servers)
|
||||
Proto RefCnt Flags Type State I-Node Path
|
||||
unix 2 [ ] DGRAM 36371 /run/user/1000/systemd/notify
|
||||
unix 3 [ ] DGRAM 15453 /run/systemd/notify
|
||||
unix 9 [ ] DGRAM 15471 /run/systemd/journal/dev-log
|
||||
unix 2 [ ] DGRAM 165956 @userdb-9bf8f59ca8f2bcce47a377edbaf8985d
|
||||
unix 12 [ ] DGRAM 15479 /run/systemd/journal/socket
|
||||
unix 2 [ ] DGRAM 29064 /var/run/chrony/chronyd.sock
|
||||
unix 2 [ ] DGRAM 165866 @userdb-3f208fa7c8c6d98822a696ee7ca5e3ad
|
||||
unix 2 [ ] DGRAM 165863 @userdb-da253950013f5ea3bc51a4049480d04e
|
||||
unix 2 [ ] DGRAM 165865
|
||||
unix 3 [ ] STREAM CONNECTED 36476
|
||||
unix 3 [ ] STREAM CONNECTED 31389
|
||||
unix 3 [ ] STREAM CONNECTED 30999 /var/lib/sss/pipes/private/sbus-dp_implicit_files.692
|
||||
unix 3 [ ] STREAM CONNECTED 33770 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 30731
|
||||
unix 2 [ ] DGRAM 24653
|
||||
unix 3 [ ] STREAM CONNECTED 31370 /var/lib/sss/pipes/private/sbus-dp_implicit_files.692
|
||||
unix 2 [ ] DGRAM 165862
|
||||
unix 2 [ ] DGRAM 33725
|
||||
unix 3 [ ] STREAM CONNECTED 33885
|
||||
unix 3 [ ] STREAM CONNECTED 31173
|
||||
unix 3 [ ] STREAM CONNECTED 31019
|
||||
unix 3 [ ] STREAM CONNECTED 33886
|
||||
unix 3 [ ] STREAM CONNECTED 30735 /var/lib/sss/pipes/private/sbus-monitor
|
||||
unix 3 [ ] STREAM CONNECTED 166231
|
||||
unix 2 [ ] DGRAM 30987
|
||||
unix 2 [ ] DGRAM 24745
|
||||
unix 2 [ ] DGRAM 165955
|
||||
unix 2 [ ] DGRAM 30575
|
||||
unix 3 [ ] STREAM CONNECTED 31062 /run/dbus/system_bus_socket
|
||||
unix 2 [ ] STREAM CONNECTED 35419
|
||||
unix 3 [ ] STREAM CONNECTED 31399 /run/dbus/system_bus_socket
|
||||
unix 2 [ ] DGRAM 32430
|
||||
unix 2 [ ] DGRAM 29403
|
||||
unix 3 [ ] STREAM CONNECTED 166232 /var/lib/sss/pipes/nss
|
||||
unix 2 [ ] DGRAM 31127
|
||||
unix 2 [ ] DGRAM 29538
|
||||
unix 2 [ ] STREAM CONNECTED 33876
|
||||
unix 3 [ ] STREAM CONNECTED 31020 /var/lib/sss/pipes/private/sbus-monitor
|
||||
unix 3 [ ] STREAM CONNECTED 30998
|
||||
unix 3 [ ] STREAM CONNECTED 36475
|
||||
unix 2 [ ] DGRAM 36002
|
||||
unix 3 [ ] STREAM CONNECTED 33769
|
||||
unix 3 [ ] STREAM CONNECTED 31390 /var/lib/sss/pipes/private/sbus-monitor
|
||||
unix 2 [ ] STREAM CONNECTED 33132
|
||||
unix 3 [ ] STREAM CONNECTED 31398
|
||||
unix 3 [ ] STREAM CONNECTED 30022
|
||||
unix 3 [ ] DGRAM 24748
|
||||
unix 3 [ ] DGRAM 24747
|
||||
unix 2 [ ] DGRAM 36348
|
||||
unix 2 [ ] DGRAM 32085
|
||||
unix 3 [ ] STREAM CONNECTED 31168 /run/systemd/journal/stdout
|
||||
unix 3 [ ] DGRAM 15455
|
||||
unix 3 [ ] STREAM CONNECTED 30830
|
||||
unix 3 [ ] STREAM CONNECTED 26911
|
||||
unix 3 [ ] STREAM CONNECTED 35960
|
||||
unix 2 [ ] DGRAM 24662
|
||||
unix 2 [ ] STREAM CONNECTED 36345
|
||||
unix 3 [ ] STREAM CONNECTED 32538
|
||||
unix 3 [ ] STREAM CONNECTED 28747
|
||||
unix 3 [ ] STREAM CONNECTED 31026
|
||||
unix 3 [ ] DGRAM 28615
|
||||
unix 3 [ ] STREAM CONNECTED 31713 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 31167
|
||||
unix 3 [ ] STREAM CONNECTED 35989 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 36303 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 31809 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 29396 /run/systemd/journal/stdout
|
||||
unix 2 [ ] STREAM CONNECTED 34911
|
||||
unix 3 [ ] DGRAM 36374
|
||||
unix 2 [ ] STREAM CONNECTED 32241
|
||||
unix 3 [ ] STREAM CONNECTED 32057 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 32000 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 33083
|
||||
unix 3 [ ] STREAM CONNECTED 31017
|
||||
unix 3 [ ] DGRAM 36373
|
||||
unix 3 [ ] STREAM CONNECTED 34101
|
||||
unix 3 [ ] STREAM CONNECTED 32539 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 26914
|
||||
unix 3 [ ] STREAM CONNECTED 29395
|
||||
unix 3 [ ] STREAM CONNECTED 31022
|
||||
unix 3 [ ] DGRAM 15456
|
||||
unix 3 [ ] STREAM CONNECTED 29251 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 26915
|
||||
unix 2 [ ] STREAM CONNECTED 33052
|
||||
unix 3 [ ] STREAM CONNECTED 31999
|
||||
unix 2 [ ] DGRAM 29496
|
||||
unix 3 [ ] STREAM CONNECTED 28400
|
||||
unix 3 [ ] STREAM CONNECTED 36378 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 31808
|
||||
unix 3 [ ] STREAM CONNECTED 29250
|
||||
unix 3 [ ] STREAM CONNECTED 24582
|
||||
unix 3 [ ] STREAM CONNECTED 32056
|
||||
unix 3 [ ] STREAM CONNECTED 31347
|
||||
unix 3 [ ] STREAM CONNECTED 28678 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 30980
|
||||
unix 3 [ ] STREAM CONNECTED 31348 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 28677
|
||||
unix 3 [ ] STREAM CONNECTED 34102 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 24805 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 29322 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 36357
|
||||
unix 3 [ ] STREAM CONNECTED 30832 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 26913
|
||||
unix 2 [ ] STREAM CONNECTED 32010
|
||||
unix 3 [ ] STREAM CONNECTED 28748 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 28602
|
||||
unix 3 [ ] STREAM CONNECTED 28401 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 31069 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] DGRAM 28616
|
||||
unix 3 [ ] STREAM CONNECTED 32334 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 31712
|
||||
unix 3 [ ] STREAM CONNECTED 36302
|
||||
unix 3 [ ] STREAM CONNECTED 32333
|
||||
unix 3 [ ] STREAM CONNECTED 32093
|
||||
unix 3 [ ] STREAM CONNECTED 26912
|
||||
unix 2 [ ] STREAM CONNECTED 35774
|
||||
unix 3 [ ] STREAM CONNECTED 29321
|
||||
unix 3 [ ] STREAM CONNECTED 31025
|
||||
unix 3 [ ] STREAM CONNECTED 28470
|
||||
unix 3 [ ] STREAM CONNECTED 32094 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 31259 /run/systemd/journal/stdout
|
||||
unix 2 [ ] DGRAM 36471
|
||||
unix 3 [ ] STREAM CONNECTED 31054
|
||||
unix 3 [ ] STREAM CONNECTED 31064 /run/dbus/system_bus_socket
|
||||
unix 3 [ ] STREAM CONNECTED 28471 /run/systemd/journal/stdout
|
||||
unix 3 [ ] STREAM CONNECTED 36377
|
||||
unix 2 [ ] STREAM CONNECTED 35788
|
||||
unix 3 [ ] STREAM CONNECTED 31258
|
||||
unix 3 [ ] STREAM CONNECTED 31065 /run/dbus/system_bus_socket
|
||||
Active Bluetooth connections (w/o servers)
|
||||
Proto Destination Source State PSM DCID SCID IMTU OMTU Security
|
||||
Proto Destination Source State Channel
|
||||
|
||||
2
tests/fixtures/osx-10.11.6/du.json
vendored
2
tests/fixtures/osx-10.11.6/du.json
vendored
File diff suppressed because one or more lines are too long
7
tests/fixtures/osx-10.11.6/du.out
vendored
7
tests/fixtures/osx-10.11.6/du.out
vendored
@@ -911,13 +911,6 @@
|
||||
112 /usr/local/Homebrew/Library/Homebrew/rubocops/cask
|
||||
40 /usr/local/Homebrew/Library/Homebrew/rubocops/extend
|
||||
344 /usr/local/Homebrew/Library/Homebrew/rubocops
|
||||
288 /usr/local/Homebrew/Library/Homebrew/shims/linux/super
|
||||
288 /usr/local/Homebrew/Library/Homebrew/shims/linux
|
||||
344 /usr/local/Homebrew/Library/Homebrew/shims/mac/super
|
||||
344 /usr/local/Homebrew/Library/Homebrew/shims/mac
|
||||
16 /usr/local/Homebrew/Library/Homebrew/shims/scm
|
||||
280 /usr/local/Homebrew/Library/Homebrew/shims/super
|
||||
928 /usr/local/Homebrew/Library/Homebrew/shims
|
||||
24 /usr/local/Homebrew/Library/Homebrew/test/cask/artifact/shared_examples
|
||||
144 /usr/local/Homebrew/Library/Homebrew/test/cask/artifact
|
||||
24 /usr/local/Homebrew/Library/Homebrew/test/cask/cask_loader
|
||||
|
||||
2
tests/fixtures/osx-10.14.6/du.json
vendored
2
tests/fixtures/osx-10.14.6/du.json
vendored
File diff suppressed because one or more lines are too long
7
tests/fixtures/osx-10.14.6/du.out
vendored
7
tests/fixtures/osx-10.14.6/du.out
vendored
@@ -317,13 +317,6 @@
|
||||
32 /usr/local/Homebrew/Library/Homebrew/cli
|
||||
56 /usr/local/Homebrew/Library/Homebrew/manpages
|
||||
8 /usr/local/Homebrew/Library/Homebrew/version
|
||||
64 /usr/local/Homebrew/Library/Homebrew/shims/mac/super
|
||||
64 /usr/local/Homebrew/Library/Homebrew/shims/mac
|
||||
24 /usr/local/Homebrew/Library/Homebrew/shims/super
|
||||
8 /usr/local/Homebrew/Library/Homebrew/shims/linux/super
|
||||
8 /usr/local/Homebrew/Library/Homebrew/shims/linux
|
||||
8 /usr/local/Homebrew/Library/Homebrew/shims/scm
|
||||
104 /usr/local/Homebrew/Library/Homebrew/shims
|
||||
8 /usr/local/Homebrew/Library/Homebrew/debrew
|
||||
56 /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.8
|
||||
24 /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.6
|
||||
|
||||
2
tests/fixtures/osx-10.14.6/ls-glob.json
vendored
2
tests/fixtures/osx-10.14.6/ls-glob.json
vendored
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
[{"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY", "parent": "."}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ", "parent": "."}, {"filename": "vmware-root_670-2722828838", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]
|
||||
[{"filename": "lstest", "parent": "."}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY", "parent": "."}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ", "parent": "."}, {"filename": "vmware-root_670-2722828838", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}]
|
||||
|
||||
2
tests/fixtures/ubuntu-18.04/ls-R.json
vendored
2
tests/fixtures/ubuntu-18.04/ls-R.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/ubuntu-18.04/ls-glob.json
vendored
2
tests/fixtures/ubuntu-18.04/ls-glob.json
vendored
File diff suppressed because one or more lines are too long
@@ -31,6 +31,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/last-w.out'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_4_last_w = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/last.out'), 'r', encoding='utf-8') as f:
|
||||
self.fedora32_last = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/last.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_last_json = json.loads(f.read())
|
||||
@@ -53,6 +56,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/last-w.json'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_4_last_w_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/last.json'), 'r', encoding='utf-8') as f:
|
||||
self.fedora32_last_json = json.loads(f.read())
|
||||
|
||||
def test_last_centos_7_7(self):
|
||||
"""
|
||||
Test plain 'last' on Centos 7.7
|
||||
@@ -95,6 +101,12 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.last.parse(self.ubuntu_18_4_last_w, quiet=True), self.ubuntu_18_4_last_w_json)
|
||||
|
||||
def test_last_fedora32(self):
|
||||
"""
|
||||
Test plain 'last' on Fedora32
|
||||
"""
|
||||
self.assertEqual(jc.parsers.last.parse(self.fedora32_last, quiet=True), self.fedora32_last_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -40,6 +40,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-aeep.out'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_4_netstat_sudo_aeep = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/netstat.out'), 'r', encoding='utf-8') as f:
|
||||
self.fedora32_netstat = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_netstat_json = json.loads(f.read())
|
||||
@@ -71,6 +74,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-aeep.json'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_4_netstat_sudo_aeep_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/netstat.json'), 'r', encoding='utf-8') as f:
|
||||
self.fedora32_netstat_json = json.loads(f.read())
|
||||
|
||||
def test_netstat_centos_7_7(self):
|
||||
"""
|
||||
Test 'netstat' on Centos 7.7
|
||||
@@ -131,6 +137,12 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_sudo_aeep, quiet=True), self.ubuntu_18_4_netstat_sudo_aeep_json)
|
||||
|
||||
def test_netstat_fedora32(self):
|
||||
"""
|
||||
Test 'netstat' on Fedora32
|
||||
"""
|
||||
self.assertEqual(jc.parsers.netstat.parse(self.fedora32_netstat, quiet=True), self.fedora32_netstat_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user