jpcli 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jpcli-0.2.0/jpcli.egg-info → jpcli-0.4.0}/PKG-INFO +11 -14
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/main.py +2 -2
- jpcli-0.4.0/jpcli/parsers/cmdline_parser.py +19 -0
- jpcli-0.4.0/jpcli/parsers/cpuinfo_parser.py +29 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/df_parser.py +4 -1
- jpcli-0.4.0/jpcli/parsers/dmesg_parser.py +13 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/ifconfig_parser.py +2 -1
- jpcli-0.4.0/jpcli/parsers/journalctl_parser.py +27 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/lscpu_parser.py +4 -14
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/lshw_parser.py +13 -9
- jpcli-0.4.0/jpcli/parsers/lsmem_parser.py +34 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/mcelog_parser.py +4 -1
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/os_release_parser.py +4 -2
- jpcli-0.4.0/jpcli/parsers/uname_parser.py +31 -0
- {jpcli-0.2.0 → jpcli-0.4.0/jpcli.egg-info}/PKG-INFO +11 -14
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli.egg-info/SOURCES.txt +0 -1
- {jpcli-0.2.0 → jpcli-0.4.0}/setup.py +1 -1
- jpcli-0.2.0/LICENCE +0 -21
- jpcli-0.2.0/jpcli/parsers/cmdline_parser.py +0 -12
- jpcli-0.2.0/jpcli/parsers/cpuinfo_parser.py +0 -33
- jpcli-0.2.0/jpcli/parsers/dmesg_parser.py +0 -12
- jpcli-0.2.0/jpcli/parsers/journalctl_parser.py +0 -12
- jpcli-0.2.0/jpcli/parsers/lsmem_parser.py +0 -23
- jpcli-0.2.0/jpcli/parsers/uname_parser.py +0 -8
- {jpcli-0.2.0 → jpcli-0.4.0}/MANIFEST.in +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/README.md +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/__init__.py +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/__init__.py +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli/parsers/free_parser.py +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli.egg-info/dependency_links.txt +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli.egg-info/entry_points.txt +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/jpcli.egg-info/top_level.txt +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/setup.cfg +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/tests/__init__.py +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/tests/test_lsmem_parser.py +0 -0
- {jpcli-0.2.0 → jpcli-0.4.0}/tests/test_other_command_parser.py +0 -0
@@ -1,27 +1,24 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: jpcli
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.0
|
4
4
|
Summary: A library to convert Linux command output to JSON
|
5
5
|
Home-page: https://github.com/JaimeAdanCuevas/jpcli
|
6
6
|
Author: Jaime Cuevas
|
7
7
|
Author-email: adancuevas@outlook.com
|
8
8
|
License: UNKNOWN
|
9
|
+
Description: # jpcli
|
10
|
+
|
11
|
+
jpcli is a library that converts the output of various Linux commands to JSON format.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```sh
|
16
|
+
pip install jpcli
|
17
|
+
|
18
|
+
|
9
19
|
Platform: UNKNOWN
|
10
20
|
Classifier: Programming Language :: Python :: 3
|
11
21
|
Classifier: License :: OSI Approved :: MIT License
|
12
22
|
Classifier: Operating System :: OS Independent
|
13
23
|
Requires-Python: >=3.6
|
14
24
|
Description-Content-Type: text/markdown
|
15
|
-
License-File: LICENCE
|
16
|
-
|
17
|
-
# jpcli
|
18
|
-
|
19
|
-
jpcli is a library that converts the output of various Linux commands to JSON format.
|
20
|
-
|
21
|
-
## Installation
|
22
|
-
|
23
|
-
```sh
|
24
|
-
pip install jpcli
|
25
|
-
|
26
|
-
|
27
|
-
|
@@ -27,8 +27,8 @@ def parse_command_output(command_output, parser_name):
|
|
27
27
|
'cmdline': cmdline_parser.parse,
|
28
28
|
'os-release': os_release_parser.parse,
|
29
29
|
'dmesg': dmesg_parser.parse,
|
30
|
-
'journalctl'
|
31
|
-
'mcelog'
|
30
|
+
'journalctl': journalctl_parser.parse,
|
31
|
+
'mcelog': mcelog_parser.parse,
|
32
32
|
}
|
33
33
|
if parser_name in parsers:
|
34
34
|
return parsers[parser_name](command_output)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(command_output):
|
5
|
+
# Split the command line output into individual parameters
|
6
|
+
params = command_output.strip().split()
|
7
|
+
|
8
|
+
# Create a dictionary to hold the parsed key-value pairs
|
9
|
+
cmdline_dict = {}
|
10
|
+
|
11
|
+
for param in params:
|
12
|
+
if '=' in param:
|
13
|
+
key, value = param.split('=', 1)
|
14
|
+
else:
|
15
|
+
key, value = param, None # Handle flags with no value (e.g., "quiet")
|
16
|
+
cmdline_dict[key] = value
|
17
|
+
|
18
|
+
# Convert the dictionary to a JSON-formatted string
|
19
|
+
return json.dumps(cmdline_dict, indent=2)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(command_output):
|
5
|
+
processors = []
|
6
|
+
current_processor = {}
|
7
|
+
|
8
|
+
lines = command_output.splitlines()
|
9
|
+
for line in lines:
|
10
|
+
if line.strip(): # Check if line is not empty
|
11
|
+
key, value = line.split(':')
|
12
|
+
key = key.strip().replace(' ', '_').lower()
|
13
|
+
value = value.strip()
|
14
|
+
if key == 'processor' and current_processor:
|
15
|
+
# When a new processor block starts, append the previous one
|
16
|
+
processors.append(current_processor)
|
17
|
+
current_processor = {}
|
18
|
+
current_processor[key] = value
|
19
|
+
else:
|
20
|
+
# Empty line indicates the end of one processor's info
|
21
|
+
if current_processor:
|
22
|
+
processors.append(current_processor)
|
23
|
+
current_processor = {}
|
24
|
+
|
25
|
+
# Append the last processor if exists
|
26
|
+
if current_processor:
|
27
|
+
processors.append(current_processor)
|
28
|
+
|
29
|
+
return json.dumps(processors, indent=2)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
1
4
|
def parse(command_output):
|
2
5
|
lines = command_output.splitlines()
|
3
6
|
data = []
|
@@ -13,4 +16,4 @@ def parse(command_output):
|
|
13
16
|
entry = {headers[i]: values[i] for i in range(len(headers))}
|
14
17
|
data.append(entry)
|
15
18
|
|
16
|
-
return data
|
19
|
+
return json.dumps(data, indent=2)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(dmesg_output):
|
5
|
+
"""
|
6
|
+
Parse the contents of dmesg output.
|
7
|
+
"""
|
8
|
+
try:
|
9
|
+
dmesg_lines = dmesg_output.strip().split('\n')
|
10
|
+
dmesg_list = [{"message": line} for line in dmesg_lines]
|
11
|
+
return json.dumps(dmesg_list, indent=2)
|
12
|
+
except Exception as e:
|
13
|
+
return json.dumps({"error": str(e), "message": "Failed to parse dmesg output"}, indent=2)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(journalctl_output):
|
5
|
+
"""
|
6
|
+
Parse the contents of journalctl output.
|
7
|
+
"""
|
8
|
+
try:
|
9
|
+
# Split the output into individual lines
|
10
|
+
journalctl_lines = journalctl_output.strip().split('\n')
|
11
|
+
|
12
|
+
# Initialize a list to store JSON objects
|
13
|
+
journalctl_list = []
|
14
|
+
|
15
|
+
# Process each line
|
16
|
+
for line in journalctl_lines:
|
17
|
+
if line: # Skip empty lines
|
18
|
+
# Parse each line as JSON and append to the list
|
19
|
+
journalctl_list.append(json.loads(line))
|
20
|
+
|
21
|
+
# Convert the list of JSON objects to a pretty-printed JSON string
|
22
|
+
return json.dumps(journalctl_list, indent=2)
|
23
|
+
|
24
|
+
except json.JSONDecodeError as e:
|
25
|
+
return json.dumps({"error": str(e), "message": "Failed to parse JSON from journalctl output"}, indent=2)
|
26
|
+
except Exception as e:
|
27
|
+
return json.dumps({"error": str(e), "message": "Failed to parse journalctl output"}, indent=2)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
1
4
|
def parse(command_output):
|
2
5
|
"""
|
3
6
|
Parses the output of the lscpu command into a dictionary.
|
@@ -17,17 +20,4 @@ def parse(command_output):
|
|
17
20
|
key = parts[0].strip()
|
18
21
|
value = parts[1].strip()
|
19
22
|
cpu_info[key] = value
|
20
|
-
return cpu_info
|
21
|
-
|
22
|
-
|
23
|
-
def lscpu_parser(command_output):
|
24
|
-
"""
|
25
|
-
Wrapper function to parse lscpu output.
|
26
|
-
|
27
|
-
Args:
|
28
|
-
command_output (str): The string output from the lscpu command.
|
29
|
-
|
30
|
-
Returns:
|
31
|
-
dict: Parsed CPU information.
|
32
|
-
"""
|
33
|
-
return parse(command_output)
|
23
|
+
return json.dumps(cpu_info, indent=2)
|
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(command_output, indent_level=0):
|
5
|
+
"""
|
6
|
+
Recursively parse sections of command output based on indentation level.
|
7
|
+
"""
|
2
8
|
def parse_section(lines, indent_level):
|
3
9
|
data = {}
|
4
10
|
current_section = {} # Initialize as empty dictionary
|
@@ -6,14 +12,16 @@ def parse(command_output):
|
|
6
12
|
line = lines.pop(0)
|
7
13
|
if line.strip() == "":
|
8
14
|
continue # Ignore empty lines
|
15
|
+
|
9
16
|
indent = len(line) - len(line.lstrip())
|
17
|
+
|
10
18
|
if indent < indent_level:
|
11
19
|
lines.insert(0, line)
|
12
20
|
break
|
13
21
|
elif line.startswith(' *-'):
|
14
22
|
if current_section:
|
15
23
|
yield current_section
|
16
|
-
current_section = {'description': line.split('-')[-1].strip()} # Initialize
|
24
|
+
current_section = {'description': line.split('-')[-1].strip()} # Initialize with description
|
17
25
|
elif indent == indent_level and line.startswith(' '):
|
18
26
|
parts = line.strip().split(': ', 1)
|
19
27
|
if len(parts) == 2:
|
@@ -25,14 +33,10 @@ def parse(command_output):
|
|
25
33
|
if 'subsections' not in current_section:
|
26
34
|
current_section['subsections'] = []
|
27
35
|
current_section['subsections'].extend(parse_section([line] + lines, indent))
|
36
|
+
|
28
37
|
if current_section:
|
29
38
|
yield current_section
|
30
39
|
|
31
40
|
lines = command_output.splitlines()
|
32
|
-
|
33
|
-
return
|
34
|
-
|
35
|
-
|
36
|
-
def lshw_parser(command_output):
|
37
|
-
lines = command_output.splitlines()
|
38
|
-
return list(parse_section(lines, 0))
|
41
|
+
parsed_data = list(parse_section(lines, indent_level))
|
42
|
+
return json.dumps(parsed_data, indent=2)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(command_output):
|
5
|
+
lines = command_output.splitlines()
|
6
|
+
memory_blocks = []
|
7
|
+
headers = []
|
8
|
+
summary = {}
|
9
|
+
|
10
|
+
# Extract headers from the first line
|
11
|
+
if lines:
|
12
|
+
headers = [header.strip() for header in lines[0].split() if header.strip()]
|
13
|
+
lines = lines[1:]
|
14
|
+
|
15
|
+
for line in lines:
|
16
|
+
if not line.strip(): # Skip empty lines
|
17
|
+
continue
|
18
|
+
|
19
|
+
# Check if the line contains summary information
|
20
|
+
if ':' in line:
|
21
|
+
key, value = line.split(':')
|
22
|
+
summary[key.strip().lower().replace(' ', '_')] = value.strip()
|
23
|
+
else:
|
24
|
+
values = [value.strip() for value in line.split() if value.strip()]
|
25
|
+
if len(values) == len(headers):
|
26
|
+
entry = {headers[i].lower(): values[i] for i in range(len(headers))}
|
27
|
+
memory_blocks.append(entry)
|
28
|
+
|
29
|
+
result = {
|
30
|
+
"memory_blocks": memory_blocks,
|
31
|
+
**summary
|
32
|
+
}
|
33
|
+
|
34
|
+
return json.dumps(result, indent=2)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
1
4
|
def parse(mcelog_output):
|
2
5
|
"""
|
3
6
|
Parse the contents of mcelog output.
|
@@ -7,6 +10,6 @@ def parse(mcelog_output):
|
|
7
10
|
mcelog_list = []
|
8
11
|
for line in mcelog_lines:
|
9
12
|
mcelog_list.append(line)
|
10
|
-
return mcelog_list
|
13
|
+
return json.dumps(mcelog_list, indent=2)
|
11
14
|
except Exception as e:
|
12
15
|
return {"error": str(e), "message": "Failed to parse mcelog output"}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
2
4
|
def parse(os_release_output):
|
3
5
|
"""
|
4
6
|
Parse the contents of /etc/os-release.
|
@@ -8,4 +10,4 @@ def parse(os_release_output):
|
|
8
10
|
if '=' in line:
|
9
11
|
key, value = line.split('=', 1)
|
10
12
|
os_release_dict[key] = value.strip('"')
|
11
|
-
return os_release_dict
|
13
|
+
return json.dumps(os_release_dict, indent=2)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def parse(command_output):
|
5
|
+
"""
|
6
|
+
Parses the output of the uname -a command into a dictionary.
|
7
|
+
|
8
|
+
Args:
|
9
|
+
command_output (str): The string output from the uname -a command.
|
10
|
+
|
11
|
+
Returns:
|
12
|
+
str: A JSON-formatted string with system information.
|
13
|
+
"""
|
14
|
+
uname_info = {}
|
15
|
+
parts = command_output.split()
|
16
|
+
|
17
|
+
if len(parts) >= 6:
|
18
|
+
uname_info['system'] = parts[0] # Kernel name
|
19
|
+
uname_info['node'] = parts[1] # Network node hostname
|
20
|
+
uname_info['kernel'] = parts[2] # Kernel release
|
21
|
+
uname_info['kernel_version'] = parts[3] # Kernel version
|
22
|
+
uname_info['architecture'] = parts[4] # Machine hardware name
|
23
|
+
uname_info['processor'] = parts[5] # Processor type
|
24
|
+
|
25
|
+
# Additional fields if available
|
26
|
+
if len(parts) > 6:
|
27
|
+
uname_info['platform'] = parts[6] # Platform type (e.g., GNU/Linux)
|
28
|
+
if len(parts) > 7:
|
29
|
+
uname_info['additional_info'] = ' '.join(parts[7:]) # Any remaining info
|
30
|
+
|
31
|
+
return json.dumps(uname_info, indent=2)
|
@@ -1,27 +1,24 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: jpcli
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.0
|
4
4
|
Summary: A library to convert Linux command output to JSON
|
5
5
|
Home-page: https://github.com/JaimeAdanCuevas/jpcli
|
6
6
|
Author: Jaime Cuevas
|
7
7
|
Author-email: adancuevas@outlook.com
|
8
8
|
License: UNKNOWN
|
9
|
+
Description: # jpcli
|
10
|
+
|
11
|
+
jpcli is a library that converts the output of various Linux commands to JSON format.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```sh
|
16
|
+
pip install jpcli
|
17
|
+
|
18
|
+
|
9
19
|
Platform: UNKNOWN
|
10
20
|
Classifier: Programming Language :: Python :: 3
|
11
21
|
Classifier: License :: OSI Approved :: MIT License
|
12
22
|
Classifier: Operating System :: OS Independent
|
13
23
|
Requires-Python: >=3.6
|
14
24
|
Description-Content-Type: text/markdown
|
15
|
-
License-File: LICENCE
|
16
|
-
|
17
|
-
# jpcli
|
18
|
-
|
19
|
-
jpcli is a library that converts the output of various Linux commands to JSON format.
|
20
|
-
|
21
|
-
## Installation
|
22
|
-
|
23
|
-
```sh
|
24
|
-
pip install jpcli
|
25
|
-
|
26
|
-
|
27
|
-
|
jpcli-0.2.0/LICENCE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 Jaime Cuevas
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
@@ -1,12 +0,0 @@
|
|
1
|
-
def parse(cmdline_output):
|
2
|
-
"""
|
3
|
-
Parse the contents of /proc/cmdline.
|
4
|
-
"""
|
5
|
-
cmdline_dict = {}
|
6
|
-
for item in cmdline_output.strip().split():
|
7
|
-
if '=' in item:
|
8
|
-
key, value = item.split('=', 1)
|
9
|
-
cmdline_dict[key] = value
|
10
|
-
else:
|
11
|
-
cmdline_dict[item] = None
|
12
|
-
return cmdline_dict
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# cpuinfo_parser.py
|
2
|
-
|
3
|
-
def parse(command_output):
|
4
|
-
"""
|
5
|
-
Parses the output of the 'cat /proc/cpuinfo' command into a list of dictionaries,
|
6
|
-
where each dictionary contains information about one processor core.
|
7
|
-
|
8
|
-
Args:
|
9
|
-
command_output (str): The string output from the 'cat /proc/cpuinfo' command.
|
10
|
-
|
11
|
-
Returns:
|
12
|
-
list: A list of dictionaries, each representing a CPU core's information.
|
13
|
-
"""
|
14
|
-
processors = []
|
15
|
-
current_processor = {}
|
16
|
-
lines = command_output.splitlines()
|
17
|
-
for line in lines:
|
18
|
-
line = line.strip() # Remove leading and trailing whitespace
|
19
|
-
if line:
|
20
|
-
key_value_pair = line.split(':', 1) # Split only on the first colon
|
21
|
-
if len(key_value_pair) == 2:
|
22
|
-
key, value = key_value_pair
|
23
|
-
key = key.strip()
|
24
|
-
value = value.strip()
|
25
|
-
current_processor[key] = value
|
26
|
-
else:
|
27
|
-
# Handle new processor block (empty line)
|
28
|
-
if current_processor:
|
29
|
-
processors.append(current_processor)
|
30
|
-
current_processor = {}
|
31
|
-
if current_processor:
|
32
|
-
processors.append(current_processor)
|
33
|
-
return processors
|
@@ -1,12 +0,0 @@
|
|
1
|
-
def parse(dmesg_output):
|
2
|
-
"""
|
3
|
-
Parse the contents of dmesg output.
|
4
|
-
"""
|
5
|
-
try:
|
6
|
-
dmesg_lines = dmesg_output.strip().split('\n')
|
7
|
-
dmesg_list = []
|
8
|
-
for line in dmesg_lines:
|
9
|
-
dmesg_list.append(line)
|
10
|
-
return dmesg_list
|
11
|
-
except Exception as e:
|
12
|
-
return {"error": str(e), "message": "Failed to parse dmesg output"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
def parse(journalctl_output):
|
2
|
-
"""
|
3
|
-
Parse the contents of journalctl output.
|
4
|
-
"""
|
5
|
-
try:
|
6
|
-
journalctl_lines = journalctl_output.strip().split('\n')
|
7
|
-
journalctl_list = []
|
8
|
-
for line in journalctl_lines:
|
9
|
-
journalctl_list.append(line)
|
10
|
-
return journalctl_list
|
11
|
-
except Exception as e:
|
12
|
-
return {"error": str(e), "message": "Failed to parse journalctl output"}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
def parse(command_output):
|
2
|
-
lines = command_output.splitlines()
|
3
|
-
data = []
|
4
|
-
headers = []
|
5
|
-
|
6
|
-
# Extract headers from the first line
|
7
|
-
if lines:
|
8
|
-
headers = [header.strip() for header in lines[0].split() if header.strip()]
|
9
|
-
lines = lines[1:]
|
10
|
-
|
11
|
-
for line in lines:
|
12
|
-
if not line.strip(): # Skip empty lines
|
13
|
-
continue
|
14
|
-
|
15
|
-
values = [value.strip() for value in line.split() if value.strip()]
|
16
|
-
if len(values) != len(headers):
|
17
|
-
# For handling lines with different formats (like summary lines)
|
18
|
-
data.append({headers[0]: " ".join(values)})
|
19
|
-
else:
|
20
|
-
entry = {headers[i]: values[i] for i in range(len(headers))}
|
21
|
-
data.append(entry)
|
22
|
-
|
23
|
-
return data
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# jpcli/parsers/uname_parser.py
|
2
|
-
def parse(uname_output):
|
3
|
-
"""
|
4
|
-
Parse the output of the `uname` command.
|
5
|
-
"""
|
6
|
-
uname_info = uname_output.strip().split()
|
7
|
-
keys = ['sysname', 'nodename', 'release', 'version', 'machine', 'processor', 'hardware_platform', 'os']
|
8
|
-
return dict(zip(keys, uname_info))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|