diff --git a/CHANGELOG b/CHANGELOG index 7ffd73a0..f1dc6486 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ jc changelog -20240301 v1.25.2 +20240315 v1.25.2 - Add `apt-cache-show` command parser - Add `apt-get-sqq` command parser - Add `ethtool` command parser @@ -13,7 +13,7 @@ jc changelog - Enhance `/proc/pid/stat` parser to support "Idle" state - Enhance `rpm_qi` and `pkg_index_deb` parsers to split list fields into arrays - Fix `iwconfig` parser to handle more special characters in the SSID name -- Documentation updates +- Documentation and doc build updates 20240212 v1.25.1 - Fix for crash when optional libraries are not installed (e.g. xmltodict) diff --git a/doc2md.py b/doc2md.py new file mode 100755 index 00000000..c81a1623 --- /dev/null +++ b/doc2md.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +""" +Convert parser doc string to markdown +""" +import sys +import importlib +from inspect import isfunction, signature, cleandoc +import yapf # type: ignore + +ignore_lib_functions = [ + 'cast', + 'wraps', + 'lru_cache', + 'namedtuple' +] + +mod_path = sys.argv[1] +mod_name = mod_path.split('.')[-1] +module = importlib.import_module(f'{mod_path}') + +######## HEADER ######## +header = f'''[Home](https://kellyjonbrazil.github.io/jc/) + + +# {mod_path} +''' + +summary = module.__doc__ or '' + +functions = [] +for attribute in dir(module): + if isfunction(getattr(module, attribute)) \ + and not getattr(module, attribute).__name__.startswith('_'): + + if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + if attribute == 'parse': + functions.append(attribute) + + else: + if not attribute in ignore_lib_functions: + functions.append(attribute) + +######## TABLE OF CONTENTS ######## +toc = f'## Table of Contents\n\n* [{mod_path}](#{mod_path})\n' +for api in functions: + toc = f'{toc} * [{api}](#{mod_path}.{api})\n' + +######## API DOCS ######## +api_docs = '' +for api in functions: + api_function = getattr(module, api) + + this_header = f'\n\n### {api}\n' + this_sig = str(signature(api_function)) + formatted_sig = yapf.yapf_api.FormatCode(f'def {api_function.__name__}{this_sig}:\n pass' ) + formatted_sig = formatted_sig[0].split(':\n pass')[0] + this_name_and_sig = f'{this_header}\n```python\n{formatted_sig}\n```' + + this_doc = cleandoc(api_function.__doc__) + api_docs = api_docs + this_name_and_sig + '\n\n' + this_doc + '\n\n' + +######## FOOTER ######## +footer = '' +if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + footer = '### Parser Information\n' + comp = ', '.join(module.info.compatible) + ver = module.info.version + author = module.info.author + author_email = module.info.author_email + slurpable = 'slurpable' in module.info.tags + footer = footer + f'Compatibility: {comp}\n\n' + footer = footer + f'Source: [`jc/parsers/{mod_name}.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/{mod_name}.py)\n\n' + if slurpable: + footer = footer + 'This parser can be used with the `--slurp` command-line option.\n\n' + footer = footer + f'Version {ver} by {author} ({author_email})' + +final_doc = '' +if 'jc.parsers.' in mod_path and not 'universal' in mod_path: + final_doc = header + '\n' + summary + '\n' + api_docs + footer +elif mod_path == 'jc': + final_doc = header + '\n' + summary +else: + final_doc = header + '\n' + toc + '\n' + summary + '\n\n' + api_docs + +print(final_doc) diff --git a/docgen.sh b/docgen.sh index a403c627..d5d876e1 100755 --- a/docgen.sh +++ b/docgen.sh @@ -1,107 +1,32 @@ #!/bin/bash -# Generate docs.md -# requires pydoc-markdown 4.6.1 - +# Generate markdown document files (*.md) +# Requires the yapf python library # use ./docgen all to generate all docs -readme_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - -toc_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "render_toc": true, - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - -parser_config=$(cat <<'EOF' -{ - "processors": [ - { - "type": "filter", - "expression": "not name == \"info\" and not name.startswith(\"_\") and default()" - }, - { - "type": "pydocmd" - } - ], - "renderer": { - "type": "markdown", - "header_level_by_type": { - "Module": 1, - "Class": 3, - "Method": 3, - "Function": 3, - "Variable": 3 - } - } -} -EOF -) - cd jc ( echo Building docs for: package - pydoc-markdown -m jc "${readme_config}" > ../docs/readme.md; echo "+++ package docs complete" + ../doc2md.py jc > ../docs/readme.md && echo "+++ package docs complete" || echo "*** PACKAGE DOCS FAILED ***" ) & ( echo Building docs for: lib - pydoc-markdown -m jc.lib "${toc_config}" > ../docs/lib.md; echo "+++ lib docs complete" + ../doc2md.py jc.lib > ../docs/lib.md && echo "+++ lib docs complete" || echo "*** LIB DOCS FAILED ***" ) & ( echo Building docs for: utils - pydoc-markdown -m jc.utils "${toc_config}" > ../docs/utils.md; echo "+++ utils docs complete" + ../doc2md.py jc.utils > ../docs/utils.md && echo "+++ utils docs complete" || echo "*** UTILS DOCS FAILED ***" ) & ( echo Building docs for: streaming - pydoc-markdown -m jc.streaming "${toc_config}" > ../docs/streaming.md; echo "+++ streaming docs complete" + ../doc2md.py jc.streaming > ../docs/streaming.md && echo "+++ streaming docs complete" || echo "*** STREAMING DOCS FAILED ***" ) & ( echo Building docs for: universal parser - pydoc-markdown -m jc.parsers.universal "${toc_config}" > ../docs/parsers/universal.md; echo "+++ universal parser docs complete" + ../doc2md.py jc.parsers.universal > ../docs/parsers/universal.md && echo "+++ universal parser docs complete" || echo "*** UNIVERSAL PARSER DOCS FAILED ***" ) & # a bit of inception here... jc is being used to help @@ -119,27 +44,8 @@ for parser in "${parsers[@]}"; do parser_name=$(jq -r '.name' <<< "$parser") { if [[ $1 == "all" ]] || ! git diff --quiet --exit-code HEAD~5 -- "parsers/${parser_name}.py"; then - compatible=$(jq -r '.compatible | join(", ")' <<< "$parser") - version=$(jq -r '.version' <<< "$parser") - author=$(jq -r '.author' <<< "$parser") - author_email=$(jq -r '.author_email' <<< "$parser") - echo "Building docs for: ${parser_name}" - echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md - pydoc-markdown -m jc.parsers."${parser_name}" "${parser_config}" >> ../docs/parsers/"${parser_name}".md - echo "### Parser Information" >> ../docs/parsers/"${parser_name}".md - echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - echo "Source: [\`jc/parsers/${parser_name}.py\`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/${parser_name}.py)" >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - - if $(jq -e '.tags | contains(["slurpable"])' <<< "$parser"); then - echo "This parser can be used with the \`--slurp\` command-line option." >> ../docs/parsers/"${parser_name}".md - echo >> ../docs/parsers/"${parser_name}".md - fi - - echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md - echo "+++ ${parser_name} docs complete" + ../doc2md.py jc.parsers."${parser_name}" > ../docs/parsers/"${parser_name}".md && echo "+++ ${parser_name} docs complete" || echo "*** ${parser_name} DOCS FAILED ***" fi } & done diff --git a/docs/lib.md b/docs/lib.md index 060a5c8b..309444df 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -1,29 +1,67 @@ -# Table of Contents - -* [jc.lib](#jc.lib) - * [get\_parser](#jc.lib.get_parser) - * [parse](#jc.lib.parse) - * [parser\_mod\_list](#jc.lib.parser_mod_list) - * [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list) - * [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list) - * [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list) - * [slurpable\_parser\_mod\_list](#jc.lib.slurpable_parser_mod_list) - * [parser\_info](#jc.lib.parser_info) - * [all\_parser\_info](#jc.lib.all_parser_info) - * [get\_help](#jc.lib.get_help) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.lib +## Table of Contents + +* [jc.lib](#jc.lib) + * [all_parser_info](#jc.lib.all_parser_info) + * [get_help](#jc.lib.get_help) + * [get_parser](#jc.lib.get_parser) + * [parse](#jc.lib.parse) + * [parser_info](#jc.lib.parser_info) + * [parser_mod_list](#jc.lib.parser_mod_list) + * [plugin_parser_mod_list](#jc.lib.plugin_parser_mod_list) + * [slurpable_parser_mod_list](#jc.lib.slurpable_parser_mod_list) + * [standard_parser_mod_list](#jc.lib.standard_parser_mod_list) + * [streaming_parser_mod_list](#jc.lib.streaming_parser_mod_list) + jc - JSON Convert lib module + + +### all_parser_info + +```python +def all_parser_info( + documentation: bool = False, + show_hidden: bool = False, + show_deprecated: bool = False) -> List[jc.jc_types.ParserInfoType] +``` + +Returns a list of dictionaries that includes metadata for all parser +modules. By default only non-hidden, non-deprecated parsers are +returned. + +Parameters: + + documentation: (boolean) include parser docstrings if True + show_hidden: (boolean) also show parsers marked as hidden + in their info metadata. + show_deprecated: (boolean) also show parsers marked as + deprecated in their info metadata. + + + +### get_help + +```python +def get_help(parser_mod_name: Union[str, module]) -> None +``` + +Show help screen for the selected parser. + +This function will accept **module_name**, **cli-name**, and +**--argument-name** variants of the module name string as well as a +parser module object. + -### get\_parser +### get_parser ```python -def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType +def get_parser(parser_mod_name: Union[str, module]) -> module ``` Return the parser module object and check that the module is a valid @@ -56,13 +94,13 @@ Raises: ```python def parse( - parser_mod_name: Union[str, ModuleType], + parser_mod_name: Union[str, module], data: Union[str, bytes, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: Optional[bool] = None, **kwargs -) -> Union[JSONDictType, List[JSONDictType], Iterator[JSONDictType]] +) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]] ``` Parse the data (string or bytes) using the supplied parser (string or @@ -152,73 +190,13 @@ Returns: Standard Parsers: Dictionary or List of Dictionaries Streaming Parsers: Generator Object containing Dictionaries - - -### parser\_mod\_list - -```python -def parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` - -Returns a list of all available parser module names. - - - -### plugin\_parser\_mod\_list - -```python -def plugin_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` - -Returns a list of plugin parser module names. This function is a -subset of `parser_mod_list()`. - - - -### standard\_parser\_mod\_list - -```python -def standard_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` - -Returns a list of standard parser module names. This function is a -subset of `parser_mod_list()` and does not contain any streaming -parsers. - - - -### streaming\_parser\_mod\_list - -```python -def streaming_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` - -Returns a list of streaming parser module names. This function is a -subset of `parser_mod_list()`. - - - -### slurpable\_parser\_mod\_list - -```python -def slurpable_parser_mod_list(show_hidden: bool = False, - show_deprecated: bool = False) -> List[str] -``` - -Returns a list of slurpable parser module names. This function is a -subset of `parser_mod_list()`. - -### parser\_info +### parser_info ```python -def parser_info(parser_mod_name: Union[str, ModuleType], - documentation: bool = False) -> ParserInfoType +def parser_info(parser_mod_name: Union[str, module], + documentation: bool = False) -> jc.jc_types.ParserInfoType ``` Returns a dictionary that includes the parser module metadata. @@ -233,39 +211,64 @@ Parameters: documentation: (boolean) include parser docstring if True - + -### all\_parser\_info +### parser_mod_list ```python -def all_parser_info(documentation: bool = False, - show_hidden: bool = False, - show_deprecated: bool = False) -> List[ParserInfoType] +def parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] ``` -Returns a list of dictionaries that includes metadata for all parser -modules. By default only non-hidden, non-deprecated parsers are -returned. +Returns a list of all available parser module names. -Parameters: + - documentation: (boolean) include parser docstrings if True - show_hidden: (boolean) also show parsers marked as hidden - in their info metadata. - show_deprecated: (boolean) also show parsers marked as - deprecated in their info metadata. - - - -### get\_help +### plugin_parser_mod_list ```python -def get_help(parser_mod_name: Union[str, ModuleType]) -> None +def plugin_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] ``` -Show help screen for the selected parser. +Returns a list of plugin parser module names. This function is a +subset of `parser_mod_list()`. + + + +### slurpable_parser_mod_list + +```python +def slurpable_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] +``` + +Returns a list of slurpable parser module names. This function is a +subset of `parser_mod_list()`. + + + +### standard_parser_mod_list + +```python +def standard_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] +``` + +Returns a list of standard parser module names. This function is a +subset of `parser_mod_list()` and does not contain any streaming +parsers. + + + +### streaming_parser_mod_list + +```python +def streaming_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] +``` + +Returns a list of streaming parser module names. This function is a +subset of `parser_mod_list()`. -This function will accept **module_name**, **cli-name**, and -**--argument-name** variants of the module name string as well as a -parser module object. diff --git a/docs/parsers/airport_s.md b/docs/parsers/airport_s.md index 3874ff82..80b239ce 100644 --- a/docs/parsers/airport_s.md +++ b/docs/parsers/airport_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.airport\_s +# jc.parsers.airport_s jc - JSON Convert `airport -s` command output parser diff --git a/docs/parsers/apt_cache_show.md b/docs/parsers/apt_cache_show.md index 7f3b805d..8cd4db3c 100644 --- a/docs/parsers/apt_cache_show.md +++ b/docs/parsers/apt_cache_show.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.apt\_cache\_show +# jc.parsers.apt_cache_show jc - JSON Convert `apt-cache show` command parser @@ -157,7 +157,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/apt_get_sqq.md b/docs/parsers/apt_get_sqq.md index 8c57918c..3d9939f2 100644 --- a/docs/parsers/apt_get_sqq.md +++ b/docs/parsers/apt_get_sqq.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.apt\_get\_sqq +# jc.parsers.apt_get_sqq jc - JSON Convert `apt-get -sqq` command output parser @@ -28,7 +28,7 @@ Schema: "package": string, "broken": string/null, "proposed_pkg_ver": string, - "existing_src": string/null, + "existing_pkg_ver": string/null, "architecture": string } ] @@ -42,7 +42,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -50,7 +50,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -58,7 +58,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -66,7 +66,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -74,7 +74,7 @@ Examples: "package": "base-files", "broken": "10.3+deb10u4", "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -82,7 +82,7 @@ Examples: "package": "base-files", "broken": null, "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -90,7 +90,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -98,7 +98,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" } ] @@ -110,7 +110,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -118,7 +118,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -126,7 +126,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -134,7 +134,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -142,7 +142,7 @@ Examples: "package": "base-files", "broken": "10.3+deb10u4", "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -150,7 +150,7 @@ Examples: "package": "base-files", "broken": null, "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -158,7 +158,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -166,7 +166,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" } ] @@ -178,7 +178,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/asciitable_m.md b/docs/parsers/asciitable_m.md index 97777890..8e6a4acc 100644 --- a/docs/parsers/asciitable_m.md +++ b/docs/parsers/asciitable_m.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.asciitable\_m +# jc.parsers.asciitable_m jc - JSON Convert `asciitable-m` parser diff --git a/docs/parsers/bluetoothctl.md b/docs/parsers/bluetoothctl.md index eccc50d3..1474b0bd 100644 --- a/docs/parsers/bluetoothctl.md +++ b/docs/parsers/bluetoothctl.md @@ -112,7 +112,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/cbt.md b/docs/parsers/cbt.md index 37563b01..a8f753e1 100644 --- a/docs/parsers/cbt.md +++ b/docs/parsers/cbt.md @@ -104,7 +104,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/cef_s.md b/docs/parsers/cef_s.md index 17a085b3..4e5c5dcd 100644 --- a/docs/parsers/cef_s.md +++ b/docs/parsers/cef_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.cef\_s +# jc.parsers.cef_s jc - JSON Convert CEF string output streaming parser @@ -95,7 +95,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/certbot.md b/docs/parsers/certbot.md index 6e5591f2..5ccf6825 100644 --- a/docs/parsers/certbot.md +++ b/docs/parsers/certbot.md @@ -140,7 +140,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/clf.md b/docs/parsers/clf.md index a0ce543d..4f65bd1b 100644 --- a/docs/parsers/clf.md +++ b/docs/parsers/clf.md @@ -178,7 +178,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/clf_s.md b/docs/parsers/clf_s.md index 4e672728..f7c9f2e2 100644 --- a/docs/parsers/clf_s.md +++ b/docs/parsers/clf_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.clf\_s +# jc.parsers.clf_s jc - JSON Convert Common Log Format file streaming parser @@ -88,11 +88,12 @@ Examples: ### parse ```python -@add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> StreamingOutputType +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Iterator[Union[Dict[str, Any], Tuple[BaseException, str]]] ``` Main text parsing generator function. Returns an iterable object. diff --git a/docs/parsers/crontab_u.md b/docs/parsers/crontab_u.md index a4a0bb7d..ec69331a 100644 --- a/docs/parsers/crontab_u.md +++ b/docs/parsers/crontab_u.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.crontab\_u +# jc.parsers.crontab_u jc - JSON Convert `crontab -l` command output and crontab file parser diff --git a/docs/parsers/csv.md b/docs/parsers/csv.md index 6833ecef..00b16bdc 100644 --- a/docs/parsers/csv.md +++ b/docs/parsers/csv.md @@ -84,7 +84,7 @@ Examples: ```python def parse(data: Union[str, bytes], raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/csv_s.md b/docs/parsers/csv_s.md index fca783da..269fcd45 100644 --- a/docs/parsers/csv_s.md +++ b/docs/parsers/csv_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.csv\_s +# jc.parsers.csv_s jc - JSON Convert `csv` file streaming parser @@ -64,7 +64,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/curl_head.md b/docs/parsers/curl_head.md index a9c70758..cb664270 100644 --- a/docs/parsers/curl_head.md +++ b/docs/parsers/curl_head.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.curl\_head +# jc.parsers.curl_head jc - JSON Convert `curl --head` command output parser @@ -286,7 +286,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/datetime_iso.md b/docs/parsers/datetime_iso.md index c8a8651a..164bbf47 100644 --- a/docs/parsers/datetime_iso.md +++ b/docs/parsers/datetime_iso.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.datetime\_iso +# jc.parsers.datetime_iso jc - JSON Convert ISO 8601 Datetime string parser diff --git a/docs/parsers/debconf_show.md b/docs/parsers/debconf_show.md index 0b24154e..834151b1 100644 --- a/docs/parsers/debconf_show.md +++ b/docs/parsers/debconf_show.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.debconf\_show +# jc.parsers.debconf_show jc - JSON Convert `debconf-show` command output parser @@ -84,7 +84,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/dpkg_l.md b/docs/parsers/dpkg_l.md index 43bb89ad..f71ed268 100644 --- a/docs/parsers/dpkg_l.md +++ b/docs/parsers/dpkg_l.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.dpkg\_l +# jc.parsers.dpkg_l jc - JSON Convert `dpkg -l` command output parser diff --git a/docs/parsers/efibootmgr.md b/docs/parsers/efibootmgr.md index e118efc2..90a8f157 100644 --- a/docs/parsers/efibootmgr.md +++ b/docs/parsers/efibootmgr.md @@ -81,7 +81,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/email_address.md b/docs/parsers/email_address.md index ecb8765d..03850412 100644 --- a/docs/parsers/email_address.md +++ b/docs/parsers/email_address.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.email\_address +# jc.parsers.email_address jc - JSON Convert Email Address string parser diff --git a/docs/parsers/ethtool.md b/docs/parsers/ethtool.md index 711f95b5..d4104714 100644 --- a/docs/parsers/ethtool.md +++ b/docs/parsers/ethtool.md @@ -171,7 +171,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/findmnt.md b/docs/parsers/findmnt.md index 449babf0..9bc413ae 100644 --- a/docs/parsers/findmnt.md +++ b/docs/parsers/findmnt.md @@ -96,7 +96,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/git_log.md b/docs/parsers/git_log.md index 69444e32..d93a6f11 100644 --- a/docs/parsers/git_log.md +++ b/docs/parsers/git_log.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_log +# jc.parsers.git_log jc - JSON Convert `git log` command output parser diff --git a/docs/parsers/git_log_s.md b/docs/parsers/git_log_s.md index 4d501881..3dfb08e9 100644 --- a/docs/parsers/git_log_s.md +++ b/docs/parsers/git_log_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_log\_s +# jc.parsers.git_log_s jc - JSON Convert `git log` command output streaming parser @@ -82,7 +82,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/git_ls_remote.md b/docs/parsers/git_ls_remote.md index ef09b41f..ae5015a9 100644 --- a/docs/parsers/git_ls_remote.md +++ b/docs/parsers/git_ls_remote.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.git\_ls\_remote +# jc.parsers.git_ls_remote jc - JSON Convert `git ls-remote` command output parser @@ -71,7 +71,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> Union[JSONDictType, List[JSONDictType]] + quiet: bool = False) -> Union[Dict[str, Any], List[Dict[str, Any]]] ``` Main text parsing function diff --git a/docs/parsers/http_headers.md b/docs/parsers/http_headers.md index f3d74a7c..b7330ef7 100644 --- a/docs/parsers/http_headers.md +++ b/docs/parsers/http_headers.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.http\_headers +# jc.parsers.http_headers jc - JSON Convert HTTP headers parser @@ -313,7 +313,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md index 274d4c28..e9b0ddc9 100644 --- a/docs/parsers/ifconfig.md +++ b/docs/parsers/ifconfig.md @@ -222,7 +222,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ini_dup.md b/docs/parsers/ini_dup.md index a4a74d83..078c7a36 100644 --- a/docs/parsers/ini_dup.md +++ b/docs/parsers/ini_dup.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ini\_dup +# jc.parsers.ini_dup jc - JSON Convert INI with duplicate key file parser diff --git a/docs/parsers/iostat_s.md b/docs/parsers/iostat_s.md index 4bb69928..e2e98081 100644 --- a/docs/parsers/iostat_s.md +++ b/docs/parsers/iostat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.iostat\_s +# jc.parsers.iostat_s jc - JSON Convert `iostat` command output streaming parser @@ -108,7 +108,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/ip_address.md b/docs/parsers/ip_address.md index 7b1fa416..efdcc21f 100644 --- a/docs/parsers/ip_address.md +++ b/docs/parsers/ip_address.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ip\_address +# jc.parsers.ip_address jc - JSON Convert IP Address string parser diff --git a/docs/parsers/ip_route.md b/docs/parsers/ip_route.md index e5efb990..24975d91 100644 --- a/docs/parsers/ip_route.md +++ b/docs/parsers/ip_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ip\_route +# jc.parsers.ip_route jc - JSON Convert `ip route` command output parser diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index de2470b9..9fc82cd9 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.iw\_scan +# jc.parsers.iw_scan jc - JSON Convert `iw dev scan` command output parser diff --git a/docs/parsers/iwconfig.md b/docs/parsers/iwconfig.md index e5c5682b..e02e20bf 100644 --- a/docs/parsers/iwconfig.md +++ b/docs/parsers/iwconfig.md @@ -90,7 +90,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/jar_manifest.md b/docs/parsers/jar_manifest.md index 080ff674..eeb8275b 100644 --- a/docs/parsers/jar_manifest.md +++ b/docs/parsers/jar_manifest.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.jar\_manifest +# jc.parsers.jar_manifest jc - JSON Convert Java `MANIFEST.MF` file parser diff --git a/docs/parsers/kv_dup.md b/docs/parsers/kv_dup.md index dc19352c..f62f0ed9 100644 --- a/docs/parsers/kv_dup.md +++ b/docs/parsers/kv_dup.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.kv\_dup +# jc.parsers.kv_dup jc - JSON Convert `Key/Value` with duplicate key file and string parser diff --git a/docs/parsers/ls_s.md b/docs/parsers/ls_s.md index c49d5a13..a6e73af3 100644 --- a/docs/parsers/ls_s.md +++ b/docs/parsers/ls_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ls\_s +# jc.parsers.ls_s jc - JSON Convert `ls` and `vdir` command output streaming parser @@ -77,7 +77,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/lsattr.md b/docs/parsers/lsattr.md index 1c5cf141..768f6bba 100644 --- a/docs/parsers/lsattr.md +++ b/docs/parsers/lsattr.md @@ -69,7 +69,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/lsb_release.md b/docs/parsers/lsb_release.md index 3bcdb436..1dda22ce 100644 --- a/docs/parsers/lsb_release.md +++ b/docs/parsers/lsb_release.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.lsb\_release +# jc.parsers.lsb_release jc - JSON Convert `lsb_release` command parser @@ -40,7 +40,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/lspci.md b/docs/parsers/lspci.md index 95a05806..28b3dbcc 100644 --- a/docs/parsers/lspci.md +++ b/docs/parsers/lspci.md @@ -127,7 +127,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/mpstat_s.md b/docs/parsers/mpstat_s.md index 310f5236..d92e61aa 100644 --- a/docs/parsers/mpstat_s.md +++ b/docs/parsers/mpstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.mpstat\_s +# jc.parsers.mpstat_s jc - JSON Convert `mpstat` command output streaming parser @@ -100,7 +100,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/needrestart.md b/docs/parsers/needrestart.md new file mode 100644 index 00000000..e38596f0 --- /dev/null +++ b/docs/parsers/needrestart.md @@ -0,0 +1,101 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.needrestart + +jc - JSON Convert `needrestart -b` command output parser + +Usage (cli): + + $ needrestart -b | jc --needrestart + +or + + $ jc needrestart -b + +Usage (module): + + import jc + result = jc.parse('needrestart', needrestart_command_output) + +Schema: + + { + "version": string, + "running_kernel_version": string, + "expected_kernel_version": string, + "kernel_status": integer, + "container": string, + "session": [ + string + ], + "service": [ + string + ], + "pid": [ + string + ] + } + +Examples: + + $ needrestart -b | jc --needrestart -p + { + "version": "2.1", + "running_kernel_version": "3.19.3-tl1+", + "expected_kernel_version": "3.19.3-tl1+", + "kernel_status": 1, + "container": "LXC web1", + "session": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "service": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } + + $ needrestart -b | jc --needrestart -p -r + { + "needrestart_ver": "2.1", + "needrestart_kcur": "3.19.3-tl1+", + "needrestart_kexp": "3.19.3-tl1+", + "needrestart_ksta": "1", + "needrestart_cont": "LXC web1", + "needrestart_sess": [ + "metabase @ user manager service", + "root @ session #28017" + ], + "needrestart_svc": [ + "systemd-journald.service", + "systemd-machined.service" + ] + } + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] +``` + +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: + + Dictionary. Raw or processed structured data. + +### Parser Information +Compatibility: linux + +Source: [`jc/parsers/needrestart.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/needrestart.py) + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/nsd_control.md b/docs/parsers/nsd_control.md index 7231413f..f236f8ae 100644 --- a/docs/parsers/nsd_control.md +++ b/docs/parsers/nsd_control.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.nsd\_control +# jc.parsers.nsd_control jc - JSON Convert `nsd-control` command output parser diff --git a/docs/parsers/openvpn.md b/docs/parsers/openvpn.md index 9e362d87..6395ff8b 100644 --- a/docs/parsers/openvpn.md +++ b/docs/parsers/openvpn.md @@ -157,7 +157,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/os_prober.md b/docs/parsers/os_prober.md index 5bbe08c0..94fb00d6 100644 --- a/docs/parsers/os_prober.md +++ b/docs/parsers/os_prober.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.os\_prober +# jc.parsers.os_prober jc - JSON Convert `os-prober` command output parser @@ -45,7 +45,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/os_release.md b/docs/parsers/os_release.md index f6e4d9e7..cbf9a4be 100644 --- a/docs/parsers/os_release.md +++ b/docs/parsers/os_release.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.os\_release +# jc.parsers.os_release jc - JSON Convert `/etc/os-release` file parser @@ -65,7 +65,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/path_list.md b/docs/parsers/path_list.md index bf927d3d..76b2bbaa 100644 --- a/docs/parsers/path_list.md +++ b/docs/parsers/path_list.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.path\_list +# jc.parsers.path_list jc - JSON Convert POSIX path list string parser diff --git a/docs/parsers/pci_ids.md b/docs/parsers/pci_ids.md index 8027887a..ad728d4e 100644 --- a/docs/parsers/pci_ids.md +++ b/docs/parsers/pci_ids.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pci\_ids +# jc.parsers.pci_ids jc - JSON Convert `pci.ids` file parser @@ -78,7 +78,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/pgpass.md b/docs/parsers/pgpass.md index 62c96a24..d7576328 100644 --- a/docs/parsers/pgpass.md +++ b/docs/parsers/pgpass.md @@ -54,7 +54,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/pidstat_s.md b/docs/parsers/pidstat_s.md index c834e3f4..10a46efb 100644 --- a/docs/parsers/pidstat_s.md +++ b/docs/parsers/pidstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pidstat\_s +# jc.parsers.pidstat_s jc - JSON Convert `pidstat -H` command output streaming parser @@ -86,7 +86,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/ping_s.md b/docs/parsers/ping_s.md index 3b371a6f..813dee9c 100644 --- a/docs/parsers/ping_s.md +++ b/docs/parsers/ping_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ping\_s +# jc.parsers.ping_s jc - JSON Convert `ping` command output streaming parser @@ -86,7 +86,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index 75f30abc..000dbfd3 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pip\_list +# jc.parsers.pip_list jc - JSON Convert `pip-list` command output parser diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index a0dd6da2..4900f9a0 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pip\_show +# jc.parsers.pip_show jc - JSON Convert `pip-show` command output parser diff --git a/docs/parsers/pkg_index_apk.md b/docs/parsers/pkg_index_apk.md index 0dcd935e..eed1ebc3 100644 --- a/docs/parsers/pkg_index_apk.md +++ b/docs/parsers/pkg_index_apk.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pkg\_index\_apk +# jc.parsers.pkg_index_apk jc - JSON Convert Alpine Linux Package Index files diff --git a/docs/parsers/pkg_index_deb.md b/docs/parsers/pkg_index_deb.md index 2ff426cc..fc623a56 100644 --- a/docs/parsers/pkg_index_deb.md +++ b/docs/parsers/pkg_index_deb.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.pkg\_index\_deb +# jc.parsers.pkg_index_deb jc - JSON Convert Debian Package Index file parser @@ -132,7 +132,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/proc_buddyinfo.md b/docs/parsers/proc_buddyinfo.md index b3e11944..6a0ac4b9 100644 --- a/docs/parsers/proc_buddyinfo.md +++ b/docs/parsers/proc_buddyinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_buddyinfo +# jc.parsers.proc_buddyinfo jc - JSON Convert `/proc/buddyinfo` file parser diff --git a/docs/parsers/proc_cmdline.md b/docs/parsers/proc_cmdline.md index d7c4c45c..6c60f271 100644 --- a/docs/parsers/proc_cmdline.md +++ b/docs/parsers/proc_cmdline.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_cmdline +# jc.parsers.proc_cmdline jc - JSON Convert `/proc/cmdline` file parser @@ -71,7 +71,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/proc_consoles.md b/docs/parsers/proc_consoles.md index 7f9cd7e5..7ed0bde1 100644 --- a/docs/parsers/proc_consoles.md +++ b/docs/parsers/proc_consoles.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_consoles +# jc.parsers.proc_consoles jc - JSON Convert `/proc/consoles` file parser diff --git a/docs/parsers/proc_cpuinfo.md b/docs/parsers/proc_cpuinfo.md index 1f72a814..fae7ea58 100644 --- a/docs/parsers/proc_cpuinfo.md +++ b/docs/parsers/proc_cpuinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_cpuinfo +# jc.parsers.proc_cpuinfo jc - JSON Convert `/proc/cpuinfo` file parser diff --git a/docs/parsers/proc_crypto.md b/docs/parsers/proc_crypto.md index b510720f..eb1e279a 100644 --- a/docs/parsers/proc_crypto.md +++ b/docs/parsers/proc_crypto.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_crypto +# jc.parsers.proc_crypto jc - JSON Convert `/proc/crypto` file parser diff --git a/docs/parsers/proc_devices.md b/docs/parsers/proc_devices.md index f8d3d483..fe29248c 100644 --- a/docs/parsers/proc_devices.md +++ b/docs/parsers/proc_devices.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_devices +# jc.parsers.proc_devices jc - JSON Convert `/proc/devices` file parser diff --git a/docs/parsers/proc_diskstats.md b/docs/parsers/proc_diskstats.md index c118922a..7681c246 100644 --- a/docs/parsers/proc_diskstats.md +++ b/docs/parsers/proc_diskstats.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_diskstats +# jc.parsers.proc_diskstats jc - JSON Convert `/proc/diskstats` file parser diff --git a/docs/parsers/proc_driver_rtc.md b/docs/parsers/proc_driver_rtc.md index 40591627..bfe71885 100644 --- a/docs/parsers/proc_driver_rtc.md +++ b/docs/parsers/proc_driver_rtc.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_driver\_rtc +# jc.parsers.proc_driver_rtc jc - JSON Convert `/proc/driver/rtc` file parser diff --git a/docs/parsers/proc_filesystems.md b/docs/parsers/proc_filesystems.md index 7947efde..7eec09db 100644 --- a/docs/parsers/proc_filesystems.md +++ b/docs/parsers/proc_filesystems.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_filesystems +# jc.parsers.proc_filesystems jc - JSON Convert `/proc/filesystems` file parser diff --git a/docs/parsers/proc_interrupts.md b/docs/parsers/proc_interrupts.md index dc6fbf35..ff4b4c3f 100644 --- a/docs/parsers/proc_interrupts.md +++ b/docs/parsers/proc_interrupts.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_interrupts +# jc.parsers.proc_interrupts jc - JSON Convert `/proc/interrupts` file parser diff --git a/docs/parsers/proc_iomem.md b/docs/parsers/proc_iomem.md index 848c7f47..7aeae5fc 100644 --- a/docs/parsers/proc_iomem.md +++ b/docs/parsers/proc_iomem.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_iomem +# jc.parsers.proc_iomem jc - JSON Convert `/proc/iomem` file parser diff --git a/docs/parsers/proc_ioports.md b/docs/parsers/proc_ioports.md index a3c040ca..1077ac41 100644 --- a/docs/parsers/proc_ioports.md +++ b/docs/parsers/proc_ioports.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_ioports +# jc.parsers.proc_ioports jc - JSON Convert `/proc/ioports` file parser diff --git a/docs/parsers/proc_loadavg.md b/docs/parsers/proc_loadavg.md index 5562daf9..32468303 100644 --- a/docs/parsers/proc_loadavg.md +++ b/docs/parsers/proc_loadavg.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_loadavg +# jc.parsers.proc_loadavg jc - JSON Convert `/proc/loadavg` file parser diff --git a/docs/parsers/proc_locks.md b/docs/parsers/proc_locks.md index 43620338..c1826dc0 100644 --- a/docs/parsers/proc_locks.md +++ b/docs/parsers/proc_locks.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_locks +# jc.parsers.proc_locks jc - JSON Convert `/proc/locks` file parser diff --git a/docs/parsers/proc_meminfo.md b/docs/parsers/proc_meminfo.md index e70e6af2..a4383c84 100644 --- a/docs/parsers/proc_meminfo.md +++ b/docs/parsers/proc_meminfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_meminfo +# jc.parsers.proc_meminfo jc - JSON Convert `/proc/meminfo` file parser diff --git a/docs/parsers/proc_modules.md b/docs/parsers/proc_modules.md index 2e7c3fc0..119535c1 100644 --- a/docs/parsers/proc_modules.md +++ b/docs/parsers/proc_modules.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_modules +# jc.parsers.proc_modules jc - JSON Convert `/proc/modules` file parser diff --git a/docs/parsers/proc_mtrr.md b/docs/parsers/proc_mtrr.md index 85575c62..ec286ca4 100644 --- a/docs/parsers/proc_mtrr.md +++ b/docs/parsers/proc_mtrr.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_mtrr +# jc.parsers.proc_mtrr jc - JSON Convert `/proc/mtrr` file parser diff --git a/docs/parsers/proc_net_arp.md b/docs/parsers/proc_net_arp.md index e772b26e..f773db23 100644 --- a/docs/parsers/proc_net_arp.md +++ b/docs/parsers/proc_net_arp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_arp +# jc.parsers.proc_net_arp jc - JSON Convert `/proc/net/arp` file parser diff --git a/docs/parsers/proc_net_dev.md b/docs/parsers/proc_net_dev.md index 03fdabeb..021c1dfe 100644 --- a/docs/parsers/proc_net_dev.md +++ b/docs/parsers/proc_net_dev.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_dev +# jc.parsers.proc_net_dev jc - JSON Convert `/proc/net/dev` file parser diff --git a/docs/parsers/proc_net_dev_mcast.md b/docs/parsers/proc_net_dev_mcast.md index 32c64984..66b9ef57 100644 --- a/docs/parsers/proc_net_dev_mcast.md +++ b/docs/parsers/proc_net_dev_mcast.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_dev\_mcast +# jc.parsers.proc_net_dev_mcast jc - JSON Convert `/proc/net/dev_mcast` file parser diff --git a/docs/parsers/proc_net_if_inet6.md b/docs/parsers/proc_net_if_inet6.md index 75abcfce..894ecd7a 100644 --- a/docs/parsers/proc_net_if_inet6.md +++ b/docs/parsers/proc_net_if_inet6.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_if\_inet6 +# jc.parsers.proc_net_if_inet6 jc - JSON Convert `/proc/net/if_inet6` file parser diff --git a/docs/parsers/proc_net_igmp.md b/docs/parsers/proc_net_igmp.md index 26af814a..c7a1b989 100644 --- a/docs/parsers/proc_net_igmp.md +++ b/docs/parsers/proc_net_igmp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_igmp +# jc.parsers.proc_net_igmp jc - JSON Convert `/proc/net/igmp` file parser diff --git a/docs/parsers/proc_net_igmp6.md b/docs/parsers/proc_net_igmp6.md index 21ff8be2..dfcf20ff 100644 --- a/docs/parsers/proc_net_igmp6.md +++ b/docs/parsers/proc_net_igmp6.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_igmp6 +# jc.parsers.proc_net_igmp6 jc - JSON Convert `/proc/net/igmp6` file parser diff --git a/docs/parsers/proc_net_ipv6_route.md b/docs/parsers/proc_net_ipv6_route.md index 8b3f6e99..4549c5ea 100644 --- a/docs/parsers/proc_net_ipv6_route.md +++ b/docs/parsers/proc_net_ipv6_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_ipv6\_route +# jc.parsers.proc_net_ipv6_route jc - JSON Convert `/proc/net/ipv6_route` file parser diff --git a/docs/parsers/proc_net_netlink.md b/docs/parsers/proc_net_netlink.md index dcf432ff..fda000bf 100644 --- a/docs/parsers/proc_net_netlink.md +++ b/docs/parsers/proc_net_netlink.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_netlink +# jc.parsers.proc_net_netlink jc - JSON Convert `/proc/net/netlink` file parser diff --git a/docs/parsers/proc_net_netstat.md b/docs/parsers/proc_net_netstat.md index 6d3f6d0a..51be58ac 100644 --- a/docs/parsers/proc_net_netstat.md +++ b/docs/parsers/proc_net_netstat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_netstat +# jc.parsers.proc_net_netstat jc - JSON Convert `/proc/net/netstat` file parser diff --git a/docs/parsers/proc_net_packet.md b/docs/parsers/proc_net_packet.md index 01a716c9..e6ff1fe1 100644 --- a/docs/parsers/proc_net_packet.md +++ b/docs/parsers/proc_net_packet.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_packet +# jc.parsers.proc_net_packet jc - JSON Convert `/proc/net/packet` file parser diff --git a/docs/parsers/proc_net_protocols.md b/docs/parsers/proc_net_protocols.md index def15550..ab980b42 100644 --- a/docs/parsers/proc_net_protocols.md +++ b/docs/parsers/proc_net_protocols.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_protocols +# jc.parsers.proc_net_protocols jc - JSON Convert `/proc/net/protocols` file parser diff --git a/docs/parsers/proc_net_route.md b/docs/parsers/proc_net_route.md index ec37c1bc..5c086574 100644 --- a/docs/parsers/proc_net_route.md +++ b/docs/parsers/proc_net_route.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_route +# jc.parsers.proc_net_route jc - JSON Convert `/proc/net/route` file parser diff --git a/docs/parsers/proc_net_tcp.md b/docs/parsers/proc_net_tcp.md index ec34df35..57656f5b 100644 --- a/docs/parsers/proc_net_tcp.md +++ b/docs/parsers/proc_net_tcp.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_tcp +# jc.parsers.proc_net_tcp jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser diff --git a/docs/parsers/proc_net_unix.md b/docs/parsers/proc_net_unix.md index 89932f98..372712e8 100644 --- a/docs/parsers/proc_net_unix.md +++ b/docs/parsers/proc_net_unix.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_net\_unix +# jc.parsers.proc_net_unix jc - JSON Convert `/proc/net/unix` file parser diff --git a/docs/parsers/proc_pagetypeinfo.md b/docs/parsers/proc_pagetypeinfo.md index 2320e688..1451ae02 100644 --- a/docs/parsers/proc_pagetypeinfo.md +++ b/docs/parsers/proc_pagetypeinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pagetypeinfo +# jc.parsers.proc_pagetypeinfo jc - JSON Convert `/proc/pagetypeinfo` file parser diff --git a/docs/parsers/proc_partitions.md b/docs/parsers/proc_partitions.md index b4a9cb8e..e00e1f77 100644 --- a/docs/parsers/proc_partitions.md +++ b/docs/parsers/proc_partitions.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_partitions +# jc.parsers.proc_partitions jc - JSON Convert `/proc/partitions` file parser diff --git a/docs/parsers/proc_pid_fdinfo.md b/docs/parsers/proc_pid_fdinfo.md index 891b9cbc..e725b0e9 100644 --- a/docs/parsers/proc_pid_fdinfo.md +++ b/docs/parsers/proc_pid_fdinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_fdinfo +# jc.parsers.proc_pid_fdinfo jc - JSON Convert `/proc//fdinfo/` file parser diff --git a/docs/parsers/proc_pid_io.md b/docs/parsers/proc_pid_io.md index c4ebed77..f2761302 100644 --- a/docs/parsers/proc_pid_io.md +++ b/docs/parsers/proc_pid_io.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_io +# jc.parsers.proc_pid_io jc - JSON Convert `/proc//io` file parser diff --git a/docs/parsers/proc_pid_maps.md b/docs/parsers/proc_pid_maps.md index e3e72c06..0705d16d 100644 --- a/docs/parsers/proc_pid_maps.md +++ b/docs/parsers/proc_pid_maps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_maps +# jc.parsers.proc_pid_maps jc - JSON Convert `/proc//maps` file parser diff --git a/docs/parsers/proc_pid_mountinfo.md b/docs/parsers/proc_pid_mountinfo.md index ac839702..bfd60129 100644 --- a/docs/parsers/proc_pid_mountinfo.md +++ b/docs/parsers/proc_pid_mountinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_mountinfo +# jc.parsers.proc_pid_mountinfo jc - JSON Convert `/proc//mountinfo` file parser diff --git a/docs/parsers/proc_pid_numa_maps.md b/docs/parsers/proc_pid_numa_maps.md index 63304c17..d46b9d0d 100644 --- a/docs/parsers/proc_pid_numa_maps.md +++ b/docs/parsers/proc_pid_numa_maps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_numa\_maps +# jc.parsers.proc_pid_numa_maps jc - JSON Convert `/proc//numa_maps` file parser diff --git a/docs/parsers/proc_pid_smaps.md b/docs/parsers/proc_pid_smaps.md index a33aaae1..c3a778cc 100644 --- a/docs/parsers/proc_pid_smaps.md +++ b/docs/parsers/proc_pid_smaps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_smaps +# jc.parsers.proc_pid_smaps jc - JSON Convert `/proc//smaps` file parser diff --git a/docs/parsers/proc_pid_stat.md b/docs/parsers/proc_pid_stat.md index 8ce9a10d..fa0901eb 100644 --- a/docs/parsers/proc_pid_stat.md +++ b/docs/parsers/proc_pid_stat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_stat +# jc.parsers.proc_pid_stat jc - JSON Convert `/proc//stat` file parser diff --git a/docs/parsers/proc_pid_statm.md b/docs/parsers/proc_pid_statm.md index 64536f8e..1bdfc1cd 100644 --- a/docs/parsers/proc_pid_statm.md +++ b/docs/parsers/proc_pid_statm.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_statm +# jc.parsers.proc_pid_statm jc - JSON Convert `/proc//statm` file parser diff --git a/docs/parsers/proc_pid_status.md b/docs/parsers/proc_pid_status.md index 2a9b95b3..1332989e 100644 --- a/docs/parsers/proc_pid_status.md +++ b/docs/parsers/proc_pid_status.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_pid\_status +# jc.parsers.proc_pid_status jc - JSON Convert `/proc//status` file parser diff --git a/docs/parsers/proc_slabinfo.md b/docs/parsers/proc_slabinfo.md index 938dafc5..6758d6b8 100644 --- a/docs/parsers/proc_slabinfo.md +++ b/docs/parsers/proc_slabinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_slabinfo +# jc.parsers.proc_slabinfo jc - JSON Convert `/proc/slabinfo` file parser diff --git a/docs/parsers/proc_softirqs.md b/docs/parsers/proc_softirqs.md index 518223fa..d1d01194 100644 --- a/docs/parsers/proc_softirqs.md +++ b/docs/parsers/proc_softirqs.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_softirqs +# jc.parsers.proc_softirqs jc - JSON Convert `/proc/softirqs` file parser diff --git a/docs/parsers/proc_stat.md b/docs/parsers/proc_stat.md index ee671085..ae42916a 100644 --- a/docs/parsers/proc_stat.md +++ b/docs/parsers/proc_stat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_stat +# jc.parsers.proc_stat jc - JSON Convert `/proc/stat` file parser diff --git a/docs/parsers/proc_swaps.md b/docs/parsers/proc_swaps.md index 59b47872..a9317df4 100644 --- a/docs/parsers/proc_swaps.md +++ b/docs/parsers/proc_swaps.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_swaps +# jc.parsers.proc_swaps jc - JSON Convert `/proc/swaps` file parser diff --git a/docs/parsers/proc_uptime.md b/docs/parsers/proc_uptime.md index 6b807abe..48a8f52a 100644 --- a/docs/parsers/proc_uptime.md +++ b/docs/parsers/proc_uptime.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_uptime +# jc.parsers.proc_uptime jc - JSON Convert `/proc/uptime` file parser diff --git a/docs/parsers/proc_version.md b/docs/parsers/proc_version.md index 1c05fb4f..fe060d7e 100644 --- a/docs/parsers/proc_version.md +++ b/docs/parsers/proc_version.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_version +# jc.parsers.proc_version jc - JSON Convert `/proc/version` file parser diff --git a/docs/parsers/proc_vmallocinfo.md b/docs/parsers/proc_vmallocinfo.md index 81ededbb..f1f18b01 100644 --- a/docs/parsers/proc_vmallocinfo.md +++ b/docs/parsers/proc_vmallocinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_vmallocinfo +# jc.parsers.proc_vmallocinfo jc - JSON Convert `/proc/vmallocinfo` file parser diff --git a/docs/parsers/proc_vmstat.md b/docs/parsers/proc_vmstat.md index b176dc2c..38892421 100644 --- a/docs/parsers/proc_vmstat.md +++ b/docs/parsers/proc_vmstat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_vmstat +# jc.parsers.proc_vmstat jc - JSON Convert `/proc/vmstat` file parser diff --git a/docs/parsers/proc_zoneinfo.md b/docs/parsers/proc_zoneinfo.md index 16cfa908..b337260f 100644 --- a/docs/parsers/proc_zoneinfo.md +++ b/docs/parsers/proc_zoneinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.proc\_zoneinfo +# jc.parsers.proc_zoneinfo jc - JSON Convert `/proc/zoneinfo` file parser diff --git a/docs/parsers/resolve_conf.md b/docs/parsers/resolve_conf.md index 9a21a1d0..29eed293 100644 --- a/docs/parsers/resolve_conf.md +++ b/docs/parsers/resolve_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.resolve\_conf +# jc.parsers.resolve_conf jc - JSON Convert `/etc/resolve.conf` file parser @@ -62,7 +62,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index 6c36d23a..8df44a46 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.rpm\_qi +# jc.parsers.rpm_qi jc - JSON Convert `rpm -qi` command output parser diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index 01cb1528..ccb9770d 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.rsync\_s +# jc.parsers.rsync_s jc - JSON Convert `rsync` command output streaming parser @@ -89,7 +89,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/semver.md b/docs/parsers/semver.md index 57615dc3..9b7a8e37 100644 --- a/docs/parsers/semver.md +++ b/docs/parsers/semver.md @@ -56,7 +56,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/srt.md b/docs/parsers/srt.md index 3c5a23d9..6d6a1a26 100644 --- a/docs/parsers/srt.md +++ b/docs/parsers/srt.md @@ -91,23 +91,6 @@ Examples: ... ] - - -### parse\_timestamp - -```python -def parse_timestamp(timestamp: str) -> Dict -``` - -timestamp: "hours:minutes:seconds,milliseconds" ---> -{ - "hours": "hours", - "minutes": "minutes", - "seconds": "seconds", - "milliseconds": "milliseconds", - "timestamp": "hours:minutes:seconds,milliseconds" -} - ### parse @@ -115,7 +98,7 @@ timestamp: "hours:minutes:seconds,milliseconds" ---> ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/ssh_conf.md b/docs/parsers/ssh_conf.md index c0b6d874..3996db3e 100644 --- a/docs/parsers/ssh_conf.md +++ b/docs/parsers/ssh_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ssh\_conf +# jc.parsers.ssh_conf jc - JSON Convert `ssh` configuration file and `ssh -G` command output parser @@ -527,7 +527,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/sshd_conf.md b/docs/parsers/sshd_conf.md index 698a4e7d..21265967 100644 --- a/docs/parsers/sshd_conf.md +++ b/docs/parsers/sshd_conf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.sshd\_conf +# jc.parsers.sshd_conf jc - JSON Convert `sshd` configuration file and `sshd -T` command output parser @@ -486,7 +486,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/stat_s.md b/docs/parsers/stat_s.md index 8e459e3d..67c9439d 100644 --- a/docs/parsers/stat_s.md +++ b/docs/parsers/stat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.stat\_s +# jc.parsers.stat_s jc - JSON Convert `stat` command output streaming parser @@ -82,11 +82,12 @@ Examples: ### parse ```python -@add_jc_meta -def parse(data: Iterable[str], - raw: bool = False, - quiet: bool = False, - ignore_exceptions: bool = False) -> StreamingOutputType +def parse( + data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False +) -> Iterator[Union[Dict[str, Any], Tuple[BaseException, str]]] ``` Main text parsing generator function. Returns an iterable object. diff --git a/docs/parsers/swapon.md b/docs/parsers/swapon.md index c79d624a..40094f09 100644 --- a/docs/parsers/swapon.md +++ b/docs/parsers/swapon.md @@ -48,7 +48,9 @@ Example: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> List[_Entry] +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[Dict[str, Union[str, int]]] ``` Main text parsing function diff --git a/docs/parsers/syslog_bsd.md b/docs/parsers/syslog_bsd.md index 3366b8eb..5bd62711 100644 --- a/docs/parsers/syslog_bsd.md +++ b/docs/parsers/syslog_bsd.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_bsd +# jc.parsers.syslog_bsd jc - JSON Convert Syslog RFC 3164 string parser diff --git a/docs/parsers/syslog_bsd_s.md b/docs/parsers/syslog_bsd_s.md index c2e0294f..6a46a424 100644 --- a/docs/parsers/syslog_bsd_s.md +++ b/docs/parsers/syslog_bsd_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_bsd\_s +# jc.parsers.syslog_bsd_s jc - JSON Convert Syslog RFC 3164 string streaming parser @@ -62,7 +62,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/syslog_s.md b/docs/parsers/syslog_s.md index 87e7b44f..d3f7a66f 100644 --- a/docs/parsers/syslog_s.md +++ b/docs/parsers/syslog_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.syslog\_s +# jc.parsers.syslog_s jc - JSON Convert Syslog RFC 5424 string streaming parser @@ -85,7 +85,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 3b34918c..2f308680 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_lj +# jc.parsers.systemctl_lj jc - JSON Convert `systemctl list-jobs` command output parser diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index 7bf0ba0f..9b7d2b4a 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_ls +# jc.parsers.systemctl_ls jc - JSON Convert `systemctl list-sockets` command output parser diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index 5780bc33..7cffd6f0 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.systemctl\_luf +# jc.parsers.systemctl_luf jc - JSON Convert `systemctl list-unit-files` command output parser diff --git a/docs/parsers/toml.md b/docs/parsers/toml.md index 6763e97b..ee716316 100644 --- a/docs/parsers/toml.md +++ b/docs/parsers/toml.md @@ -60,7 +60,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/top_s.md b/docs/parsers/top_s.md index 88a3bbd5..87897094 100644 --- a/docs/parsers/top_s.md +++ b/docs/parsers/top_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.top\_s +# jc.parsers.top_s jc - JSON Convert `top -b` command output streaming parser @@ -151,7 +151,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, diff --git a/docs/parsers/tune2fs.md b/docs/parsers/tune2fs.md index 27ec64f8..91b237ee 100644 --- a/docs/parsers/tune2fs.md +++ b/docs/parsers/tune2fs.md @@ -214,7 +214,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/udevadm.md b/docs/parsers/udevadm.md index 2c7cdf60..27e643d1 100644 --- a/docs/parsers/udevadm.md +++ b/docs/parsers/udevadm.md @@ -122,7 +122,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function diff --git a/docs/parsers/ufw_appinfo.md b/docs/parsers/ufw_appinfo.md index af74b6b2..00c68a4c 100644 --- a/docs/parsers/ufw_appinfo.md +++ b/docs/parsers/ufw_appinfo.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.ufw\_appinfo +# jc.parsers.ufw_appinfo jc - JSON Convert `ufw app info [application]` command output parser diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index ab8b1266..5f5b0967 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -1,18 +1,19 @@ -# Table of Contents - -* [jc.parsers.universal](#jc.parsers.universal) - * [simple\_table\_parse](#jc.parsers.universal.simple_table_parse) - * [sparse\_table\_parse](#jc.parsers.universal.sparse_table_parse) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.parsers.universal +## Table of Contents + +* [jc.parsers.universal](#jc.parsers.universal) + * [simple_table_parse](#jc.parsers.universal.simple_table_parse) + * [sparse_table_parse](#jc.parsers.universal.sparse_table_parse) + jc - JSON Convert universal parsers -### simple\_table\_parse +### simple_table_parse ```python def simple_table_parse(data: Iterable[str]) -> List[Dict] @@ -50,7 +51,7 @@ Returns: -### sparse\_table\_parse +### sparse_table_parse ```python def sparse_table_parse(data: Iterable[str], @@ -86,7 +87,7 @@ Parameters: Also, ensure there are no blank line items. - delim: (string) Delimiter to use. By default `u\\2063` + delim: (string) Delimiter to use. By default `u\2063` (invisible separator) is used since it is unlikely to ever be seen in terminal output. You can change this for troubleshooting purposes or if there is a @@ -96,3 +97,4 @@ Returns: List of Dictionaries + diff --git a/docs/parsers/update_alt_gs.md b/docs/parsers/update_alt_gs.md index 86bdfd6e..e4a1b2c2 100644 --- a/docs/parsers/update_alt_gs.md +++ b/docs/parsers/update_alt_gs.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.update\_alt\_gs +# jc.parsers.update_alt_gs jc - JSON Convert `update-alternatives --get-selections` command output parser diff --git a/docs/parsers/update_alt_q.md b/docs/parsers/update_alt_q.md index 02c1165f..c6ddf5ef 100644 --- a/docs/parsers/update_alt_q.md +++ b/docs/parsers/update_alt_q.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.update\_alt\_q +# jc.parsers.update_alt_q jc - JSON Convert `update-alternatives --query` command output parser diff --git a/docs/parsers/ver.md b/docs/parsers/ver.md index b1948934..8fcbcfa3 100644 --- a/docs/parsers/ver.md +++ b/docs/parsers/ver.md @@ -91,7 +91,7 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict[str, Any] ``` Main text parsing function @@ -113,4 +113,4 @@ Source: [`jc/parsers/ver.py`](https://github.com/kellyjonbrazil/jc/blob/master/j This parser can be used with the `--slurp` command-line option. -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/veracrypt.md b/docs/parsers/veracrypt.md index 08d3f6d8..8f5c4ab0 100644 --- a/docs/parsers/veracrypt.md +++ b/docs/parsers/veracrypt.md @@ -87,7 +87,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/vmstat_s.md b/docs/parsers/vmstat_s.md index 5c4bf7ec..1d5c6c6f 100644 --- a/docs/parsers/vmstat_s.md +++ b/docs/parsers/vmstat_s.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.vmstat\_s +# jc.parsers.vmstat_s jc - JSON Convert `vmstat` command output streaming parser @@ -101,7 +101,6 @@ Examples: ### parse ```python -@add_jc_meta def parse(data, raw=False, quiet=False, ignore_exceptions=False) ``` diff --git a/docs/parsers/x509_cert.md b/docs/parsers/x509_cert.md index 0c5f2854..a9d23725 100644 --- a/docs/parsers/x509_cert.md +++ b/docs/parsers/x509_cert.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.x509\_cert +# jc.parsers.x509_cert jc - JSON Convert X.509 Certificate format file parser diff --git a/docs/parsers/x509_csr.md b/docs/parsers/x509_csr.md index bd13c9eb..ec9638df 100644 --- a/docs/parsers/x509_csr.md +++ b/docs/parsers/x509_csr.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.x509\_csr +# jc.parsers.x509_csr jc - JSON Convert X.509 Certificate Request format file parser diff --git a/docs/parsers/xrandr.md b/docs/parsers/xrandr.md index bd85056f..e334e7a4 100644 --- a/docs/parsers/xrandr.md +++ b/docs/parsers/xrandr.md @@ -199,7 +199,9 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> Response +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> jc.parsers.xrandr.Response ``` Main text parsing function diff --git a/docs/parsers/zpool_iostat.md b/docs/parsers/zpool_iostat.md index 828bd804..fd260ecf 100644 --- a/docs/parsers/zpool_iostat.md +++ b/docs/parsers/zpool_iostat.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.zpool\_iostat +# jc.parsers.zpool_iostat jc - JSON Convert `zpool iostat` command output parser @@ -104,7 +104,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/parsers/zpool_status.md b/docs/parsers/zpool_status.md index a43d7aa1..a9b6c8d5 100644 --- a/docs/parsers/zpool_status.md +++ b/docs/parsers/zpool_status.md @@ -1,7 +1,7 @@ [Home](https://kellyjonbrazil.github.io/jc/) -# jc.parsers.zpool\_status +# jc.parsers.zpool_status jc - JSON Convert `zpool status` command output parser @@ -142,7 +142,7 @@ Examples: ```python def parse(data: str, raw: bool = False, - quiet: bool = False) -> List[JSONDictType] + quiet: bool = False) -> List[Dict[str, Any]] ``` Main text parsing function diff --git a/docs/readme.md b/docs/readme.md index 488c3d00..8ae72436 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,3 +1,4 @@ +[Home](https://kellyjonbrazil.github.io/jc/) # jc diff --git a/docs/streaming.md b/docs/streaming.md index 3b593a96..09ddb82c 100644 --- a/docs/streaming.md +++ b/docs/streaming.md @@ -1,67 +1,26 @@ -# Table of Contents - -* [jc.streaming](#jc.streaming) - * [streaming\_input\_type\_check](#jc.streaming.streaming_input_type_check) - * [streaming\_line\_input\_type\_check](#jc.streaming.streaming_line_input_type_check) - * [stream\_success](#jc.streaming.stream_success) - * [stream\_error](#jc.streaming.stream_error) - * [add\_jc\_meta](#jc.streaming.add_jc_meta) - * [raise\_or\_yield](#jc.streaming.raise_or_yield) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.streaming +## Table of Contents + +* [jc.streaming](#jc.streaming) + * [add_jc_meta](#jc.streaming.add_jc_meta) + * [raise_or_yield](#jc.streaming.raise_or_yield) + * [stream_error](#jc.streaming.stream_error) + * [stream_success](#jc.streaming.stream_success) + * [streaming_input_type_check](#jc.streaming.streaming_input_type_check) + * [streaming_line_input_type_check](#jc.streaming.streaming_line_input_type_check) + jc - JSON Convert streaming utils - - -### streaming\_input\_type\_check - -```python -def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None -``` - -Ensure input data is an iterable, but not a string or bytes. Raises -`TypeError` if not. - - - -### streaming\_line\_input\_type\_check - -```python -def streaming_line_input_type_check(line: str) -> None -``` - -Ensure each line is a string. Raises `TypeError` if not. - - - -### stream\_success - -```python -def stream_success(output_line: JSONDictType, - ignore_exceptions: bool) -> JSONDictType -``` - -Add `_jc_meta` object to output line if `ignore_exceptions=True` - - - -### stream\_error - -```python -def stream_error(e: BaseException, line: str) -> JSONDictType -``` - -Return an error `_jc_meta` field. - -### add\_jc\_meta +### add_jc_meta ```python -def add_jc_meta(func: F) -> F +def add_jc_meta(func: ~F) -> ~F ``` Decorator for streaming parsers to add stream_success and stream_error @@ -103,7 +62,7 @@ In all cases above: -### raise\_or\_yield +### raise_or_yield ```python def raise_or_yield(ignore_exceptions: bool, e: BaseException, @@ -114,3 +73,46 @@ Return the exception object and line string if ignore_exceptions is True. Otherwise, re-raise the exception from the exception object with an annotation. + + +### stream_error + +```python +def stream_error(e: BaseException, line: str) -> Dict[str, Any] +``` + +Return an error `_jc_meta` field. + + + +### stream_success + +```python +def stream_success(output_line: Dict[str, Any], + ignore_exceptions: bool) -> Dict[str, Any] +``` + +Add `_jc_meta` object to output line if `ignore_exceptions=True` + + + +### streaming_input_type_check + +```python +def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None +``` + +Ensure input data is an iterable, but not a string or bytes. Raises +`TypeError` if not. + + + +### streaming_line_input_type_check + +```python +def streaming_line_input_type_check(line: str) -> None +``` + +Ensure each line is a string. Raises `TypeError` if not. + + diff --git a/docs/utils.md b/docs/utils.md index 30899517..de07a4e4 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -1,78 +1,27 @@ -# Table of Contents - -* [jc.utils](#jc.utils) - * [warning\_message](#jc.utils.warning_message) - * [error\_message](#jc.utils.error_message) - * [is\_compatible](#jc.utils.is_compatible) - * [compatibility](#jc.utils.compatibility) - * [has\_data](#jc.utils.has_data) - * [remove\_quotes](#jc.utils.remove_quotes) - * [normalize\_key](#jc.utils.normalize_key) - * [convert\_to\_int](#jc.utils.convert_to_int) - * [convert\_to\_float](#jc.utils.convert_to_float) - * [convert\_to\_bool](#jc.utils.convert_to_bool) - * [convert\_size\_to\_int](#jc.utils.convert_size_to_int) - * [input\_type\_check](#jc.utils.input_type_check) - * [line\_slice](#jc.utils.line_slice) - * [timestamp](#jc.utils.timestamp) - * [\_\_init\_\_](#jc.utils.timestamp.__init__) - +[Home](https://kellyjonbrazil.github.io/jc/) # jc.utils +## Table of Contents + +* [jc.utils](#jc.utils) + * [compatibility](#jc.utils.compatibility) + * [convert_size_to_int](#jc.utils.convert_size_to_int) + * [convert_to_bool](#jc.utils.convert_to_bool) + * [convert_to_float](#jc.utils.convert_to_float) + * [convert_to_int](#jc.utils.convert_to_int) + * [error_message](#jc.utils.error_message) + * [has_data](#jc.utils.has_data) + * [input_type_check](#jc.utils.input_type_check) + * [is_compatible](#jc.utils.is_compatible) + * [line_slice](#jc.utils.line_slice) + * [normalize_key](#jc.utils.normalize_key) + * [remove_quotes](#jc.utils.remove_quotes) + * [warning_message](#jc.utils.warning_message) + jc - JSON Convert utils - - -### warning\_message - -```python -def warning_message(message_lines: List[str]) -> None -``` - -Prints warning message to `STDERR` for non-fatal issues. The first line -is prepended with 'jc: Warning - ' and subsequent lines are indented. -Wraps text as needed based on the terminal width. - -Parameters: - - message: (list) list of string lines - -Returns: - - None - just prints output to STDERR - - - -### error\_message - -```python -def error_message(message_lines: List[str]) -> None -``` - -Prints an error message to `STDERR` for fatal issues. The first line is -prepended with 'jc: Error - ' and subsequent lines are indented. -Wraps text as needed based on the terminal width. - -Parameters: - - message: (list) list of string lines - -Returns: - - None - just prints output to STDERR - - - -### is\_compatible - -```python -def is_compatible(compatible: List[str]) -> bool -``` - -Returns True if the parser is compatible with the running OS platform. - ### compatibility @@ -101,135 +50,9 @@ Returns: None - just prints output to STDERR - - -### has\_data - -```python -def has_data(data: Union[str, bytes]) -> bool -``` - -Checks if the string input contains data. If there are any -non-whitespace characters then return `True`, else return `False`. - -For bytes, returns True if there is any data. - -Parameters: - - data: (string, bytes) input to check whether it contains data - -Returns: - - Boolean True if input string (data) contains non-whitespace - characters, otherwise False. For bytes data, returns - True if there is any data, otherwise False. - - - -### remove\_quotes - -```python -def remove_quotes(data: str) -> str -``` - -Remove single or double quotes surrounding a string. If no quotes are -found then the string is returned unmodified. - -Parameters: - - data: (string) Input value - -Returns: - - string - - - -### normalize\_key - -```python -def normalize_key(data: str) -> str -``` - -Normalize a key name by shifting to lower-case and converting special -characters to underscores. - -Special characters are defined as `space` and the following: - - !"#$%&'()*+,-./:;<=>?@[\]^`{|}~ - -This is a lossy algorithm. Repeating and trailing underscores are -removed. - -Parameters: - - data: (string) Input value - -Returns: - - string - - - -### convert\_to\_int - -```python -def convert_to_int(value: object) -> Optional[int] -``` - -Converts string and float input to int. Strips all non-numeric -characters from strings. - -Parameters: - - value: (string/float) Input value - -Returns: - - integer/None Integer if successful conversion, otherwise None - - - -### convert\_to\_float - -```python -def convert_to_float(value: object) -> Optional[float] -``` - -Converts string and int input to float. Strips all non-numeric -characters from strings. - -Parameters: - - value: (string/integer) Input value - -Returns: - - float/None Float if successful conversion, otherwise None - - - -### convert\_to\_bool - -```python -def convert_to_bool(value: object) -> bool -``` - -Converts string, integer, or float input to boolean by checking -for 'truthy' values. - -Parameters: - - value: (string/integer/float) Input value - -Returns: - - True/False False unless a 'truthy' number or string is found - ('y', 'yes', 'true', '1', 1, -1, etc.) - -### convert\_size\_to\_int +### convert_size_to_int ```python def convert_size_to_int(size: str, binary: bool = False) -> Optional[int] @@ -269,9 +92,110 @@ gigabytes, terabytes and petabytes. Some examples: >>> convert_size_to_int('1.5 GB', binary=True) 1610612736 + + +### convert_to_bool + +```python +def convert_to_bool(value: object) -> bool +``` + +Converts string, integer, or float input to boolean by checking +for 'truthy' values. + +Parameters: + + value: (string/integer/float) Input value + +Returns: + + True/False False unless a 'truthy' number or string is found + ('y', 'yes', 'true', '1', 1, -1, etc.) + + + +### convert_to_float + +```python +def convert_to_float(value: object) -> Optional[float] +``` + +Converts string and int input to float. Strips all non-numeric +characters from strings. + +Parameters: + + value: (string/integer) Input value + +Returns: + + float/None Float if successful conversion, otherwise None + + + +### convert_to_int + +```python +def convert_to_int(value: object) -> Optional[int] +``` + +Converts string and float input to int. Strips all non-numeric +characters from strings. + +Parameters: + + value: (string/float) Input value + +Returns: + + integer/None Integer if successful conversion, otherwise None + + + +### error_message + +```python +def error_message(message_lines: List[str]) -> None +``` + +Prints an error message to `STDERR` for fatal issues. The first line is +prepended with 'jc: Error - ' and subsequent lines are indented. +Wraps text as needed based on the terminal width. + +Parameters: + + message: (list) list of string lines + +Returns: + + None - just prints output to STDERR + + + +### has_data + +```python +def has_data(data: Union[str, bytes]) -> bool +``` + +Checks if the string input contains data. If there are any +non-whitespace characters then return `True`, else return `False`. + +For bytes, returns True if there is any data. + +Parameters: + + data: (string, bytes) input to check whether it contains data + +Returns: + + Boolean True if input string (data) contains non-whitespace + characters, otherwise False. For bytes data, returns + True if there is any data, otherwise False. + -### input\_type\_check +### input_type_check ```python def input_type_check(data: object) -> None @@ -279,16 +203,26 @@ def input_type_check(data: object) -> None Ensure input data is a string. Raises `TypeError` if not. + + +### is_compatible + +```python +def is_compatible(compatible: List[str]) -> bool +``` + +Returns True if the parser is compatible with the running OS platform. + -### line\_slice +### line_slice ```python def line_slice( - data: Union[str, Iterable[str], TextIO, bytes, None], + data: Union[str, Iterable[str], TextIO, bytes, NoneType], slice_start: Optional[int] = None, slice_end: Optional[int] = None -) -> Union[str, Iterable[str], TextIO, bytes, None] +) -> Union[str, Iterable[str], TextIO, bytes, NoneType] ``` Slice input data by lines - lazily, if possible. @@ -310,51 +244,69 @@ Returns: string if input is a string. iterable of strings if input is an iterable (for streaming parsers) - + -### timestamp Objects +### normalize_key ```python -class timestamp() +def normalize_key(data: str) -> str ``` - +Normalize a key name by shifting to lower-case and converting special +characters to underscores. -### \_\_init\_\_ +Special characters are defined as `space` and the following: -```python -def __init__(datetime_string: Optional[str], - format_hint: Optional[Iterable[int]] = None) -> None -``` + !"#$%&'()*+,-./:;<=>?@[\]^`{|}~ -Input a datetime text string of several formats and convert to a -naive or timezone-aware epoch timestamp in UTC. +This is a lossy algorithm. Repeating and trailing underscores are +removed. Parameters: - datetime_string (str): a string representation of a - datetime in several supported formats + data: (string) Input value - format_hint (iterable): an optional iterable of format ID - integers to instruct the timestamp object to try those - formats first in the order given. Other formats will be - tried after the format hint list is exhausted. This can - speed up timestamp conversion so several different formats - don't have to be tried in brute-force fashion. +Returns: -Returns a timestamp object with the following attributes: + string - string (str): the input datetime string + - format (int | None): the format rule that was used to decode - the datetime string. None if conversion fails. +### remove_quotes - naive (int | None): timestamp based on locally configured - timezone. None if conversion fails. +```python +def remove_quotes(data: str) -> str +``` - utc (int | None): aware timestamp only if UTC timezone - detected in datetime string. None if conversion fails. +Remove single or double quotes surrounding a string. If no quotes are +found then the string is returned unmodified. + +Parameters: + + data: (string) Input value + +Returns: + + string + + + +### warning_message + +```python +def warning_message(message_lines: List[str]) -> None +``` + +Prints warning message to `STDERR` for non-fatal issues. The first line +is prepended with 'jc: Warning - ' and subsequent lines are indented. +Wraps text as needed based on the terminal width. + +Parameters: + + message: (list) list of string lines + +Returns: + + None - just prints output to STDERR - iso (str | None): ISO string - timezone information is output - only if UTC timezone is detected in the datetime string. diff --git a/jc/parsers/acpi.py b/jc/parsers/acpi.py index 8b3a080d..e8a96336 100644 --- a/jc/parsers/acpi.py +++ b/jc/parsers/acpi.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `acpi` command output parser +r"""jc - JSON Convert `acpi` command output parser Usage (cli): diff --git a/jc/parsers/airport.py b/jc/parsers/airport.py index 696100f8..3c3d7e69 100644 --- a/jc/parsers/airport.py +++ b/jc/parsers/airport.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `airport -I` command output parser +r"""jc - JSON Convert `airport -I` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/airport_s.py b/jc/parsers/airport_s.py index 802c726e..d804226b 100644 --- a/jc/parsers/airport_s.py +++ b/jc/parsers/airport_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `airport -s` command output parser +r"""jc - JSON Convert `airport -s` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/apt_cache_show.py b/jc/parsers/apt_cache_show.py index 86cbe3e7..62ede53a 100644 --- a/jc/parsers/apt_cache_show.py +++ b/jc/parsers/apt_cache_show.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `apt-cache show` command parser +r"""jc - JSON Convert `apt-cache show` command parser Usage (cli): diff --git a/jc/parsers/apt_get_sqq.py b/jc/parsers/apt_get_sqq.py index eeec6824..77001cb9 100644 --- a/jc/parsers/apt_get_sqq.py +++ b/jc/parsers/apt_get_sqq.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `apt-get -sqq` command output parser +r"""jc - JSON Convert `apt-get -sqq` command output parser Requires the `-sqq` options in `apt-get`. @@ -23,7 +23,7 @@ Schema: "package": string, "broken": string/null, "proposed_pkg_ver": string, - "existing_src": string/null, + "existing_pkg_ver": string/null, "architecture": string } ] @@ -37,7 +37,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -45,7 +45,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -53,7 +53,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -61,7 +61,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -69,7 +69,7 @@ Examples: "package": "base-files", "broken": "10.3+deb10u4", "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -77,7 +77,7 @@ Examples: "package": "base-files", "broken": null, "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -85,7 +85,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -93,7 +93,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" } ] @@ -105,7 +105,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -113,7 +113,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -121,7 +121,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -129,7 +129,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -137,7 +137,7 @@ Examples: "package": "base-files", "broken": "10.3+deb10u4", "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -145,7 +145,7 @@ Examples: "package": "base-files", "broken": null, "proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable", - "existing_src": null, + "existing_pkg_ver": null, "architecture": "amd64" }, { @@ -153,7 +153,7 @@ Examples: "package": "dpkg", "broken": "1.19.7", "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" }, { @@ -161,7 +161,7 @@ Examples: "package": "dpkg", "broken": null, "proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable", - "existing_src": "Debian-Security:10/oldstable", + "existing_pkg_ver": "Debian-Security:10/oldstable", "architecture": "amd64" } ] @@ -238,7 +238,7 @@ def parse( # Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64]) # | | | | | \architecture - # | | | | \existing_src (optional) + # | | | | \existing_pkg_ver (optional) # | | | \proposed_pkg_ver # | | \broken (optional) # | \package @@ -250,7 +250,7 @@ def parse( broken_val = None packages_pe = None proposed_pkg_ver = None - existing_src = None + existing_pkg_ver = None parsed_line = line_re.match(line) if parsed_line: @@ -263,14 +263,14 @@ def parse( packages_pe = parsed_dict['packages_pe'].split(',') proposed_pkg_ver = packages_pe[0].strip() if len(packages_pe) == 2: - existing_src = packages_pe[1].strip() + existing_pkg_ver = packages_pe[1].strip() output_line = { 'operation': parsed_dict['operation'], 'package': parsed_dict['package'], 'broken': broken_val, 'proposed_pkg_ver': proposed_pkg_ver, - 'existing_src': existing_src, + 'existing_pkg_ver': existing_pkg_ver, 'architecture': parsed_dict['architecture'] } diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index db00708d..be0b6edc 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `arp` command output parser +r"""jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. diff --git a/jc/parsers/asciitable.py b/jc/parsers/asciitable.py index b7da4b94..4e2768c7 100644 --- a/jc/parsers/asciitable.py +++ b/jc/parsers/asciitable.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `asciitable` parser +r"""jc - JSON Convert `asciitable` parser This parser converts ASCII and Unicode text tables with single-line rows. diff --git a/jc/parsers/asciitable_m.py b/jc/parsers/asciitable_m.py index 24b55487..bc6cb979 100644 --- a/jc/parsers/asciitable_m.py +++ b/jc/parsers/asciitable_m.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `asciitable-m` parser +r"""jc - JSON Convert `asciitable-m` parser This parser converts various styles of ASCII and Unicode text tables with multi-line rows. Tables must have a header row and separator line between diff --git a/jc/parsers/blkid.py b/jc/parsers/blkid.py index 6d28664c..d799af91 100644 --- a/jc/parsers/blkid.py +++ b/jc/parsers/blkid.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `blkid` command output parser +r"""jc - JSON Convert `blkid` command output parser Usage (cli): diff --git a/jc/parsers/bluetoothctl.py b/jc/parsers/bluetoothctl.py index da3209e0..24fc553e 100644 --- a/jc/parsers/bluetoothctl.py +++ b/jc/parsers/bluetoothctl.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `bluetoothctl` command output parser +r"""jc - JSON Convert `bluetoothctl` command output parser Supports the following `bluetoothctl` subcommands: - `bluetoothctl list` diff --git a/jc/parsers/broken_parser.py b/jc/parsers/broken_parser.py index ded316ed..475b460d 100644 --- a/jc/parsers/broken_parser.py +++ b/jc/parsers/broken_parser.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert broken parser - for testing purposes only""" +r"""jc - JSON Convert broken parser - for testing purposes only""" import non_existent_library class info(): diff --git a/jc/parsers/cbt.py b/jc/parsers/cbt.py index 184993fa..7296b41a 100644 --- a/jc/parsers/cbt.py +++ b/jc/parsers/cbt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `cbt` command output parser (Google Bigtable) +r"""jc - JSON Convert `cbt` command output parser (Google Bigtable) Parses the human-, but not machine-, friendly output of the cbt command (for Google's Bigtable). diff --git a/jc/parsers/cef.py b/jc/parsers/cef.py index dae7bc54..af9d1a41 100644 --- a/jc/parsers/cef.py +++ b/jc/parsers/cef.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert CEF string parser +r"""jc - JSON Convert CEF string parser This parser conforms to the Microfocus Arcsight CEF specification. diff --git a/jc/parsers/cef_s.py b/jc/parsers/cef_s.py index 00215aca..44247912 100644 --- a/jc/parsers/cef_s.py +++ b/jc/parsers/cef_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert CEF string output streaming parser +r"""jc - JSON Convert CEF string output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/certbot.py b/jc/parsers/certbot.py index 1bf442c0..99ae223c 100644 --- a/jc/parsers/certbot.py +++ b/jc/parsers/certbot.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `certbot` command output parser +r"""jc - JSON Convert `certbot` command output parser Supports the following `certbot` commands: diff --git a/jc/parsers/chage.py b/jc/parsers/chage.py index ad24cffa..35a43fe6 100644 --- a/jc/parsers/chage.py +++ b/jc/parsers/chage.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `chage --list` command output parser +r"""jc - JSON Convert `chage --list` command output parser Supports `chage -l ` or `chage --list ` diff --git a/jc/parsers/cksum.py b/jc/parsers/cksum.py index 4e798474..463380f1 100644 --- a/jc/parsers/cksum.py +++ b/jc/parsers/cksum.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `cksum` command output parser +r"""jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` diff --git a/jc/parsers/clf.py b/jc/parsers/clf.py index 374553ce..fed1d94c 100644 --- a/jc/parsers/clf.py +++ b/jc/parsers/clf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Common Log Format file parser +r"""jc - JSON Convert Common Log Format file parser This parser will handle the Common Log Format standard as specified at https://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format. diff --git a/jc/parsers/clf_s.py b/jc/parsers/clf_s.py index fc43ed1e..2debae02 100644 --- a/jc/parsers/clf_s.py +++ b/jc/parsers/clf_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Common Log Format file streaming parser +r"""jc - JSON Convert Common Log Format file streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/crontab.py b/jc/parsers/crontab.py index 78ff5336..0df442d1 100644 --- a/jc/parsers/crontab.py +++ b/jc/parsers/crontab.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `crontab -l` command output and crontab +r"""jc - JSON Convert `crontab -l` command output and crontab file parser Supports `crontab -l` command output and crontab files. diff --git a/jc/parsers/crontab_u.py b/jc/parsers/crontab_u.py index 0379d6c3..5d20ec9d 100644 --- a/jc/parsers/crontab_u.py +++ b/jc/parsers/crontab_u.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `crontab -l` command output and crontab +r"""jc - JSON Convert `crontab -l` command output and crontab file parser This version of the `crontab -l` parser supports output that contains user diff --git a/jc/parsers/csv.py b/jc/parsers/csv.py index e97e9669..7d56fe3a 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `csv` file parser +r"""jc - JSON Convert `csv` file parser The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. diff --git a/jc/parsers/csv_s.py b/jc/parsers/csv_s.py index 9eaf1a1b..5fa0be35 100644 --- a/jc/parsers/csv_s.py +++ b/jc/parsers/csv_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `csv` file streaming parser +r"""jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/curl_head.py b/jc/parsers/curl_head.py index 2c917a29..18793949 100644 --- a/jc/parsers/curl_head.py +++ b/jc/parsers/curl_head.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `curl --head` command output parser +r"""jc - JSON Convert `curl --head` command output parser This parser converts standard and verbose `curl --head` output. diff --git a/jc/parsers/date.py b/jc/parsers/date.py index abcc3e7a..931cf5df 100644 --- a/jc/parsers/date.py +++ b/jc/parsers/date.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `date` command output parser +r"""jc - JSON Convert `date` command output parser The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/datetime_iso.py b/jc/parsers/datetime_iso.py index 6fddff33..f092b1aa 100644 --- a/jc/parsers/datetime_iso.py +++ b/jc/parsers/datetime_iso.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert ISO 8601 Datetime string parser +r"""jc - JSON Convert ISO 8601 Datetime string parser This parser supports standard ISO 8601 strings that include both date and time. If no timezone or offset information is available in the string, then diff --git a/jc/parsers/debconf_show.py b/jc/parsers/debconf_show.py index a4dfc8d6..b7a366cb 100644 --- a/jc/parsers/debconf_show.py +++ b/jc/parsers/debconf_show.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `debconf-show` command output parser +r"""jc - JSON Convert `debconf-show` command output parser Usage (cli): diff --git a/jc/parsers/df.py b/jc/parsers/df.py index ca8ce335..fbe1ca80 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `df` command output parser +r"""jc - JSON Convert `df` command output parser Values are normalized to bytes when using `df -h`. diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index cc146019..172ebeba 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dig` command output parser +r"""jc - JSON Convert `dig` command output parser Options supported: - `+noall +answer` options are supported in cases where only the answer diff --git a/jc/parsers/dir.py b/jc/parsers/dir.py index 0115fce6..d522d94a 100644 --- a/jc/parsers/dir.py +++ b/jc/parsers/dir.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dir` command output parser +r"""jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` diff --git a/jc/parsers/disabled_parser.py b/jc/parsers/disabled_parser.py index 1ed79a89..b68a4879 100644 --- a/jc/parsers/disabled_parser.py +++ b/jc/parsers/disabled_parser.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert disabled parser +r"""jc - JSON Convert disabled parser This parser has been disabled due to an error in the parser code. """ diff --git a/jc/parsers/dmidecode.py b/jc/parsers/dmidecode.py index 98a342e3..043f715a 100644 --- a/jc/parsers/dmidecode.py +++ b/jc/parsers/dmidecode.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dmidecode` command output parser +r"""jc - JSON Convert `dmidecode` command output parser Usage (cli): diff --git a/jc/parsers/dpkg_l.py b/jc/parsers/dpkg_l.py index 6375c608..26d87029 100644 --- a/jc/parsers/dpkg_l.py +++ b/jc/parsers/dpkg_l.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `dpkg -l` command output parser +r"""jc - JSON Convert `dpkg -l` command output parser Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example: diff --git a/jc/parsers/du.py b/jc/parsers/du.py index f55edda2..ad600fc1 100644 --- a/jc/parsers/du.py +++ b/jc/parsers/du.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `du` command output parser +r"""jc - JSON Convert `du` command output parser The `du -h` option is not supported with the default output. If you would like to use `du -h` or other options that change the output, be sure diff --git a/jc/parsers/efibootmgr.py b/jc/parsers/efibootmgr.py index 0d5b7015..0850c54e 100644 --- a/jc/parsers/efibootmgr.py +++ b/jc/parsers/efibootmgr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `efibootmgr` command output parser +r"""jc - JSON Convert `efibootmgr` command output parser The `-v` option is also supported. diff --git a/jc/parsers/email_address.py b/jc/parsers/email_address.py index 9dd6833f..ea8e89f1 100644 --- a/jc/parsers/email_address.py +++ b/jc/parsers/email_address.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Email Address string parser +r"""jc - JSON Convert Email Address string parser Usage (cli): diff --git a/jc/parsers/env.py b/jc/parsers/env.py index 4f2280c8..68d08af6 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `env` and `printenv` command output parser +r"""jc - JSON Convert `env` and `printenv` command output parser This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/ethtool.py b/jc/parsers/ethtool.py index 7616c3c2..d6a52fa8 100644 --- a/jc/parsers/ethtool.py +++ b/jc/parsers/ethtool.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ethtool` command output parser +r"""jc - JSON Convert `ethtool` command output parser Supports standard `ethtool` output and the `--module-info` option. @@ -161,6 +161,7 @@ Examples: "br_margin_min": "0%" } """ +import re from typing import List, Dict from jc.jc_types import JSONDictType import jc.utils @@ -202,6 +203,39 @@ def _process(proc_data: JSONDictType) -> JSONDictType: if key in proc_data: proc_data[key] = jc.utils.convert_to_bool(proc_data[key]) + # find and convert units + # "0.0468 mW / -13.30 dBm" or "-40.00 degrees C / -40.00 degrees F" + degrees_re = re.compile(r'(?P.*?) degrees C \/ (?P.*?) degrees F') + power_re = re.compile(r'(?P.*?) mW \/ (?P.*?) dBm') + + for key, val in proc_data.copy().items(): + if isinstance(val, str): + degrees_match = re.match(degrees_re, val) + if degrees_match: + degrees_dict = degrees_match.groupdict() + proc_data[key + '_celsius'] = float(degrees_dict['deg_c']) + proc_data[key + '_farenheit'] = float(degrees_dict['deg_f']) + del proc_data[key] + continue + + power_match = re.match(power_re, val) + if power_match: + power_dict = power_match.groupdict() + proc_data[key + '_mw'] = float(power_dict['pow_mw']) + proc_data[key + '_dbm'] = float(power_dict['pow_dbm']) + del proc_data[key] + continue + + if val.endswith(' V'): + proc_data[key + '_v'] = jc.utils.convert_to_float(val) + del proc_data[key] + continue + + if val.endswith(' mA'): + proc_data[key + '_ma'] = jc.utils.convert_to_float(val) + del proc_data[key] + continue + return proc_data @@ -304,18 +338,21 @@ def _parse_default(data: str) -> JSONDictType: val = val.strip() raw_output[key] = val - if supported_ports: - raw_output['supported_ports'] = supported_ports - if supported_link_modes: - raw_output['supported_link_modes'] = supported_link_modes - if supported_fec_modes: - raw_output['supported_fec_modes'] = supported_fec_modes - if advertised_link_modes: - raw_output['advertised_link_modes'] = advertised_link_modes - if advertised_fec_modes: - raw_output['advertised_fec_modes'] = advertised_fec_modes - if current_message_level: - raw_output['current_message_level'] = current_message_level + list_vals = [ + (supported_ports, 'supported_ports'), + (supported_link_modes, 'supported_link_modes'), + (supported_fec_modes, 'supported_fec_modes'), + (advertised_link_modes, 'advertised_link_modes'), + (advertised_fec_modes, 'advertised_fec_modes'), + (current_message_level, 'current_message_level') + ] + + for obj_list, obj_key in list_vals: + if raw_output.get(obj_key, '').lower() == 'not reported': + raw_output[obj_key] = [] + else: + if obj_list: + raw_output[obj_key] = obj_list return raw_output diff --git a/jc/parsers/file.py b/jc/parsers/file.py index 264ccb3a..22702825 100644 --- a/jc/parsers/file.py +++ b/jc/parsers/file.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `file` command output parser +r"""jc - JSON Convert `file` command output parser Usage (cli): diff --git a/jc/parsers/find.py b/jc/parsers/find.py index 059cf30d..087995ac 100644 --- a/jc/parsers/find.py +++ b/jc/parsers/find.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `find` command output parser +r"""jc - JSON Convert `find` command output parser This parser returns a list of objects by default and a list of strings if the `--raw` option is used. diff --git a/jc/parsers/findmnt.py b/jc/parsers/findmnt.py index 4d18c4f1..a8113c6c 100644 --- a/jc/parsers/findmnt.py +++ b/jc/parsers/findmnt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `findmnt` command output parser +r"""jc - JSON Convert `findmnt` command output parser Supports `-a`, `-l`, or no `findmnt` options. diff --git a/jc/parsers/finger.py b/jc/parsers/finger.py index f46df76e..8b680279 100644 --- a/jc/parsers/finger.py +++ b/jc/parsers/finger.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `finger` command output parser +r"""jc - JSON Convert `finger` command output parser Supports `-s` output option. Does not support the `-l` detail option. diff --git a/jc/parsers/foo.py b/jc/parsers/foo.py index 8188e517..afcb2a06 100644 --- a/jc/parsers/foo.py +++ b/jc/parsers/foo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `foo` command output parser +r"""jc - JSON Convert `foo` command output parser <> diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index 5d62c62f..145871eb 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `foo` command output streaming parser +r"""jc - JSON Convert `foo` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/free.py b/jc/parsers/free.py index 31d813a4..55405f4c 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `free` command output parser +r"""jc - JSON Convert `free` command output parser Values are normalized to bytes when using `free -h`. diff --git a/jc/parsers/fstab.py b/jc/parsers/fstab.py index c5618696..24242514 100644 --- a/jc/parsers/fstab.py +++ b/jc/parsers/fstab.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `fstab` file parser +r"""jc - JSON Convert `fstab` file parser Usage (cli): diff --git a/jc/parsers/git_log.py b/jc/parsers/git_log.py index 8ad91dbd..e1f0ea49 100644 --- a/jc/parsers/git_log.py +++ b/jc/parsers/git_log.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git log` command output parser +r"""jc - JSON Convert `git log` command output parser Can be used with the following format options: - `oneline` diff --git a/jc/parsers/git_log_s.py b/jc/parsers/git_log_s.py index e7b02a5a..cb39e8b2 100644 --- a/jc/parsers/git_log_s.py +++ b/jc/parsers/git_log_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git log` command output streaming parser +r"""jc - JSON Convert `git log` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/git_ls_remote.py b/jc/parsers/git_ls_remote.py index e05c8993..8af4aa49 100644 --- a/jc/parsers/git_ls_remote.py +++ b/jc/parsers/git_ls_remote.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `git ls-remote` command output parser +r"""jc - JSON Convert `git ls-remote` command output parser This parser outputs two schemas: diff --git a/jc/parsers/gpg.py b/jc/parsers/gpg.py index 21eb32fa..2d8502bb 100644 --- a/jc/parsers/gpg.py +++ b/jc/parsers/gpg.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `gpg --with-colons` command output parser +r"""jc - JSON Convert `gpg --with-colons` command output parser Usage (cli): diff --git a/jc/parsers/group.py b/jc/parsers/group.py index 6bf65f52..13aeaf5e 100644 --- a/jc/parsers/group.py +++ b/jc/parsers/group.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/group` file parser +r"""jc - JSON Convert `/etc/group` file parser Usage (cli): diff --git a/jc/parsers/gshadow.py b/jc/parsers/gshadow.py index b2b87dea..b5d50ca1 100644 --- a/jc/parsers/gshadow.py +++ b/jc/parsers/gshadow.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/gshadow` file parser +r"""jc - JSON Convert `/etc/gshadow` file parser Usage (cli): diff --git a/jc/parsers/hash.py b/jc/parsers/hash.py index c88b87a9..8e79c78d 100644 --- a/jc/parsers/hash.py +++ b/jc/parsers/hash.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hash` command output parser +r"""jc - JSON Convert `hash` command output parser Usage (cli): diff --git a/jc/parsers/hashsum.py b/jc/parsers/hashsum.py index be47b742..d8633997 100644 --- a/jc/parsers/hashsum.py +++ b/jc/parsers/hashsum.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hash sum` command output parser +r"""jc - JSON Convert `hash sum` command output parser This parser works with the following hash calculation utilities: - `md5` diff --git a/jc/parsers/hciconfig.py b/jc/parsers/hciconfig.py index 7b769172..15820eab 100644 --- a/jc/parsers/hciconfig.py +++ b/jc/parsers/hciconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `hciconfig` command output parser +r"""jc - JSON Convert `hciconfig` command output parser Usage (cli): diff --git a/jc/parsers/history.py b/jc/parsers/history.py index d07d09e0..dce1ee64 100644 --- a/jc/parsers/history.py +++ b/jc/parsers/history.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `history` command output parser +r"""jc - JSON Convert `history` command output parser This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/host.py b/jc/parsers/host.py index a026a0b5..40a878ac 100644 --- a/jc/parsers/host.py +++ b/jc/parsers/host.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `host` command output parser +r"""jc - JSON Convert `host` command output parser Supports parsing of the most commonly used RR types (A, AAAA, MX, TXT) diff --git a/jc/parsers/hosts.py b/jc/parsers/hosts.py index bb5dd009..b9b2efff 100644 --- a/jc/parsers/hosts.py +++ b/jc/parsers/hosts.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/hosts` file parser +r"""jc - JSON Convert `/etc/hosts` file parser Usage (cli): diff --git a/jc/parsers/http_headers.py b/jc/parsers/http_headers.py index e1de8c3e..69ffdb4b 100644 --- a/jc/parsers/http_headers.py +++ b/jc/parsers/http_headers.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert HTTP headers parser +r"""jc - JSON Convert HTTP headers parser Converts HTTP request and response headers into a list of dictionaries. Well-known headers are processed to allow multiple instances which are diff --git a/jc/parsers/id.py b/jc/parsers/id.py index d77961a4..da3d261f 100644 --- a/jc/parsers/id.py +++ b/jc/parsers/id.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `id` command output parser +r"""jc - JSON Convert `id` command output parser Usage (cli): diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 6192d699..d24b9147 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ifconfig` command output parser +r"""jc - JSON Convert `ifconfig` command output parser No `ifconfig` options are supported. diff --git a/jc/parsers/iftop.py b/jc/parsers/iftop.py index 3439507c..ca1fe556 100644 --- a/jc/parsers/iftop.py +++ b/jc/parsers/iftop.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iftop` command output parser +r"""jc - JSON Convert `iftop` command output parser Usage (cli): diff --git a/jc/parsers/ini.py b/jc/parsers/ini.py index 21ce3cf4..6455e324 100644 --- a/jc/parsers/ini.py +++ b/jc/parsers/ini.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert INI file parser +r"""jc - JSON Convert INI file parser Parses standard INI files. diff --git a/jc/parsers/ini_dup.py b/jc/parsers/ini_dup.py index bb94ea43..f8dbd148 100644 --- a/jc/parsers/ini_dup.py +++ b/jc/parsers/ini_dup.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert INI with duplicate key file parser +r"""jc - JSON Convert INI with duplicate key file parser Parses standard INI files and preserves duplicate values. All values are contained in lists/arrays. diff --git a/jc/parsers/iostat.py b/jc/parsers/iostat.py index 0a4b4107..74675980 100644 --- a/jc/parsers/iostat.py +++ b/jc/parsers/iostat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iostat` command output parser +r"""jc - JSON Convert `iostat` command output parser > Note: `iostat` version 11 and higher include a JSON output option diff --git a/jc/parsers/iostat_s.py b/jc/parsers/iostat_s.py index c2f5921f..3fa92a53 100644 --- a/jc/parsers/iostat_s.py +++ b/jc/parsers/iostat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iostat` command output streaming parser +r"""jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/ip_address.py b/jc/parsers/ip_address.py index 991159c1..7e6b37cb 100644 --- a/jc/parsers/ip_address.py +++ b/jc/parsers/ip_address.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert IP Address string parser +r"""jc - JSON Convert IP Address string parser Accepts standard and integer IP address notation for both IPv4 and IPv6 addresses. CIDR subnet mask and Scope ID is also allowed for standard diff --git a/jc/parsers/ip_route.py b/jc/parsers/ip_route.py index 0396dd32..eedd9422 100644 --- a/jc/parsers/ip_route.py +++ b/jc/parsers/ip_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ip route` command output parser +r"""jc - JSON Convert `ip route` command output parser Usage (cli): diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 893a0476..a2d52ea6 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iptables` command output parser +r"""jc - JSON Convert `iptables` command output parser Supports `-vLn` and `--line-numbers` for all tables. diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 8b936807..90e008af 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iw dev scan` command output parser +r"""jc - JSON Convert `iw dev scan` command output parser This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test. diff --git a/jc/parsers/iwconfig.py b/jc/parsers/iwconfig.py index 56fff475..e4bd43bf 100644 --- a/jc/parsers/iwconfig.py +++ b/jc/parsers/iwconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `iwconfig` command output parser +r"""jc - JSON Convert `iwconfig` command output parser No `iwconfig` options are supported. diff --git a/jc/parsers/jar_manifest.py b/jc/parsers/jar_manifest.py index d54a2901..235e4738 100644 --- a/jc/parsers/jar_manifest.py +++ b/jc/parsers/jar_manifest.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Java `MANIFEST.MF` file parser +r"""jc - JSON Convert Java `MANIFEST.MF` file parser Usage (cli): diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index 0befa601..7815ab59 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `jobs` command output parser +r"""jc - JSON Convert `jobs` command output parser Also supports the `-l` option. diff --git a/jc/parsers/jwt.py b/jc/parsers/jwt.py index c1658cfa..8356d9ea 100644 --- a/jc/parsers/jwt.py +++ b/jc/parsers/jwt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert JWT string parser +r"""jc - JSON Convert JWT string parser > Note: `jc` will not check the integrity of the JWT payload. diff --git a/jc/parsers/kv.py b/jc/parsers/kv.py index c4ede399..4fe3156f 100644 --- a/jc/parsers/kv.py +++ b/jc/parsers/kv.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `Key/Value` file and string parser +r"""jc - JSON Convert `Key/Value` file and string parser Supports files containing simple key/value pairs. diff --git a/jc/parsers/kv_dup.py b/jc/parsers/kv_dup.py index f457c69d..417a3805 100644 --- a/jc/parsers/kv_dup.py +++ b/jc/parsers/kv_dup.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `Key/Value` with duplicate key file and string parser +r"""jc - JSON Convert `Key/Value` with duplicate key file and string parser Supports files containing simple key/value pairs and preserves duplicate values. All values are contained in lists/arrays. diff --git a/jc/parsers/last.py b/jc/parsers/last.py index 8683e3d1..821f8eb9 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `last` and `lastb` command output parser +r"""jc - JSON Convert `last` and `lastb` command output parser Supports `-w`, `-F`, and `-x` options. @@ -98,7 +98,6 @@ Examples: }, ... ] - """ import re import jc.utils diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 85a69e42..4be45e89 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ls` and `vdir` command output parser +r"""jc - JSON Convert `ls` and `vdir` command output parser Options supported: - `lbaR1` diff --git a/jc/parsers/ls_s.py b/jc/parsers/ls_s.py index 8cf2213d..6f4b8e09 100644 --- a/jc/parsers/ls_s.py +++ b/jc/parsers/ls_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ls` and `vdir` command output streaming parser +r"""jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/lsattr.py b/jc/parsers/lsattr.py index 30d60945..dc3a3794 100644 --- a/jc/parsers/lsattr.py +++ b/jc/parsers/lsattr.py @@ -1,162 +1,162 @@ -"""jc - JSON Convert `lsattr` command output parser - -Usage (cli): - - $ lsattr | jc --lsattr - -or - - $ jc lsattr - -Usage (module): - - import jc - result = jc.parse('lsattr', lsattr_command_output) - -Schema: - -Information from https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 -used to define field names - - [ - { - "file": string, - "compressed_file": Optional[boolean], - "compressed_dirty_file": Optional[boolean], - "compression_raw_access": Optional[boolean], - "secure_deletion": Optional[boolean], - "undelete": Optional[boolean], - "synchronous_updates": Optional[boolean], - "synchronous_directory_updates": Optional[boolean], - "immutable": Optional[boolean], - "append_only": Optional[boolean], - "no_dump": Optional[boolean], - "no_atime": Optional[boolean], - "compression_requested": Optional[boolean], - "encrypted": Optional[boolean], - "journaled_data": Optional[boolean], - "indexed_directory": Optional[boolean], - "no_tailmerging": Optional[boolean], - "top_of_directory_hierarchies": Optional[boolean], - "extents": Optional[boolean], - "no_cow": Optional[boolean], - "casefold": Optional[boolean], - "inline_data": Optional[boolean], - "project_hierarchy": Optional[boolean], - "verity": Optional[boolean], - } - ] - -Examples: - - $ sudo lsattr /etc/passwd | jc --lsattr - [ - { - "file": "/etc/passwd", - "extents": true - } - ] -""" -from typing import List, Dict -from jc.jc_types import JSONDictType -import jc.utils - - -class info(): - """Provides parser metadata (version, author, etc.)""" - version = '1.0' - description = '`lsattr` command parser' - author = 'Mark Rotner' - author_email = 'rotner.mr@gmail.com' - compatible = ['linux'] - magic_commands = ['lsattr'] - tags = ['command'] - - -__version__ = info.version - - -ERROR_PREFIX = "lsattr:" - -# https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 -# https://github.com/landley/toybox/blob/f1682dc79fd75f64042b5438918fe5a507977e1c/toys/other/lsattr.c#L97 -ATTRIBUTES = { - "B": "compressed_file", - "Z": "compressed_dirty_file", - "X": "compression_raw_access", - "s": "secure_deletion", - "u": "undelete", - "S": "synchronous_updates", - "D": "synchronous_directory_updates", - "i": "immutable", - "a": "append_only", - "d": "no_dump", - "A": "no_atime", - "c": "compression_requested", - "E": "encrypted", - "j": "journaled_data", - "I": "indexed_directory", - "t": "no_tailmerging", - "T": "top_of_directory_hierarchies", - "e": "extents", - "C": "no_cow", - "F": "casefold", - "N": "inline_data", - "P": "project_hierarchy", - "V": "verity", -} - - -def parse( - data: str, - raw: bool = False, - quiet: bool = False -) -> List[JSONDictType]: - """ - Main text parsing function - - Parameters: - - data: (string) text data to parse - quiet: (boolean) suppress warning messages if True - - Returns: - - List of Dictionaries. Raw or processed structured data. - """ - jc.utils.compatibility(__name__, info.compatible, quiet) - jc.utils.input_type_check(data) - - output: List = [] - - cleandata = list(filter(None, data.splitlines())) - - if not jc.utils.has_data(data): - return output - - for line in cleandata: - # -R flag returns the output in the format: - # Folder: - # attributes file_in_folder - if line.endswith(':'): - continue - - # lsattr: Operation not supported .... - if line.startswith(ERROR_PREFIX): - continue - - line_output: Dict = {} - - # attributes file - # --------------e----- /etc/passwd - attributes, file = line.split() - line_output['file'] = file - for attribute in list(attributes): - attribute_key = ATTRIBUTES.get(attribute) - if attribute_key: - line_output[attribute_key] = True - - if line_output: - output.append(line_output) - - return output +r"""jc - JSON Convert `lsattr` command output parser + +Usage (cli): + + $ lsattr | jc --lsattr + +or + + $ jc lsattr + +Usage (module): + + import jc + result = jc.parse('lsattr', lsattr_command_output) + +Schema: + +Information from https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 +used to define field names + + [ + { + "file": string, + "compressed_file": Optional[boolean], + "compressed_dirty_file": Optional[boolean], + "compression_raw_access": Optional[boolean], + "secure_deletion": Optional[boolean], + "undelete": Optional[boolean], + "synchronous_updates": Optional[boolean], + "synchronous_directory_updates": Optional[boolean], + "immutable": Optional[boolean], + "append_only": Optional[boolean], + "no_dump": Optional[boolean], + "no_atime": Optional[boolean], + "compression_requested": Optional[boolean], + "encrypted": Optional[boolean], + "journaled_data": Optional[boolean], + "indexed_directory": Optional[boolean], + "no_tailmerging": Optional[boolean], + "top_of_directory_hierarchies": Optional[boolean], + "extents": Optional[boolean], + "no_cow": Optional[boolean], + "casefold": Optional[boolean], + "inline_data": Optional[boolean], + "project_hierarchy": Optional[boolean], + "verity": Optional[boolean], + } + ] + +Examples: + + $ sudo lsattr /etc/passwd | jc --lsattr + [ + { + "file": "/etc/passwd", + "extents": true + } + ] +""" +from typing import List, Dict +from jc.jc_types import JSONDictType +import jc.utils + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`lsattr` command parser' + author = 'Mark Rotner' + author_email = 'rotner.mr@gmail.com' + compatible = ['linux'] + magic_commands = ['lsattr'] + tags = ['command'] + + +__version__ = info.version + + +ERROR_PREFIX = "lsattr:" + +# https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/e2fsprogs/e2fs_lib.c#L40 +# https://github.com/landley/toybox/blob/f1682dc79fd75f64042b5438918fe5a507977e1c/toys/other/lsattr.c#L97 +ATTRIBUTES = { + "B": "compressed_file", + "Z": "compressed_dirty_file", + "X": "compression_raw_access", + "s": "secure_deletion", + "u": "undelete", + "S": "synchronous_updates", + "D": "synchronous_directory_updates", + "i": "immutable", + "a": "append_only", + "d": "no_dump", + "A": "no_atime", + "c": "compression_requested", + "E": "encrypted", + "j": "journaled_data", + "I": "indexed_directory", + "t": "no_tailmerging", + "T": "top_of_directory_hierarchies", + "e": "extents", + "C": "no_cow", + "F": "casefold", + "N": "inline_data", + "P": "project_hierarchy", + "V": "verity", +} + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[JSONDictType]: + """ + Main text parsing function + + Parameters: + + data: (string) text data to parse + quiet: (boolean) suppress warning messages if True + + Returns: + + List of Dictionaries. Raw or processed structured data. + """ + jc.utils.compatibility(__name__, info.compatible, quiet) + jc.utils.input_type_check(data) + + output: List = [] + + cleandata = list(filter(None, data.splitlines())) + + if not jc.utils.has_data(data): + return output + + for line in cleandata: + # -R flag returns the output in the format: + # Folder: + # attributes file_in_folder + if line.endswith(':'): + continue + + # lsattr: Operation not supported .... + if line.startswith(ERROR_PREFIX): + continue + + line_output: Dict = {} + + # attributes file + # --------------e----- /etc/passwd + attributes, file = line.split() + line_output['file'] = file + for attribute in list(attributes): + attribute_key = ATTRIBUTES.get(attribute) + if attribute_key: + line_output[attribute_key] = True + + if line_output: + output.append(line_output) + + return output diff --git a/jc/parsers/lsb_release.py b/jc/parsers/lsb_release.py index 0d1d8e64..ed7540fa 100644 --- a/jc/parsers/lsb_release.py +++ b/jc/parsers/lsb_release.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsb_release` command parser +r"""jc - JSON Convert `lsb_release` command parser This parser is an alias to the Key/Value parser (`--kv`). diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 7276711c..f25e0e02 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsblk` command output parser +r"""jc - JSON Convert `lsblk` command output parser Usage (cli): diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index b4b65d05..e794a8af 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsmod` command output parser +r"""jc - JSON Convert `lsmod` command output parser Usage (cli): diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index 0fc434ae..03abbdc0 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsof` command output parser +r"""jc - JSON Convert `lsof` command output parser Usage (cli): diff --git a/jc/parsers/lspci.py b/jc/parsers/lspci.py index 771fe38a..b47c38eb 100644 --- a/jc/parsers/lspci.py +++ b/jc/parsers/lspci.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lspci -mmv` command output parser +r"""jc - JSON Convert `lspci -mmv` command output parser This parser supports the following `lspci` options: - `-mmv` diff --git a/jc/parsers/lsusb.py b/jc/parsers/lsusb.py index 075c7fc0..86ec6953 100644 --- a/jc/parsers/lsusb.py +++ b/jc/parsers/lsusb.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `lsusb` command output parser +r"""jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. diff --git a/jc/parsers/m3u.py b/jc/parsers/m3u.py index 76fbb4d3..f5b0f5b1 100644 --- a/jc/parsers/m3u.py +++ b/jc/parsers/m3u.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert M3U and M3U8 file parser +r"""jc - JSON Convert M3U and M3U8 file parser This parser will make a best-effort to parse extended field information. If the extended fields cannot be successfully parsed, then an `unparsed_info` diff --git a/jc/parsers/mdadm.py b/jc/parsers/mdadm.py index 852911ae..70744a30 100644 --- a/jc/parsers/mdadm.py +++ b/jc/parsers/mdadm.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mdadm` command output parser +r"""jc - JSON Convert `mdadm` command output parser Supports the `--query` and `--examine` options in `mdadm`. diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index 945ed81a..c2297130 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mount` command output parser +r"""jc - JSON Convert `mount` command output parser Usage (cli): diff --git a/jc/parsers/mpstat.py b/jc/parsers/mpstat.py index a89c940d..40184fc5 100644 --- a/jc/parsers/mpstat.py +++ b/jc/parsers/mpstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mpstat` command output parser +r"""jc - JSON Convert `mpstat` command output parser > Note: Latest versions of `mpstat` support JSON output (v11.5.1+) diff --git a/jc/parsers/mpstat_s.py b/jc/parsers/mpstat_s.py index 3a746f2b..c35493a7 100644 --- a/jc/parsers/mpstat_s.py +++ b/jc/parsers/mpstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `mpstat` command output streaming parser +r"""jc - JSON Convert `mpstat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/needrestart.py b/jc/parsers/needrestart.py index c76983fd..c64f1cc2 100644 --- a/jc/parsers/needrestart.py +++ b/jc/parsers/needrestart.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `needrestart -b` command output parser +r"""jc - JSON Convert `needrestart -b` command output parser Usage (cli): diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index df715541..50c82b00 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `netstat` command output parser +r"""jc - JSON Convert `netstat` command output parser Caveats: - Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`) diff --git a/jc/parsers/netstat_freebsd_osx.py b/jc/parsers/netstat_freebsd_osx.py index eb610ea8..9eeb9e8d 100644 --- a/jc/parsers/netstat_freebsd_osx.py +++ b/jc/parsers/netstat_freebsd_osx.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert FreeBSD and OSX netstat Parser""" +r"""jc - JSON Convert FreeBSD and OSX netstat Parser""" def normalize_headers(header): diff --git a/jc/parsers/netstat_linux.py b/jc/parsers/netstat_linux.py index 322fcab8..222f2944 100644 --- a/jc/parsers/netstat_linux.py +++ b/jc/parsers/netstat_linux.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Linux netstat Parser""" +r"""jc - JSON Convert Linux netstat Parser""" import string diff --git a/jc/parsers/netstat_windows.py b/jc/parsers/netstat_windows.py index 835bc163..a14f57d8 100644 --- a/jc/parsers/netstat_windows.py +++ b/jc/parsers/netstat_windows.py @@ -1,4 +1,4 @@ -""" +r""" jc - JSON Convert Windows `netstat` command output parser """ diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py index 25572eb9..4779725a 100644 --- a/jc/parsers/nmcli.py +++ b/jc/parsers/nmcli.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `nmcli` command output parser +r"""jc - JSON Convert `nmcli` command output parser Supports the following `nmcli` subcommands: - `nmcli general` diff --git a/jc/parsers/nsd_control.py b/jc/parsers/nsd_control.py index 55ef7bd2..fd80e950 100644 --- a/jc/parsers/nsd_control.py +++ b/jc/parsers/nsd_control.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `nsd-control` command output parser +r"""jc - JSON Convert `nsd-control` command output parser Usage (cli): @@ -58,7 +58,6 @@ Examples: } } ] - """ from typing import List, Dict import jc.utils diff --git a/jc/parsers/ntpq.py b/jc/parsers/ntpq.py index ab5740e9..fc75b65f 100644 --- a/jc/parsers/ntpq.py +++ b/jc/parsers/ntpq.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ntpq -p` command output parser +r"""jc - JSON Convert `ntpq -p` command output parser Usage (cli): diff --git a/jc/parsers/openvpn.py b/jc/parsers/openvpn.py index 2aa3f1ad..2917024f 100644 --- a/jc/parsers/openvpn.py +++ b/jc/parsers/openvpn.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert openvpn-status.log file parser +r"""jc - JSON Convert openvpn-status.log file parser The `*_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/os_prober.py b/jc/parsers/os_prober.py index 94de1f5f..a97f15db 100644 --- a/jc/parsers/os_prober.py +++ b/jc/parsers/os_prober.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `os-prober` command output parser +r"""jc - JSON Convert `os-prober` command output parser Usage (cli): diff --git a/jc/parsers/os_release.py b/jc/parsers/os_release.py index b7065a34..2cbf1b63 100644 --- a/jc/parsers/os_release.py +++ b/jc/parsers/os_release.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/os-release` file parser +r"""jc - JSON Convert `/etc/os-release` file parser This parser is an alias to the Key/Value parser (`--kv`). diff --git a/jc/parsers/passwd.py b/jc/parsers/passwd.py index 523e5d52..3ed40735 100644 --- a/jc/parsers/passwd.py +++ b/jc/parsers/passwd.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/passwd` file Parser +r"""jc - JSON Convert `/etc/passwd` file Parser Usage (cli): diff --git a/jc/parsers/path.py b/jc/parsers/path.py index 9596bb09..c556bd9f 100644 --- a/jc/parsers/path.py +++ b/jc/parsers/path.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert POSIX path string parser +r"""jc - JSON Convert POSIX path string parser Parse a POSIX path. diff --git a/jc/parsers/path_list.py b/jc/parsers/path_list.py index 09095ed5..61763187 100644 --- a/jc/parsers/path_list.py +++ b/jc/parsers/path_list.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert POSIX path list string parser +r"""jc - JSON Convert POSIX path list string parser Parse a colon-separated POSIX path list, commonly found in environment variables. @@ -59,7 +59,6 @@ Examples: ] } ] - """ import jc.parsers.path as path diff --git a/jc/parsers/pci_ids.py b/jc/parsers/pci_ids.py index 2deb4031..7d7bbba3 100644 --- a/jc/parsers/pci_ids.py +++ b/jc/parsers/pci_ids.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pci.ids` file parser +r"""jc - JSON Convert `pci.ids` file parser This parser converts the pci.ids database file. diff --git a/jc/parsers/pgpass.py b/jc/parsers/pgpass.py index 409b2c2d..02b0134f 100644 --- a/jc/parsers/pgpass.py +++ b/jc/parsers/pgpass.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert PostgreSQL password file parser +r"""jc - JSON Convert PostgreSQL password file parser Usage (cli): diff --git a/jc/parsers/pidstat.py b/jc/parsers/pidstat.py index 29ac3aea..db480e3d 100644 --- a/jc/parsers/pidstat.py +++ b/jc/parsers/pidstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pidstat -H` command output parser +r"""jc - JSON Convert `pidstat -H` command output parser Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`. All other `pidstat` options are supported in combination with this option. diff --git a/jc/parsers/pidstat_s.py b/jc/parsers/pidstat_s.py index c347a13a..3a4d6e3f 100644 --- a/jc/parsers/pidstat_s.py +++ b/jc/parsers/pidstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pidstat -H` command output streaming parser +r"""jc - JSON Convert `pidstat -H` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index 624e6739..6adf338b 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ping` command output parser +r"""jc - JSON Convert `ping` command output parser Supports `ping` and `ping6` output. diff --git a/jc/parsers/ping_s.py b/jc/parsers/ping_s.py index 6cb7220f..8178f2d7 100644 --- a/jc/parsers/ping_s.py +++ b/jc/parsers/ping_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ping` command output streaming parser +r"""jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index 7bafeec2..2135936e 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pip-list` command output parser +r"""jc - JSON Convert `pip-list` command output parser Usage (cli): diff --git a/jc/parsers/pip_show.py b/jc/parsers/pip_show.py index 8d12ebd8..c3d9d9e8 100644 --- a/jc/parsers/pip_show.py +++ b/jc/parsers/pip_show.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `pip-show` command output parser +r"""jc - JSON Convert `pip-show` command output parser Usage (cli): diff --git a/jc/parsers/pkg_index_apk.py b/jc/parsers/pkg_index_apk.py index 3dd228dd..916a8ef5 100644 --- a/jc/parsers/pkg_index_apk.py +++ b/jc/parsers/pkg_index_apk.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Alpine Linux Package Index files +r"""jc - JSON Convert Alpine Linux Package Index files Usage (cli): diff --git a/jc/parsers/pkg_index_deb.py b/jc/parsers/pkg_index_deb.py index f5208f5f..5c9f1d28 100644 --- a/jc/parsers/pkg_index_deb.py +++ b/jc/parsers/pkg_index_deb.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Debian Package Index file parser +r"""jc - JSON Convert Debian Package Index file parser Usage (cli): diff --git a/jc/parsers/plist.py b/jc/parsers/plist.py index f7cd5514..e2c49eb9 100644 --- a/jc/parsers/plist.py +++ b/jc/parsers/plist.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert PLIST file parser +r"""jc - JSON Convert PLIST file parser Converts binary, XML, and NeXTSTEP PLIST files. diff --git a/jc/parsers/postconf.py b/jc/parsers/postconf.py index c4678fe0..ee83c660 100644 --- a/jc/parsers/postconf.py +++ b/jc/parsers/postconf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `postconf -M` command output parser +r"""jc - JSON Convert `postconf -M` command output parser Usage (cli): diff --git a/jc/parsers/proc.py b/jc/parsers/proc.py index 39bfe029..92b667ae 100644 --- a/jc/parsers/proc.py +++ b/jc/parsers/proc.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Proc file output parser +r"""jc - JSON Convert Proc file output parser This parser automatically identifies the Proc file and calls the corresponding parser to perform the parsing. diff --git a/jc/parsers/proc_buddyinfo.py b/jc/parsers/proc_buddyinfo.py index 8262ca45..8bb22b3e 100644 --- a/jc/parsers/proc_buddyinfo.py +++ b/jc/parsers/proc_buddyinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/buddyinfo` file parser +r"""jc - JSON Convert `/proc/buddyinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_cmdline.py b/jc/parsers/proc_cmdline.py index d4bf3d4f..287cac8b 100644 --- a/jc/parsers/proc_cmdline.py +++ b/jc/parsers/proc_cmdline.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/cmdline` file parser +r"""jc - JSON Convert `/proc/cmdline` file parser Usage (cli): diff --git a/jc/parsers/proc_consoles.py b/jc/parsers/proc_consoles.py index 3d8a95be..095f94d5 100644 --- a/jc/parsers/proc_consoles.py +++ b/jc/parsers/proc_consoles.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/consoles` file parser +r"""jc - JSON Convert `/proc/consoles` file parser Usage (cli): diff --git a/jc/parsers/proc_cpuinfo.py b/jc/parsers/proc_cpuinfo.py index e7628e65..4355941f 100644 --- a/jc/parsers/proc_cpuinfo.py +++ b/jc/parsers/proc_cpuinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/cpuinfo` file parser +r"""jc - JSON Convert `/proc/cpuinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_crypto.py b/jc/parsers/proc_crypto.py index 76b270c5..7f392f35 100644 --- a/jc/parsers/proc_crypto.py +++ b/jc/parsers/proc_crypto.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/crypto` file parser +r"""jc - JSON Convert `/proc/crypto` file parser Usage (cli): diff --git a/jc/parsers/proc_devices.py b/jc/parsers/proc_devices.py index 20c2d1a5..63bf6a0d 100644 --- a/jc/parsers/proc_devices.py +++ b/jc/parsers/proc_devices.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/devices` file parser +r"""jc - JSON Convert `/proc/devices` file parser Usage (cli): diff --git a/jc/parsers/proc_diskstats.py b/jc/parsers/proc_diskstats.py index 1067f869..78686d33 100644 --- a/jc/parsers/proc_diskstats.py +++ b/jc/parsers/proc_diskstats.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/diskstats` file parser +r"""jc - JSON Convert `/proc/diskstats` file parser Usage (cli): diff --git a/jc/parsers/proc_driver_rtc.py b/jc/parsers/proc_driver_rtc.py index 8356755b..292649f3 100644 --- a/jc/parsers/proc_driver_rtc.py +++ b/jc/parsers/proc_driver_rtc.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/driver/rtc` file parser +r"""jc - JSON Convert `/proc/driver/rtc` file parser Usage (cli): diff --git a/jc/parsers/proc_filesystems.py b/jc/parsers/proc_filesystems.py index 2e079b98..2ed7b1d8 100644 --- a/jc/parsers/proc_filesystems.py +++ b/jc/parsers/proc_filesystems.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/filesystems` file parser +r"""jc - JSON Convert `/proc/filesystems` file parser Usage (cli): diff --git a/jc/parsers/proc_interrupts.py b/jc/parsers/proc_interrupts.py index 376c053e..acdd0615 100644 --- a/jc/parsers/proc_interrupts.py +++ b/jc/parsers/proc_interrupts.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/interrupts` file parser +r"""jc - JSON Convert `/proc/interrupts` file parser Usage (cli): diff --git a/jc/parsers/proc_iomem.py b/jc/parsers/proc_iomem.py index 9d4b2766..c0a18d1d 100644 --- a/jc/parsers/proc_iomem.py +++ b/jc/parsers/proc_iomem.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/iomem` file parser +r"""jc - JSON Convert `/proc/iomem` file parser Usage (cli): diff --git a/jc/parsers/proc_ioports.py b/jc/parsers/proc_ioports.py index bac1c563..128dbaa7 100644 --- a/jc/parsers/proc_ioports.py +++ b/jc/parsers/proc_ioports.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/ioports` file parser +r"""jc - JSON Convert `/proc/ioports` file parser Usage (cli): diff --git a/jc/parsers/proc_loadavg.py b/jc/parsers/proc_loadavg.py index 9247a41b..2ad3146f 100644 --- a/jc/parsers/proc_loadavg.py +++ b/jc/parsers/proc_loadavg.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/loadavg` file parser +r"""jc - JSON Convert `/proc/loadavg` file parser Usage (cli): diff --git a/jc/parsers/proc_locks.py b/jc/parsers/proc_locks.py index 01e8a3ca..8c9e95e5 100644 --- a/jc/parsers/proc_locks.py +++ b/jc/parsers/proc_locks.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/locks` file parser +r"""jc - JSON Convert `/proc/locks` file parser Usage (cli): diff --git a/jc/parsers/proc_meminfo.py b/jc/parsers/proc_meminfo.py index d8ddce64..6181747c 100644 --- a/jc/parsers/proc_meminfo.py +++ b/jc/parsers/proc_meminfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/meminfo` file parser +r"""jc - JSON Convert `/proc/meminfo` file parser Usage (cli): diff --git a/jc/parsers/proc_modules.py b/jc/parsers/proc_modules.py index 472c389a..17c4ad3a 100644 --- a/jc/parsers/proc_modules.py +++ b/jc/parsers/proc_modules.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/modules` file parser +r"""jc - JSON Convert `/proc/modules` file parser Usage (cli): diff --git a/jc/parsers/proc_mtrr.py b/jc/parsers/proc_mtrr.py index fbeae40b..29195a54 100644 --- a/jc/parsers/proc_mtrr.py +++ b/jc/parsers/proc_mtrr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/mtrr` file parser +r"""jc - JSON Convert `/proc/mtrr` file parser Usage (cli): diff --git a/jc/parsers/proc_net_arp.py b/jc/parsers/proc_net_arp.py index 47dfa623..1ae44733 100644 --- a/jc/parsers/proc_net_arp.py +++ b/jc/parsers/proc_net_arp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/arp` file parser +r"""jc - JSON Convert `/proc/net/arp` file parser Usage (cli): diff --git a/jc/parsers/proc_net_dev.py b/jc/parsers/proc_net_dev.py index 14cf4af6..9c584fbf 100644 --- a/jc/parsers/proc_net_dev.py +++ b/jc/parsers/proc_net_dev.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/dev` file parser +r"""jc - JSON Convert `/proc/net/dev` file parser Usage (cli): diff --git a/jc/parsers/proc_net_dev_mcast.py b/jc/parsers/proc_net_dev_mcast.py index 3984f341..e585e6d2 100644 --- a/jc/parsers/proc_net_dev_mcast.py +++ b/jc/parsers/proc_net_dev_mcast.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/dev_mcast` file parser +r"""jc - JSON Convert `/proc/net/dev_mcast` file parser Usage (cli): diff --git a/jc/parsers/proc_net_if_inet6.py b/jc/parsers/proc_net_if_inet6.py index a2e3d11e..ea5d1b5a 100644 --- a/jc/parsers/proc_net_if_inet6.py +++ b/jc/parsers/proc_net_if_inet6.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/if_inet6` file parser +r"""jc - JSON Convert `/proc/net/if_inet6` file parser Usage (cli): diff --git a/jc/parsers/proc_net_igmp.py b/jc/parsers/proc_net_igmp.py index d4f26b7d..ff1b7aa8 100644 --- a/jc/parsers/proc_net_igmp.py +++ b/jc/parsers/proc_net_igmp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/igmp` file parser +r"""jc - JSON Convert `/proc/net/igmp` file parser Usage (cli): diff --git a/jc/parsers/proc_net_igmp6.py b/jc/parsers/proc_net_igmp6.py index a1640959..594042f0 100644 --- a/jc/parsers/proc_net_igmp6.py +++ b/jc/parsers/proc_net_igmp6.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/igmp6` file parser +r"""jc - JSON Convert `/proc/net/igmp6` file parser Usage (cli): diff --git a/jc/parsers/proc_net_ipv6_route.py b/jc/parsers/proc_net_ipv6_route.py index b9643a8f..123ae176 100644 --- a/jc/parsers/proc_net_ipv6_route.py +++ b/jc/parsers/proc_net_ipv6_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/ipv6_route` file parser +r"""jc - JSON Convert `/proc/net/ipv6_route` file parser Usage (cli): diff --git a/jc/parsers/proc_net_netlink.py b/jc/parsers/proc_net_netlink.py index 31a8deb6..037af0b1 100644 --- a/jc/parsers/proc_net_netlink.py +++ b/jc/parsers/proc_net_netlink.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/netlink` file parser +r"""jc - JSON Convert `/proc/net/netlink` file parser Usage (cli): diff --git a/jc/parsers/proc_net_netstat.py b/jc/parsers/proc_net_netstat.py index d7ae90a7..7d769227 100644 --- a/jc/parsers/proc_net_netstat.py +++ b/jc/parsers/proc_net_netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/netstat` file parser +r"""jc - JSON Convert `/proc/net/netstat` file parser Usage (cli): diff --git a/jc/parsers/proc_net_packet.py b/jc/parsers/proc_net_packet.py index c2945171..fdff3b3e 100644 --- a/jc/parsers/proc_net_packet.py +++ b/jc/parsers/proc_net_packet.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/packet` file parser +r"""jc - JSON Convert `/proc/net/packet` file parser Usage (cli): diff --git a/jc/parsers/proc_net_protocols.py b/jc/parsers/proc_net_protocols.py index 11a136dd..b04fd47f 100644 --- a/jc/parsers/proc_net_protocols.py +++ b/jc/parsers/proc_net_protocols.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/protocols` file parser +r"""jc - JSON Convert `/proc/net/protocols` file parser Usage (cli): diff --git a/jc/parsers/proc_net_route.py b/jc/parsers/proc_net_route.py index ff7e41d7..ffac2bb8 100644 --- a/jc/parsers/proc_net_route.py +++ b/jc/parsers/proc_net_route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/route` file parser +r"""jc - JSON Convert `/proc/net/route` file parser Usage (cli): diff --git a/jc/parsers/proc_net_tcp.py b/jc/parsers/proc_net_tcp.py index 6b504f7e..4f687e26 100644 --- a/jc/parsers/proc_net_tcp.py +++ b/jc/parsers/proc_net_tcp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser +r"""jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser IPv4 and IPv6 addresses are converted to standard notation unless the raw (--raw) option is used. diff --git a/jc/parsers/proc_net_unix.py b/jc/parsers/proc_net_unix.py index db1f5338..dc51afd5 100644 --- a/jc/parsers/proc_net_unix.py +++ b/jc/parsers/proc_net_unix.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/net/unix` file parser +r"""jc - JSON Convert `/proc/net/unix` file parser Usage (cli): diff --git a/jc/parsers/proc_pagetypeinfo.py b/jc/parsers/proc_pagetypeinfo.py index 92a0ed26..f14458e9 100644 --- a/jc/parsers/proc_pagetypeinfo.py +++ b/jc/parsers/proc_pagetypeinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/pagetypeinfo` file parser +r"""jc - JSON Convert `/proc/pagetypeinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_partitions.py b/jc/parsers/proc_partitions.py index 6afbeda0..494acff9 100644 --- a/jc/parsers/proc_partitions.py +++ b/jc/parsers/proc_partitions.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/partitions` file parser +r"""jc - JSON Convert `/proc/partitions` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_fdinfo.py b/jc/parsers/proc_pid_fdinfo.py index d86d6ec3..48cbfeae 100644 --- a/jc/parsers/proc_pid_fdinfo.py +++ b/jc/parsers/proc_pid_fdinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//fdinfo/` file parser +r"""jc - JSON Convert `/proc//fdinfo/` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_io.py b/jc/parsers/proc_pid_io.py index c450302d..a2fda8a8 100644 --- a/jc/parsers/proc_pid_io.py +++ b/jc/parsers/proc_pid_io.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//io` file parser +r"""jc - JSON Convert `/proc//io` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_maps.py b/jc/parsers/proc_pid_maps.py index e51c0fed..28ca6567 100644 --- a/jc/parsers/proc_pid_maps.py +++ b/jc/parsers/proc_pid_maps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//maps` file parser +r"""jc - JSON Convert `/proc//maps` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_mountinfo.py b/jc/parsers/proc_pid_mountinfo.py index 5b43bc94..3d55fb1d 100644 --- a/jc/parsers/proc_pid_mountinfo.py +++ b/jc/parsers/proc_pid_mountinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//mountinfo` file parser +r"""jc - JSON Convert `/proc//mountinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_numa_maps.py b/jc/parsers/proc_pid_numa_maps.py index 2210d401..a9ebc3d4 100644 --- a/jc/parsers/proc_pid_numa_maps.py +++ b/jc/parsers/proc_pid_numa_maps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//numa_maps` file parser +r"""jc - JSON Convert `/proc//numa_maps` file parser This parser will attempt to convert number values to integers. If that is not desired, please use the `--raw` option (cli) or `raw=True` argument diff --git a/jc/parsers/proc_pid_smaps.py b/jc/parsers/proc_pid_smaps.py index e20c3882..d7be98fc 100644 --- a/jc/parsers/proc_pid_smaps.py +++ b/jc/parsers/proc_pid_smaps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//smaps` file parser +r"""jc - JSON Convert `/proc//smaps` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_stat.py b/jc/parsers/proc_pid_stat.py index 76e489e2..4e83a707 100644 --- a/jc/parsers/proc_pid_stat.py +++ b/jc/parsers/proc_pid_stat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//stat` file parser +r"""jc - JSON Convert `/proc//stat` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_statm.py b/jc/parsers/proc_pid_statm.py index a1cd2f42..eae5b5ea 100644 --- a/jc/parsers/proc_pid_statm.py +++ b/jc/parsers/proc_pid_statm.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//statm` file parser +r"""jc - JSON Convert `/proc//statm` file parser Usage (cli): diff --git a/jc/parsers/proc_pid_status.py b/jc/parsers/proc_pid_status.py index aae91e2f..abd0bd7a 100644 --- a/jc/parsers/proc_pid_status.py +++ b/jc/parsers/proc_pid_status.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc//status` file parser +r"""jc - JSON Convert `/proc//status` file parser Usage (cli): diff --git a/jc/parsers/proc_slabinfo.py b/jc/parsers/proc_slabinfo.py index 15488281..630e31bd 100644 --- a/jc/parsers/proc_slabinfo.py +++ b/jc/parsers/proc_slabinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/slabinfo` file parser +r"""jc - JSON Convert `/proc/slabinfo` file parser Usage (cli): diff --git a/jc/parsers/proc_softirqs.py b/jc/parsers/proc_softirqs.py index cac25ae9..cd5c7ad1 100644 --- a/jc/parsers/proc_softirqs.py +++ b/jc/parsers/proc_softirqs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/softirqs` file parser +r"""jc - JSON Convert `/proc/softirqs` file parser Usage (cli): diff --git a/jc/parsers/proc_stat.py b/jc/parsers/proc_stat.py index a09f67e9..f25f5a0f 100644 --- a/jc/parsers/proc_stat.py +++ b/jc/parsers/proc_stat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/stat` file parser +r"""jc - JSON Convert `/proc/stat` file parser Usage (cli): diff --git a/jc/parsers/proc_swaps.py b/jc/parsers/proc_swaps.py index 97269f4b..b1a3f94b 100644 --- a/jc/parsers/proc_swaps.py +++ b/jc/parsers/proc_swaps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/swaps` file parser +r"""jc - JSON Convert `/proc/swaps` file parser Usage (cli): diff --git a/jc/parsers/proc_uptime.py b/jc/parsers/proc_uptime.py index c3207e47..a00ea498 100644 --- a/jc/parsers/proc_uptime.py +++ b/jc/parsers/proc_uptime.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/uptime` file parser +r"""jc - JSON Convert `/proc/uptime` file parser Usage (cli): diff --git a/jc/parsers/proc_version.py b/jc/parsers/proc_version.py index e0fc4626..8d0c59c3 100644 --- a/jc/parsers/proc_version.py +++ b/jc/parsers/proc_version.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/version` file parser +r"""jc - JSON Convert `/proc/version` file parser > Note: This parser will parse `/proc/version` files that follow the > common format used by most popular linux distributions. diff --git a/jc/parsers/proc_vmallocinfo.py b/jc/parsers/proc_vmallocinfo.py index 4001830e..35545e21 100644 --- a/jc/parsers/proc_vmallocinfo.py +++ b/jc/parsers/proc_vmallocinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/vmallocinfo` file parser +r"""jc - JSON Convert `/proc/vmallocinfo` file parser This parser will attempt to convert number values to integers. If that is not desired, please use the `--raw` option (cli) or `raw=True` argument diff --git a/jc/parsers/proc_vmstat.py b/jc/parsers/proc_vmstat.py index 522f04ba..8298af6e 100644 --- a/jc/parsers/proc_vmstat.py +++ b/jc/parsers/proc_vmstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/vmstat` file parser +r"""jc - JSON Convert `/proc/vmstat` file parser Usage (cli): diff --git a/jc/parsers/proc_zoneinfo.py b/jc/parsers/proc_zoneinfo.py index 77688b3b..cfc30b07 100644 --- a/jc/parsers/proc_zoneinfo.py +++ b/jc/parsers/proc_zoneinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/proc/zoneinfo` file parser +r"""jc - JSON Convert `/proc/zoneinfo` file parser Usage (cli): diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index 11ef2f90..493fc015 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ps` command output parser +r"""jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` diff --git a/jc/parsers/resolve_conf.py b/jc/parsers/resolve_conf.py index 82f22129..5de046e2 100644 --- a/jc/parsers/resolve_conf.py +++ b/jc/parsers/resolve_conf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/resolve.conf` file parser +r"""jc - JSON Convert `/etc/resolve.conf` file parser This parser may be more forgiving than the system parser. For example, if multiple `search` lists are defined, this parser will append all entries to diff --git a/jc/parsers/route.py b/jc/parsers/route.py index d6ae5a42..17b7eff6 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `route` command output parser +r"""jc - JSON Convert `route` command output parser Usage (cli): diff --git a/jc/parsers/route_windows.py b/jc/parsers/route_windows.py index 46a8cbf7..a653f03b 100644 --- a/jc/parsers/route_windows.py +++ b/jc/parsers/route_windows.py @@ -1,4 +1,4 @@ -""" +r""" jc - JSON Convert Windows `route` command output parser """ diff --git a/jc/parsers/rpm_qi.py b/jc/parsers/rpm_qi.py index 046ad003..e48fb731 100644 --- a/jc/parsers/rpm_qi.py +++ b/jc/parsers/rpm_qi.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `rpm -qi` command output parser +r"""jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. diff --git a/jc/parsers/rsync.py b/jc/parsers/rsync.py index 0a3fdede..195aae77 100644 --- a/jc/parsers/rsync.py +++ b/jc/parsers/rsync.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `rsync` command output parser +r"""jc - JSON Convert `rsync` command output parser Supports the `-i` or `--itemize-changes` options with all levels of verbosity. This parser will process the `STDOUT` output or a log file diff --git a/jc/parsers/rsync_s.py b/jc/parsers/rsync_s.py index f48c9888..4e80c4ef 100644 --- a/jc/parsers/rsync_s.py +++ b/jc/parsers/rsync_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `rsync` command output streaming parser +r"""jc - JSON Convert `rsync` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/semver.py b/jc/parsers/semver.py index 08e2f30e..eca78de8 100644 --- a/jc/parsers/semver.py +++ b/jc/parsers/semver.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Semantic Version string parser +r"""jc - JSON Convert Semantic Version string parser This parser conforms to the specification at https://semver.org/ diff --git a/jc/parsers/sfdisk.py b/jc/parsers/sfdisk.py index 365414c5..50de56dc 100644 --- a/jc/parsers/sfdisk.py +++ b/jc/parsers/sfdisk.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `sfdisk` command output parser +r"""jc - JSON Convert `sfdisk` command output parser Supports the following `sfdisk` options: - `-l` diff --git a/jc/parsers/shadow.py b/jc/parsers/shadow.py index 6b5c8dc4..def7fc74 100644 --- a/jc/parsers/shadow.py +++ b/jc/parsers/shadow.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/etc/shadow` file parser +r"""jc - JSON Convert `/etc/shadow` file parser Usage (cli): diff --git a/jc/parsers/srt.py b/jc/parsers/srt.py index ef89f5ae..08e278c8 100644 --- a/jc/parsers/srt.py +++ b/jc/parsers/srt.py @@ -1,281 +1,281 @@ -"""jc - JSON Convert `SRT` file parser - -Usage (cli): - - $ cat foo.srt | jc --srt - -Usage (module): - - import jc - result = jc.parse('srt', srt_file_output) - -Schema: - - [ - { - "index": int, - "start": { - "hours": int, - "minutes": int, - "seconds": int, - "milliseconds": int, - "timestamp": string - }, - "end": { - "hours": int, - "minutes": int, - "seconds": int, - "milliseconds": int, - "timestamp": string - }, - "content": string - } - ] - -Examples: - - $ cat attack_of_the_clones.srt - 1 - 00:02:16,612 --> 00:02:19,376 - Senator, we're making - our final approach into Coruscant. - - 2 - 00:02:19,482 --> 00:02:21,609 - Very good, Lieutenant. - ... - - $ cat attack_of_the_clones.srt | jc --srt - [ - { - "index": 1, - "start": { - "hours": 0, - "minutes": 2, - "seconds": 16, - "milliseconds": 612, - "timestamp": "00:02:16,612" - }, - "end": { - "hours": 0, - "minutes": 2, - "seconds": 19, - "milliseconds": 376, - "timestamp": "00:02:19,376" - }, - "content": "Senator, we're making\nour final approach into Coruscant." - }, - { - "index": 2, - "start": { - "hours": 0, - "minutes": 2, - "seconds": 19, - "milliseconds": 482, - "timestamp": "00:02:19,482" - }, - "end": { - "hours": 0, - "minutes": 2, - "seconds": 21, - "milliseconds": 609, - "timestamp": "00:02:21,609" - }, - "content": "Very good, Lieutenant." - }, - ... - ] -""" -import jc.utils -import re -from typing import List, Dict -from jc.jc_types import JSONDictType - - -class info(): - """Provides parser metadata (version, author, etc.)""" - version = '1.0' - description = 'SRT file parser' - author = 'Mark Rotner' - author_email = 'rotner.mr@gmail.com' - compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] - tags = ['standard', 'file', 'string'] - - -__version__ = info.version - -# Regex from https://github.com/cdown/srt/blob/434d0c1c9d5c26d5c3fb1ce979fc05b478e9253c/srt.py#LL16C1. - -# The MIT License - -# Copyright (c) 2014-present Christopher Down - -# 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. - -# The format: (int)index\n(timestamp)start --> (timestamp)end\n(str)content\n. -# Example: -# 1 -# 00:02:16,612 --> 00:02:19,376 -# Senator, we're making our final approach into Coruscant. - -# Start & End timestamp format: hours:minutes:seconds,millisecond. -# "." is not technically valid as a delimiter, but many editors create SRT -# files with this delimiter for whatever reason. Many editors and players -# accept it, so we do too. -RGX_TIMESTAMP_MAGNITUDE_DELIM = r"[,.:,.。:]" -RGX_POSITIVE_INT = r"[0-9]+" -RGX_POSITIVE_INT_OPTIONAL = r"[0-9]*" -RGX_TIMESTAMP = '{field}{separator}{field}{separator}{field}{separator}?{optional_field}'.format( - separator=RGX_TIMESTAMP_MAGNITUDE_DELIM, - field=RGX_POSITIVE_INT, - optional_field=RGX_POSITIVE_INT_OPTIONAL -) -RGX_INDEX = r"-?[0-9]+\.?[0-9]*" # int\float\negative. -RGX_CONTENT = r".*?" # Anything(except newline) but lazy. -RGX_NEWLINE = r"\r?\n" # Newline(CRLF\LF). -SRT_REGEX = re.compile( - r"\s*(?:({index})\s*{newline})?({ts}) *-[ -] *> *({ts}) ?(?:{newline}|\Z)({content})" - # Many sub editors don't add a blank line to the end, and many editors and - # players accept that. We allow it to be missing in input. - # - # We also allow subs that are missing a double blank newline. This often - # happens on subs which were first created as a mixed language subtitle, - # for example chs/eng, and then were stripped using naive methods (such as - # ed/sed) that don't understand newline preservation rules in SRT files. - # - # This means that when you are, say, only keeping chs, and the line only - # contains english, you end up with not only no content, but also all of - # the content lines are stripped instead of retaining a newline. - r"(?:{newline}|\Z)(?:{newline}|\Z|(?=(?:{index}\s*{newline}{ts})))" - # Some SRT blocks, while this is technically invalid, have blank lines - # inside the subtitle content. We look ahead a little to check that the - # next lines look like an index and a timestamp as a best-effort - # solution to work around these. - r"(?=(?:(?:{index}\s*{newline})?{ts}|\Z))".format( - index=RGX_INDEX, - ts=RGX_TIMESTAMP, - content=RGX_CONTENT, - newline=RGX_NEWLINE, - ), - re.DOTALL, -) -TIMESTAMP_REGEX = re.compile( - '^({field}){separator}({field}){separator}({field}){separator}?({optional_field})$'.format( - separator=RGX_TIMESTAMP_MAGNITUDE_DELIM, - field=RGX_POSITIVE_INT, - optional_field=RGX_POSITIVE_INT_OPTIONAL - ) -) - - -def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: - """ - Final processing to conform to the schema. - - Parameters: - - proc_data: (Dictionary) raw structured data to process - - Returns: - - List of Dictionaries representing an SRT document. - """ - - int_list = {'index'} - timestamp_list = {"start", "end"} - timestamp_int_list = {"hours", "minutes", "seconds", "milliseconds"} - - for entry in proc_data: - # Converting {"index"} to int. - for key in entry: - if key in int_list: - entry[key] = jc.utils.convert_to_int(entry[key]) - - # Converting {"hours", "minutes", "seconds", "milliseconds"} to int. - if key in timestamp_list: - timestamp = entry[key] - for timestamp_key in timestamp: - if timestamp_key in timestamp_int_list: - timestamp[timestamp_key] = jc.utils.convert_to_int( - timestamp[timestamp_key]) - - return proc_data - - -def parse_timestamp(timestamp: str) -> Dict: - """ - timestamp: "hours:minutes:seconds,milliseconds" ---> - { - "hours": "hours", - "minutes": "minutes", - "seconds": "seconds", - "milliseconds": "milliseconds", - "timestamp": "hours:minutes:seconds,milliseconds" - } - """ - ts_match = TIMESTAMP_REGEX.match(timestamp) - if ts_match: - hours, minutes, seconds, milliseconds = ts_match.groups() - return { - "hours": hours, - "minutes": minutes, - "seconds": seconds, - "milliseconds": milliseconds, - "timestamp": timestamp - } - return {} - - -def parse( - data: str, - raw: bool = False, - quiet: bool = False -) -> List[JSONDictType]: - """ - 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: - - Dictionary. Raw or processed structured data. - """ - jc.utils.compatibility(__name__, info.compatible, quiet) - jc.utils.input_type_check(data) - - raw_output: List[Dict] = [] - if not jc.utils.has_data(data): - return raw_output - - for subtitle in SRT_REGEX.finditer(data): - index, start, end, content = subtitle.groups() - raw_output.append( - { - "index": index, - "start": parse_timestamp(start), - "end": parse_timestamp(end), - "content": content.replace("\r\n", "\n") - } - ) - - return raw_output if raw else _process(raw_output) +r"""jc - JSON Convert `SRT` file parser + +Usage (cli): + + $ cat foo.srt | jc --srt + +Usage (module): + + import jc + result = jc.parse('srt', srt_file_output) + +Schema: + + [ + { + "index": int, + "start": { + "hours": int, + "minutes": int, + "seconds": int, + "milliseconds": int, + "timestamp": string + }, + "end": { + "hours": int, + "minutes": int, + "seconds": int, + "milliseconds": int, + "timestamp": string + }, + "content": string + } + ] + +Examples: + + $ cat attack_of_the_clones.srt + 1 + 00:02:16,612 --> 00:02:19,376 + Senator, we're making + our final approach into Coruscant. + + 2 + 00:02:19,482 --> 00:02:21,609 + Very good, Lieutenant. + ... + + $ cat attack_of_the_clones.srt | jc --srt + [ + { + "index": 1, + "start": { + "hours": 0, + "minutes": 2, + "seconds": 16, + "milliseconds": 612, + "timestamp": "00:02:16,612" + }, + "end": { + "hours": 0, + "minutes": 2, + "seconds": 19, + "milliseconds": 376, + "timestamp": "00:02:19,376" + }, + "content": "Senator, we're making\nour final approach into Coruscant." + }, + { + "index": 2, + "start": { + "hours": 0, + "minutes": 2, + "seconds": 19, + "milliseconds": 482, + "timestamp": "00:02:19,482" + }, + "end": { + "hours": 0, + "minutes": 2, + "seconds": 21, + "milliseconds": 609, + "timestamp": "00:02:21,609" + }, + "content": "Very good, Lieutenant." + }, + ... + ] +""" +import jc.utils +import re +from typing import List, Dict +from jc.jc_types import JSONDictType + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = 'SRT file parser' + author = 'Mark Rotner' + author_email = 'rotner.mr@gmail.com' + compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] + tags = ['standard', 'file', 'string'] + + +__version__ = info.version + +# Regex from https://github.com/cdown/srt/blob/434d0c1c9d5c26d5c3fb1ce979fc05b478e9253c/srt.py#LL16C1. + +# The MIT License + +# Copyright (c) 2014-present Christopher Down + +# 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. + +# The format: (int)index\n(timestamp)start --> (timestamp)end\n(str)content\n. +# Example: +# 1 +# 00:02:16,612 --> 00:02:19,376 +# Senator, we're making our final approach into Coruscant. + +# Start & End timestamp format: hours:minutes:seconds,millisecond. +# "." is not technically valid as a delimiter, but many editors create SRT +# files with this delimiter for whatever reason. Many editors and players +# accept it, so we do too. +RGX_TIMESTAMP_MAGNITUDE_DELIM = r"[,.:,.。:]" +RGX_POSITIVE_INT = r"[0-9]+" +RGX_POSITIVE_INT_OPTIONAL = r"[0-9]*" +RGX_TIMESTAMP = '{field}{separator}{field}{separator}{field}{separator}?{optional_field}'.format( + separator=RGX_TIMESTAMP_MAGNITUDE_DELIM, + field=RGX_POSITIVE_INT, + optional_field=RGX_POSITIVE_INT_OPTIONAL +) +RGX_INDEX = r"-?[0-9]+\.?[0-9]*" # int\float\negative. +RGX_CONTENT = r".*?" # Anything(except newline) but lazy. +RGX_NEWLINE = r"\r?\n" # Newline(CRLF\LF). +SRT_REGEX = re.compile( + r"\s*(?:({index})\s*{newline})?({ts}) *-[ -] *> *({ts}) ?(?:{newline}|\Z)({content})" + # Many sub editors don't add a blank line to the end, and many editors and + # players accept that. We allow it to be missing in input. + # + # We also allow subs that are missing a double blank newline. This often + # happens on subs which were first created as a mixed language subtitle, + # for example chs/eng, and then were stripped using naive methods (such as + # ed/sed) that don't understand newline preservation rules in SRT files. + # + # This means that when you are, say, only keeping chs, and the line only + # contains english, you end up with not only no content, but also all of + # the content lines are stripped instead of retaining a newline. + r"(?:{newline}|\Z)(?:{newline}|\Z|(?=(?:{index}\s*{newline}{ts})))" + # Some SRT blocks, while this is technically invalid, have blank lines + # inside the subtitle content. We look ahead a little to check that the + # next lines look like an index and a timestamp as a best-effort + # solution to work around these. + r"(?=(?:(?:{index}\s*{newline})?{ts}|\Z))".format( + index=RGX_INDEX, + ts=RGX_TIMESTAMP, + content=RGX_CONTENT, + newline=RGX_NEWLINE, + ), + re.DOTALL, +) +TIMESTAMP_REGEX = re.compile( + '^({field}){separator}({field}){separator}({field}){separator}?({optional_field})$'.format( + separator=RGX_TIMESTAMP_MAGNITUDE_DELIM, + field=RGX_POSITIVE_INT, + optional_field=RGX_POSITIVE_INT_OPTIONAL + ) +) + + +def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: + """ + Final processing to conform to the schema. + + Parameters: + + proc_data: (Dictionary) raw structured data to process + + Returns: + + List of Dictionaries representing an SRT document. + """ + + int_list = {'index'} + timestamp_list = {"start", "end"} + timestamp_int_list = {"hours", "minutes", "seconds", "milliseconds"} + + for entry in proc_data: + # Converting {"index"} to int. + for key in entry: + if key in int_list: + entry[key] = jc.utils.convert_to_int(entry[key]) + + # Converting {"hours", "minutes", "seconds", "milliseconds"} to int. + if key in timestamp_list: + timestamp = entry[key] + for timestamp_key in timestamp: + if timestamp_key in timestamp_int_list: + timestamp[timestamp_key] = jc.utils.convert_to_int( + timestamp[timestamp_key]) + + return proc_data + + +def parse_timestamp(timestamp: str) -> Dict: + """ + timestamp: "hours:minutes:seconds,milliseconds" ---> + { + "hours": "hours", + "minutes": "minutes", + "seconds": "seconds", + "milliseconds": "milliseconds", + "timestamp": "hours:minutes:seconds,milliseconds" + } + """ + ts_match = TIMESTAMP_REGEX.match(timestamp) + if ts_match: + hours, minutes, seconds, milliseconds = ts_match.groups() + return { + "hours": hours, + "minutes": minutes, + "seconds": seconds, + "milliseconds": milliseconds, + "timestamp": timestamp + } + return {} + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[JSONDictType]: + """ + 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: + + Dictionary. Raw or processed structured data. + """ + jc.utils.compatibility(__name__, info.compatible, quiet) + jc.utils.input_type_check(data) + + raw_output: List[Dict] = [] + if not jc.utils.has_data(data): + return raw_output + + for subtitle in SRT_REGEX.finditer(data): + index, start, end, content = subtitle.groups() + raw_output.append( + { + "index": index, + "start": parse_timestamp(start), + "end": parse_timestamp(end), + "content": content.replace("\r\n", "\n") + } + ) + + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/ss.py b/jc/parsers/ss.py index 20f7cb6b..502953fa 100644 --- a/jc/parsers/ss.py +++ b/jc/parsers/ss.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ss` command output parser +r"""jc - JSON Convert `ss` command output parser Usage (cli): diff --git a/jc/parsers/ssh_conf.py b/jc/parsers/ssh_conf.py index 95b2c7ec..771d93ef 100644 --- a/jc/parsers/ssh_conf.py +++ b/jc/parsers/ssh_conf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ssh` configuration file and `ssh -G` command output parser +r"""jc - JSON Convert `ssh` configuration file and `ssh -G` command output parser This parser will work with `ssh` configuration files or the output of `ssh -G`. Any `Match` blocks in the `ssh` configuration file will be diff --git a/jc/parsers/sshd_conf.py b/jc/parsers/sshd_conf.py index a295e237..9b57e0e5 100644 --- a/jc/parsers/sshd_conf.py +++ b/jc/parsers/sshd_conf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `sshd` configuration file and `sshd -T` command output parser +r"""jc - JSON Convert `sshd` configuration file and `sshd -T` command output parser This parser will work with `sshd` configuration files or the output of `sshd -T`. Any `Match` blocks in the `sshd` configuration file will be diff --git a/jc/parsers/stat.py b/jc/parsers/stat.py index 00040e04..20e9d585 100644 --- a/jc/parsers/stat.py +++ b/jc/parsers/stat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `stat` command output parser +r"""jc - JSON Convert `stat` command output parser The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/stat_s.py b/jc/parsers/stat_s.py index c3e1a0b4..b55c0db1 100644 --- a/jc/parsers/stat_s.py +++ b/jc/parsers/stat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `stat` command output streaming parser +r"""jc - JSON Convert `stat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/swapon.py b/jc/parsers/swapon.py index 180be925..8c4aabd1 100644 --- a/jc/parsers/swapon.py +++ b/jc/parsers/swapon.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `swapon` command output parser +r"""jc - JSON Convert `swapon` command output parser Usage (cli): diff --git a/jc/parsers/sysctl.py b/jc/parsers/sysctl.py index e1bbe56e..195679c4 100644 --- a/jc/parsers/sysctl.py +++ b/jc/parsers/sysctl.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `sysctl -a` command output parser +r"""jc - JSON Convert `sysctl -a` command output parser > Note: Since `sysctl` output is not easily parsable only a very simple > key/value object will be output. An attempt is made to convert obvious diff --git a/jc/parsers/syslog.py b/jc/parsers/syslog.py index 4853bdb7..84c0843d 100644 --- a/jc/parsers/syslog.py +++ b/jc/parsers/syslog.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Syslog RFC 5424 string parser +r"""jc - JSON Convert Syslog RFC 5424 string parser This parser accepts a single syslog line string or multiple syslog lines separated by newlines. A warning message to `STDERR` will be printed if an diff --git a/jc/parsers/syslog_bsd.py b/jc/parsers/syslog_bsd.py index 87ce7236..3040a247 100644 --- a/jc/parsers/syslog_bsd.py +++ b/jc/parsers/syslog_bsd.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Syslog RFC 3164 string parser +r"""jc - JSON Convert Syslog RFC 3164 string parser This parser accepts a single syslog line string or multiple syslog lines separated by newlines. A warning message to `STDERR` will be printed if an diff --git a/jc/parsers/syslog_bsd_s.py b/jc/parsers/syslog_bsd_s.py index a4b05c0c..ebbad402 100644 --- a/jc/parsers/syslog_bsd_s.py +++ b/jc/parsers/syslog_bsd_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Syslog RFC 3164 string streaming parser +r"""jc - JSON Convert Syslog RFC 3164 string streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/syslog_s.py b/jc/parsers/syslog_s.py index 871f27cf..e708b5e0 100644 --- a/jc/parsers/syslog_s.py +++ b/jc/parsers/syslog_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Syslog RFC 5424 string streaming parser +r"""jc - JSON Convert Syslog RFC 5424 string streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/systemctl.py b/jc/parsers/systemctl.py index 9d648449..1f7bd0bb 100644 --- a/jc/parsers/systemctl.py +++ b/jc/parsers/systemctl.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `systemctl` command output parser +r"""jc - JSON Convert `systemctl` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_lj.py b/jc/parsers/systemctl_lj.py index 0c7ecf04..fd0ad10d 100644 --- a/jc/parsers/systemctl_lj.py +++ b/jc/parsers/systemctl_lj.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `systemctl list-jobs` command output parser +r"""jc - JSON Convert `systemctl list-jobs` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_ls.py b/jc/parsers/systemctl_ls.py index df4baecf..15fe4ee5 100644 --- a/jc/parsers/systemctl_ls.py +++ b/jc/parsers/systemctl_ls.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `systemctl list-sockets` command output +r"""jc - JSON Convert `systemctl list-sockets` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_luf.py b/jc/parsers/systemctl_luf.py index a7019c1d..504af4ac 100644 --- a/jc/parsers/systemctl_luf.py +++ b/jc/parsers/systemctl_luf.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `systemctl list-unit-files` command output +r"""jc - JSON Convert `systemctl list-unit-files` command output parser Usage (cli): diff --git a/jc/parsers/systeminfo.py b/jc/parsers/systeminfo.py index 04f9ac9f..eaf77f82 100644 --- a/jc/parsers/systeminfo.py +++ b/jc/parsers/systeminfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `systeminfo` command output parser +r"""jc - JSON Convert `systeminfo` command output parser Blank or missing elements are set to `null`. diff --git a/jc/parsers/time.py b/jc/parsers/time.py index 1d89ac0c..539de8de 100644 --- a/jc/parsers/time.py +++ b/jc/parsers/time.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `/usr/bin/time` command output parser +r"""jc - JSON Convert `/usr/bin/time` command output parser Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`. diff --git a/jc/parsers/timedatectl.py b/jc/parsers/timedatectl.py index 684bc93b..f27f8984 100644 --- a/jc/parsers/timedatectl.py +++ b/jc/parsers/timedatectl.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `timedatectl` command output parser +r"""jc - JSON Convert `timedatectl` command output parser Also supports the `timesync-status` option. diff --git a/jc/parsers/timestamp.py b/jc/parsers/timestamp.py index 0c71d385..68f6a601 100644 --- a/jc/parsers/timestamp.py +++ b/jc/parsers/timestamp.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Unix Epoch Timestamp string parser +r"""jc - JSON Convert Unix Epoch Timestamp string parser The naive fields are based on the local time of the system the parser is run on. diff --git a/jc/parsers/toml.py b/jc/parsers/toml.py index 8fe3ff65..f0145f70 100644 --- a/jc/parsers/toml.py +++ b/jc/parsers/toml.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert TOML file parser +r"""jc - JSON Convert TOML file parser Usage (cli): diff --git a/jc/parsers/top.py b/jc/parsers/top.py index 5ca4717c..2b87f22b 100644 --- a/jc/parsers/top.py +++ b/jc/parsers/top.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `top -b` command output parser +r"""jc - JSON Convert `top -b` command output parser Requires batch mode (`-b`). The `-n` option must also be used to limit the number of times `top` is run. diff --git a/jc/parsers/top_s.py b/jc/parsers/top_s.py index 34d76750..38a94086 100644 --- a/jc/parsers/top_s.py +++ b/jc/parsers/top_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `top -b` command output streaming parser +r"""jc - JSON Convert `top -b` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/tracepath.py b/jc/parsers/tracepath.py index 929ff1ec..e25c51c1 100644 --- a/jc/parsers/tracepath.py +++ b/jc/parsers/tracepath.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `tracepath` command output parser +r"""jc - JSON Convert `tracepath` command output parser Supports `tracepath` and `tracepath6` output. diff --git a/jc/parsers/traceroute.py b/jc/parsers/traceroute.py index fe6824be..41a9890c 100644 --- a/jc/parsers/traceroute.py +++ b/jc/parsers/traceroute.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `traceroute` command output parser +r"""jc - JSON Convert `traceroute` command output parser Supports `traceroute` and `traceroute6` output. diff --git a/jc/parsers/tune2fs.py b/jc/parsers/tune2fs.py index 9637733b..6ba50861 100644 --- a/jc/parsers/tune2fs.py +++ b/jc/parsers/tune2fs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `tune2fs -l` command output parser +r"""jc - JSON Convert `tune2fs -l` command output parser Usage (cli): diff --git a/jc/parsers/udevadm.py b/jc/parsers/udevadm.py index 2f51d3be..980c81c6 100644 --- a/jc/parsers/udevadm.py +++ b/jc/parsers/udevadm.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `udevadm info` command output parser +r"""jc - JSON Convert `udevadm info` command output parser Usage (cli): diff --git a/jc/parsers/ufw.py b/jc/parsers/ufw.py index d3ca7cff..bfacada3 100644 --- a/jc/parsers/ufw.py +++ b/jc/parsers/ufw.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ufw status` command output parser +r"""jc - JSON Convert `ufw status` command output parser Usage (cli): diff --git a/jc/parsers/ufw_appinfo.py b/jc/parsers/ufw_appinfo.py index be6410c9..c2824165 100644 --- a/jc/parsers/ufw_appinfo.py +++ b/jc/parsers/ufw_appinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `ufw app info [application]` command +r"""jc - JSON Convert `ufw app info [application]` command output parser Supports individual apps via `ufw app info [application]` and all apps list diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py index fb4304af..ab09bf81 100644 --- a/jc/parsers/uname.py +++ b/jc/parsers/uname.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `uname -a` command output parser +r"""jc - JSON Convert `uname -a` command output parser > Note: Must use `uname -a` diff --git a/jc/parsers/universal.py b/jc/parsers/universal.py index c476803a..4ee7a5be 100644 --- a/jc/parsers/universal.py +++ b/jc/parsers/universal.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert universal parsers""" +r"""jc - JSON Convert universal parsers""" from typing import Iterable, List, Dict diff --git a/jc/parsers/update_alt_gs.py b/jc/parsers/update_alt_gs.py index 633e2a5c..ad3e9d72 100644 --- a/jc/parsers/update_alt_gs.py +++ b/jc/parsers/update_alt_gs.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `update-alternatives --get-selections` command output parser +r"""jc - JSON Convert `update-alternatives --get-selections` command output parser Usage (cli): diff --git a/jc/parsers/update_alt_q.py b/jc/parsers/update_alt_q.py index 6f35e56d..e9733e0f 100644 --- a/jc/parsers/update_alt_q.py +++ b/jc/parsers/update_alt_q.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `update-alternatives --query` command output parser +r"""jc - JSON Convert `update-alternatives --query` command output parser Usage (cli): diff --git a/jc/parsers/upower.py b/jc/parsers/upower.py index a659717f..626556d9 100644 --- a/jc/parsers/upower.py +++ b/jc/parsers/upower.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `upower` command output parser +r"""jc - JSON Convert `upower` command output parser The `updated_epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/uptime.py b/jc/parsers/uptime.py index 39d63906..2e9d31fa 100644 --- a/jc/parsers/uptime.py +++ b/jc/parsers/uptime.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `uptime` command output parser +r"""jc - JSON Convert `uptime` command output parser Usage (cli): diff --git a/jc/parsers/url.py b/jc/parsers/url.py index 8984ccb8..05257d23 100644 --- a/jc/parsers/url.py +++ b/jc/parsers/url.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert URL string parser +r"""jc - JSON Convert URL string parser Normalized, Encoded, and Decoded versions of the original URL and URL parts are included in the output. Encoding and Decoding is best effort. diff --git a/jc/parsers/ver.py b/jc/parsers/ver.py index a34d764f..084fbed9 100644 --- a/jc/parsers/ver.py +++ b/jc/parsers/ver.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert Version string output parser +r"""jc - JSON Convert Version string output parser Best-effort attempt to parse various styles of version numbers. This parser is based off of the version parser included in the CPython distutils @@ -89,7 +89,7 @@ import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.1' + version = '1.2' description = 'Version string parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -132,7 +132,7 @@ def _process(proc_data: JSONDictType) -> JSONDictType: return proc_data -def strict_parse(vstring): +def _strict_parse(vstring): version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$', re.VERBOSE) match = version_re.match(vstring) if not match: @@ -158,7 +158,7 @@ def strict_parse(vstring): } -def loose_parse(vstring): +def _loose_parse(vstring): component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE) components = [x for x in component_re.split(vstring) if x and x != '.'] @@ -197,10 +197,10 @@ def parse( data = data.strip() try: - raw_output = strict_parse(data) + raw_output = _strict_parse(data) except ValueError: - raw_output['components'] = loose_parse(data) + raw_output['components'] = _loose_parse(data) strict = False if raw_output: diff --git a/jc/parsers/veracrypt.py b/jc/parsers/veracrypt.py index d48237b4..af1051d6 100644 --- a/jc/parsers/veracrypt.py +++ b/jc/parsers/veracrypt.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `veracrypt` command output parser +r"""jc - JSON Convert `veracrypt` command output parser Supports the following `veracrypt` subcommands: - `veracrypt --text --list` @@ -74,7 +74,6 @@ Examples: "backup_header": "Yes" } ] - """ import re from typing import List, Dict, Optional, Any diff --git a/jc/parsers/vmstat.py b/jc/parsers/vmstat.py index 6f4c9048..c6c41d6c 100644 --- a/jc/parsers/vmstat.py +++ b/jc/parsers/vmstat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `vmstat` command output parser +r"""jc - JSON Convert `vmstat` command output parser Options supported: `-a`, `-w`, `-d`, `-t` diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index 6df5964b..a52c9bda 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `vmstat` command output streaming parser +r"""jc - JSON Convert `vmstat` command output streaming parser > This streaming parser outputs JSON Lines (cli) or returns an Iterable of > Dictionaries (module) diff --git a/jc/parsers/w.py b/jc/parsers/w.py index c1b764d3..38c730cb 100644 --- a/jc/parsers/w.py +++ b/jc/parsers/w.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `w` command output parser +r"""jc - JSON Convert `w` command output parser Usage (cli): diff --git a/jc/parsers/wc.py b/jc/parsers/wc.py index 49f64a5b..738ebf65 100644 --- a/jc/parsers/wc.py +++ b/jc/parsers/wc.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `wc` command output parser +r"""jc - JSON Convert `wc` command output parser Usage (cli): diff --git a/jc/parsers/who.py b/jc/parsers/who.py index 6c8cc784..ad6f582b 100644 --- a/jc/parsers/who.py +++ b/jc/parsers/who.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `who` command output parser +r"""jc - JSON Convert `who` command output parser Accepts any of the following who options (or no options): `-aTH` diff --git a/jc/parsers/x509_cert.py b/jc/parsers/x509_cert.py index 8381638e..a60ce949 100644 --- a/jc/parsers/x509_cert.py +++ b/jc/parsers/x509_cert.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert X.509 Certificate format file parser +r"""jc - JSON Convert X.509 Certificate format file parser This parser will convert DER and PEM encoded X.509 certificate files. diff --git a/jc/parsers/x509_csr.py b/jc/parsers/x509_csr.py index 41bac2e9..64fa8678 100644 --- a/jc/parsers/x509_csr.py +++ b/jc/parsers/x509_csr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert X.509 Certificate Request format file parser +r"""jc - JSON Convert X.509 Certificate Request format file parser This parser will convert DER and PEM encoded X.509 certificate request files. @@ -248,7 +248,6 @@ Examples: "signature": "30:45:02:20:77:ac:5b:51:bf:c5:f5:43:02:52:ae:66:..." } ] - """ # import binascii # from collections import OrderedDict diff --git a/jc/parsers/xml.py b/jc/parsers/xml.py index 3a5fa718..87ce0476 100644 --- a/jc/parsers/xml.py +++ b/jc/parsers/xml.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `XML` file parser +r"""jc - JSON Convert `XML` file parser This parser adds a `@` prefix to attributes by default. This can be changed to a `_` prefix by using the `-r` (cli) or `raw=True` (module) option. diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index 76d2b2a6..335eb37e 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `xrandr` command output parser +r"""jc - JSON Convert `xrandr` command output parser Usage (cli): diff --git a/jc/parsers/yaml.py b/jc/parsers/yaml.py index 2e2e2213..8a13a5b6 100644 --- a/jc/parsers/yaml.py +++ b/jc/parsers/yaml.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `YAML` file parser +r"""jc - JSON Convert `YAML` file parser > Note: `datetime` objects will be converted to strings. diff --git a/jc/parsers/zipinfo.py b/jc/parsers/zipinfo.py index a35265c2..6a878fa4 100644 --- a/jc/parsers/zipinfo.py +++ b/jc/parsers/zipinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `zipinfo` command output parser +r"""jc - JSON Convert `zipinfo` command output parser > Note: No `zipinfo` options are supported. diff --git a/jc/parsers/zpool_iostat.py b/jc/parsers/zpool_iostat.py index bc838094..2758a79e 100644 --- a/jc/parsers/zpool_iostat.py +++ b/jc/parsers/zpool_iostat.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `zpool iostat` command output parser +r"""jc - JSON Convert `zpool iostat` command output parser Supports with or without the `-v` flag. diff --git a/jc/parsers/zpool_status.py b/jc/parsers/zpool_status.py index bce6c001..589e11cb 100644 --- a/jc/parsers/zpool_status.py +++ b/jc/parsers/zpool_status.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `zpool status` command output parser +r"""jc - JSON Convert `zpool status` command output parser Works with or without the `-v` option. diff --git a/jc/utils.py b/jc/utils.py index a3627092..b5076a38 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -210,7 +210,7 @@ def remove_quotes(data: str) -> str: def normalize_key(data: str) -> str: - """ + r""" Normalize a key name by shifting to lower-case and converting special characters to underscores. @@ -229,7 +229,7 @@ def normalize_key(data: str) -> str: string """ - special = '''!"#$%&'()*+,-./:;<=>?@[\]^`{|}~ ''' + special = r'''!"#$%&'()*+,-./:;<=>?@[\]^`{|}~ ''' initial_underscore = False data = data.strip().lower() diff --git a/man/jc.1 b/man/jc.1 index 8ee8b80a..ccc5a760 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2024-03-01 1.25.2 "JSON Convert" +.TH jc 1 2024-03-15 1.25.2 "JSON Convert" .SH NAME \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings diff --git a/tests/fixtures/generic/apt_get_sqq--sample.json b/tests/fixtures/generic/apt_get_sqq--sample.json index e6616ac1..cf14034c 100644 --- a/tests/fixtures/generic/apt_get_sqq--sample.json +++ b/tests/fixtures/generic/apt_get_sqq--sample.json @@ -1 +1 @@ -[{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"remove","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"base-files","broken":"10.3+deb10u4","proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_src":null,"architecture":"amd64"},{"operation":"configure","package":"base-files","broken":null,"proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_src":null,"architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"}] +[{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"remove","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"base-files","broken":"10.3+deb10u4","proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_pkg_ver":null,"architecture":"amd64"},{"operation":"configure","package":"base-files","broken":null,"proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_pkg_ver":null,"architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_pkg_ver":"Debian-Security:10/oldstable","architecture":"amd64"}] diff --git a/tests/fixtures/generic/ethtool--default1.json b/tests/fixtures/generic/ethtool--default1.json index 75d39613..57e3f847 100644 --- a/tests/fixtures/generic/ethtool--default1.json +++ b/tests/fixtures/generic/ethtool--default1.json @@ -1 +1 @@ -{"name":"enp0s3","supported_pause_frame_use":"No","supports_auto_negotiation":true,"supported_fec_modes":"Not reported","advertised_pause_frame_use":false,"advertised_auto_negotiation":true,"advertised_fec_modes":"Not reported","speed":"1000Mb/s","duplex":"Full","port":"Twisted Pair","phyad":"0","transceiver":"internal","auto_negotiation":false,"mdi_x":"off (auto)","supports_wake_on":"umbg","wake_on":"d","link_detected":true,"supported_ports":["TP"],"supported_link_modes":["10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000baseT/Full"],"advertised_link_modes":["10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000baseT/Full"],"current_message_level":["0x00000007 (7)","drv probe link"],"speed_bps":1000000000} +{"name":"enp0s3","supported_pause_frame_use":"No","supports_auto_negotiation":true,"supported_fec_modes":[],"advertised_pause_frame_use":false,"advertised_auto_negotiation":true,"advertised_fec_modes":[],"speed":"1000Mb/s","duplex":"Full","port":"Twisted Pair","phyad":"0","transceiver":"internal","auto_negotiation":false,"mdi_x":"off (auto)","supports_wake_on":"umbg","wake_on":"d","link_detected":true,"supported_ports":["TP"],"supported_link_modes":["10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000baseT/Full"],"advertised_link_modes":["10baseT/Half","10baseT/Full","100baseT/Half","100baseT/Full","1000baseT/Full"],"current_message_level":["0x00000007 (7)","drv probe link"],"speed_bps":1000000000} diff --git a/tests/fixtures/generic/ethtool--default2.json b/tests/fixtures/generic/ethtool--default2.json index 87e9b69f..ff9ba7c9 100644 --- a/tests/fixtures/generic/ethtool--default2.json +++ b/tests/fixtures/generic/ethtool--default2.json @@ -1 +1 @@ -{"name":"enp1s0","supported_pause_frame_use":"Symmetric Receive-only","supports_auto_negotiation":true,"supported_fec_modes":"Not reported","advertised_pause_frame_use":false,"advertised_auto_negotiation":true,"advertised_fec_modes":"Not reported","speed":"40000Mb/s","duplex":"Full","auto_negotiation":false,"port":"FIBRE","phyad":"0","transceiver":"internal","supports_wake_on":"d","wake_on":"d","link_detected":true,"supported_ports":["FIBRE"],"supported_link_modes":["10000baseKX4/Full","40000baseCR4/Full","40000baseSR4/Full","56000baseCR4/Full","56000baseSR4/Full","1000baseX/Full","10000baseCR/Full","10000baseSR/Full"],"advertised_link_modes":["10000baseKX4/Full","40000baseCR4/Full","40000baseSR4/Full","1000baseX/Full","10000baseCR/Full","10000baseSR/Full"],"current_message_level":["0x00000014 (20)","link ifdown"],"speed_bps":40000000000} +{"name":"enp1s0","supported_pause_frame_use":"Symmetric Receive-only","supports_auto_negotiation":true,"supported_fec_modes":[],"advertised_pause_frame_use":false,"advertised_auto_negotiation":true,"advertised_fec_modes":[],"speed":"40000Mb/s","duplex":"Full","auto_negotiation":false,"port":"FIBRE","phyad":"0","transceiver":"internal","supports_wake_on":"d","wake_on":"d","link_detected":true,"supported_ports":["FIBRE"],"supported_link_modes":["10000baseKX4/Full","40000baseCR4/Full","40000baseSR4/Full","56000baseCR4/Full","56000baseSR4/Full","1000baseX/Full","10000baseCR/Full","10000baseSR/Full"],"advertised_link_modes":["10000baseKX4/Full","40000baseCR4/Full","40000baseSR4/Full","1000baseX/Full","10000baseCR/Full","10000baseSR/Full"],"current_message_level":["0x00000014 (20)","link ifdown"],"speed_bps":40000000000} diff --git a/tests/fixtures/generic/ethtool--module-info-convert-units.json b/tests/fixtures/generic/ethtool--module-info-convert-units.json new file mode 100644 index 00000000..54f32780 --- /dev/null +++ b/tests/fixtures/generic/ethtool--module-info-convert-units.json @@ -0,0 +1 @@ +{"identifier":"0x03 (SFP)","extended_identifier":"0x04 (GBIC/SFP defined by 2-wire interface ID)","connector":"0x07 (LC)","transceiver_codes":"0x20 0x00 0x00 0x00 0x44 0x40 0x00 0x00 0x03","transceiver_type":["10G Ethernet: 10G Base-LR","FC: short distance (S)","FC: Shortwave laser, linear Rx (SA)","FC: Shortwave laser w/o OFC (SN)","Extended: 100G Base-LR4 or 25GBase-LR"],"encoding":"0x03 (NRZ)","br_nominal":"25750MBd","rate_identifier":"0x00 (unspecified)","length_smf_km":"10km","length_smf":"10000m","length_50um":"0m","length_62_5um":"0m","length_copper":"0m","length_om3":"0m","laser_wavelength":"1310nm","vendor_name":"EDGE","vendor_oui":"00:1b:21","vendor_pn":"SFP-10/25GLR-31","vendor_rev":"1A","option_values":"0x08 0x1a","option":["RX_LOS implemented","TX_FAULT implemented","TX_DISABLE implemented","Retimer or CDR implemented"],"br_margin_max":"0%","br_margin_min":"0%","vendor_sn":"EO11111111111","date_code":"230619","optical_diagnostics_support":"Yes","alarm_warning_flags_implemented":"Yes","laser_bias_current_high_alarm":"Off","laser_bias_current_low_alarm":"Off","laser_bias_current_high_warning":"Off","laser_bias_current_low_warning":"Off","laser_output_power_high_alarm":"Off","laser_output_power_low_alarm":"Off","laser_output_power_high_warning":"Off","laser_output_power_low_warning":"Off","module_temperature_high_alarm":"Off","module_temperature_low_alarm":"Off","module_temperature_high_warning":"Off","module_temperature_low_warning":"Off","module_voltage_high_alarm":"Off","module_voltage_low_alarm":"Off","module_voltage_high_warning":"Off","module_voltage_low_warning":"Off","laser_rx_power_high_alarm":"Off","laser_rx_power_low_alarm":"On","laser_rx_power_high_warning":"Off","laser_rx_power_low_warning":"On","laser_bias_current_ma":51.494,"laser_output_power_mw":0.8183,"laser_output_power_dbm":-0.87,"receiver_signal_average_optical_power_mw":0.0001,"receiver_signal_average_optical_power_dbm":-40.0,"module_temperature_celsius":34.99,"module_temperature_farenheit":94.99,"module_voltage_v":3.2995,"laser_bias_current_high_alarm_threshold_ma":110.0,"laser_bias_current_low_alarm_threshold_ma":1.0,"laser_bias_current_high_warning_threshold_ma":100.0,"laser_bias_current_low_warning_threshold_ma":1.0,"laser_output_power_high_alarm_threshold_mw":3.1623,"laser_output_power_high_alarm_threshold_dbm":5.0,"laser_output_power_low_alarm_threshold_mw":0.1,"laser_output_power_low_alarm_threshold_dbm":-10.0,"laser_output_power_high_warning_threshold_mw":1.5849,"laser_output_power_high_warning_threshold_dbm":2.0,"laser_output_power_low_warning_threshold_mw":0.1995,"laser_output_power_low_warning_threshold_dbm":-7.0,"module_temperature_high_alarm_threshold_celsius":95.0,"module_temperature_high_alarm_threshold_farenheit":203.0,"module_temperature_low_alarm_threshold_celsius":-50.0,"module_temperature_low_alarm_threshold_farenheit":-58.0,"module_temperature_high_warning_threshold_celsius":85.0,"module_temperature_high_warning_threshold_farenheit":185.0,"module_temperature_low_warning_threshold_celsius":-40.0,"module_temperature_low_warning_threshold_farenheit":-40.0,"module_voltage_high_alarm_threshold_v":3.63,"module_voltage_low_alarm_threshold_v":2.97,"module_voltage_high_warning_threshold_v":3.465,"module_voltage_low_warning_threshold_v":3.135,"laser_rx_power_high_alarm_threshold_mw":3.1623,"laser_rx_power_high_alarm_threshold_dbm":5.0,"laser_rx_power_low_alarm_threshold_mw":0.0234,"laser_rx_power_low_alarm_threshold_dbm":-16.31,"laser_rx_power_high_warning_threshold_mw":1.5849,"laser_rx_power_high_warning_threshold_dbm":2.0,"laser_rx_power_low_warning_threshold_mw":0.0468,"laser_rx_power_low_warning_threshold_dbm":-13.3} diff --git a/tests/fixtures/generic/ethtool--module-info-convert-units.out b/tests/fixtures/generic/ethtool--module-info-convert-units.out new file mode 100644 index 00000000..1d67bae1 --- /dev/null +++ b/tests/fixtures/generic/ethtool--module-info-convert-units.out @@ -0,0 +1,79 @@ + Identifier : 0x03 (SFP) + Extended identifier : 0x04 (GBIC/SFP defined by 2-wire interface ID) + Connector : 0x07 (LC) + Transceiver codes : 0x20 0x00 0x00 0x00 0x44 0x40 0x00 0x00 0x03 + Transceiver type : 10G Ethernet: 10G Base-LR + Transceiver type : FC: short distance (S) + Transceiver type : FC: Shortwave laser, linear Rx (SA) + Transceiver type : FC: Shortwave laser w/o OFC (SN) + Transceiver type : Extended: 100G Base-LR4 or 25GBase-LR + Encoding : 0x03 (NRZ) + BR, Nominal : 25750MBd + Rate identifier : 0x00 (unspecified) + Length (SMF,km) : 10km + Length (SMF) : 10000m + Length (50um) : 0m + Length (62.5um) : 0m + Length (Copper) : 0m + Length (OM3) : 0m + Laser wavelength : 1310nm + Vendor name : EDGE + Vendor OUI : 00:1b:21 + Vendor PN : SFP-10/25GLR-31 + Vendor rev : 1A + Option values : 0x08 0x1a + Option : RX_LOS implemented + Option : TX_FAULT implemented + Option : TX_DISABLE implemented + Option : Retimer or CDR implemented + BR margin, max : 0% + BR margin, min : 0% + Vendor SN : EO11111111111 + Date code : 230619 + Optical diagnostics support : Yes + Laser bias current : 51.494 mA + Laser output power : 0.8183 mW / -0.87 dBm + Receiver signal average optical power : 0.0001 mW / -40.00 dBm + Module temperature : 34.99 degrees C / 94.99 degrees F + Module voltage : 3.2995 V + Alarm/warning flags implemented : Yes + Laser bias current high alarm : Off + Laser bias current low alarm : Off + Laser bias current high warning : Off + Laser bias current low warning : Off + Laser output power high alarm : Off + Laser output power low alarm : Off + Laser output power high warning : Off + Laser output power low warning : Off + Module temperature high alarm : Off + Module temperature low alarm : Off + Module temperature high warning : Off + Module temperature low warning : Off + Module voltage high alarm : Off + Module voltage low alarm : Off + Module voltage high warning : Off + Module voltage low warning : Off + Laser rx power high alarm : Off + Laser rx power low alarm : On + Laser rx power high warning : Off + Laser rx power low warning : On + Laser bias current high alarm threshold : 110.000 mA + Laser bias current low alarm threshold : 1.000 mA + Laser bias current high warning threshold : 100.000 mA + Laser bias current low warning threshold : 1.000 mA + Laser output power high alarm threshold : 3.1623 mW / 5.00 dBm + Laser output power low alarm threshold : 0.1000 mW / -10.00 dBm + Laser output power high warning threshold : 1.5849 mW / 2.00 dBm + Laser output power low warning threshold : 0.1995 mW / -7.00 dBm + Module temperature high alarm threshold : 95.00 degrees C / 203.00 degrees F + Module temperature low alarm threshold : -50.00 degrees C / -58.00 degrees F + Module temperature high warning threshold : 85.00 degrees C / 185.00 degrees F + Module temperature low warning threshold : -40.00 degrees C / -40.00 degrees F + Module voltage high alarm threshold : 3.6300 V + Module voltage low alarm threshold : 2.9700 V + Module voltage high warning threshold : 3.4650 V + Module voltage low warning threshold : 3.1350 V + Laser rx power high alarm threshold : 3.1623 mW / 5.00 dBm + Laser rx power low alarm threshold : 0.0234 mW / -16.31 dBm + Laser rx power high warning threshold : 1.5849 mW / 2.00 dBm + Laser rx power low warning threshold : 0.0468 mW / -13.30 dBm diff --git a/tests/templates/_test_foo_simple.py b/tests/templates/_test_foo_simple.py index 2bd24c5c..dfc4a27e 100644 --- a/tests/templates/_test_foo_simple.py +++ b/tests/templates/_test_foo_simple.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_apt_cache_show.py b/tests/test_apt_cache_show.py index 234e61b3..77b48155 100644 --- a/tests/test_apt_cache_show.py +++ b/tests/test_apt_cache_show.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_apt_get_sqq.py b/tests/test_apt_get_sqq.py index a0243179..1df3e9b8 100644 --- a/tests/test_apt_get_sqq.py +++ b/tests/test_apt_get_sqq.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_curl_head.py b/tests/test_curl_head.py index a3cc80a4..9df5dec8 100644 --- a/tests/test_curl_head.py +++ b/tests/test_curl_head.py @@ -1,5 +1,9 @@ import unittest +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_ethtool.py b/tests/test_ethtool.py index ed5e2083..a958d6a8 100644 --- a/tests/test_ethtool.py +++ b/tests/test_ethtool.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_http_headers.py b/tests/test_http_headers.py index 25a2b4fd..b215b1c4 100644 --- a/tests/test_http_headers.py +++ b/tests/test_http_headers.py @@ -1,5 +1,9 @@ import unittest +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_needrestart.py b/tests/test_needrestart.py index d0e92f63..4b4bea96 100644 --- a/tests/test_needrestart.py +++ b/tests/test_needrestart.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() # Execute these steps for standard tests: # - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename. diff --git a/tests/test_path.py b/tests/test_path.py index b00d5066..385ff726 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -1,7 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils - +sys.path.pop() class MyTests(unittest.TestCase): diff --git a/tests/test_path_list.py b/tests/test_path_list.py index 9d920759..0161d99b 100644 --- a/tests/test_path_list.py +++ b/tests/test_path_list.py @@ -1,6 +1,9 @@ import unittest - +import os +import sys +sys.path.append(os.getcwd()) from tests import utils_for_test as test_utils +sys.path.pop() class MyTests(unittest.TestCase):