jpcli 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
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/main.py +4 -4
- jpcli/parsers/free_parser.py +22 -0
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/METADATA +4 -4
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/RECORD +8 -7
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/LICENCE +0 -0
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/WHEEL +0 -0
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/entry_points.txt +0 -0
- {jpcli-0.1.0.dist-info → jpcli-0.1.1.dist-info}/top_level.txt +0 -0
jpcli/main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
import argparse
|
3
3
|
import subprocess
|
4
|
-
from .parsers import lsmem_parser, other_command_parser
|
4
|
+
from .parsers import lsmem_parser, free_parser, other_command_parser
|
5
5
|
|
6
6
|
def run_command(command):
|
7
7
|
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
@@ -9,10 +9,10 @@ def run_command(command):
|
|
9
9
|
raise RuntimeError(f"Command '{command}' failed with error: {result.stderr.decode()}")
|
10
10
|
return result.stdout.decode()
|
11
11
|
|
12
|
-
def parse_command_output(command_output, parser_name
|
12
|
+
def parse_command_output(command_output, parser_name):
|
13
13
|
parsers = {
|
14
|
-
'': lsmem_parser.parse,
|
15
|
-
'
|
14
|
+
'lsmem': lsmem_parser.parse,
|
15
|
+
'free': free_parser.parse,
|
16
16
|
# Add other parsers here
|
17
17
|
}
|
18
18
|
if parser_name in parsers:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
def parse(command_output):
|
4
|
+
lines = command_output.strip().split('\n')
|
5
|
+
headers = lines[0].split()
|
6
|
+
memory_data = []
|
7
|
+
|
8
|
+
for line in lines[1:]:
|
9
|
+
values = line.split()
|
10
|
+
# Ensure that the length of headers and values are the same
|
11
|
+
if len(values) == len(headers):
|
12
|
+
entry = {headers[i]: values[i] for i in range(len(headers))}
|
13
|
+
else:
|
14
|
+
# Handle cases where the line might not match header length
|
15
|
+
entry = {}
|
16
|
+
for i in range(len(values)):
|
17
|
+
key = headers[i] if i < len(headers) else f'unknown_{i}'
|
18
|
+
entry[key] = values[i]
|
19
|
+
memory_data.append(entry)
|
20
|
+
|
21
|
+
return json.dumps(memory_data, indent=2)
|
22
|
+
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: jpcli
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: A library to convert Linux command output to JSON
|
5
|
-
Home-page: https://github.com/JaimeAdanCuevas/
|
5
|
+
Home-page: https://github.com/JaimeAdanCuevas/jpcli
|
6
6
|
Author: Jaime Cuevas
|
7
7
|
Author-email: adancuevas@outlook.com
|
8
8
|
License: UNKNOWN
|
@@ -14,9 +14,9 @@ Requires-Python: >=3.6
|
|
14
14
|
Description-Content-Type: text/markdown
|
15
15
|
License-File: LICENCE
|
16
16
|
|
17
|
-
#
|
17
|
+
# jpcli
|
18
18
|
|
19
|
-
|
19
|
+
jpcli is a library that converts the output of various Linux commands to JSON format.
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
@@ -1,14 +1,15 @@
|
|
1
1
|
jpcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
jpcli/main.py,sha256=
|
2
|
+
jpcli/main.py,sha256=foB1DnJZQG6hhJs71okST_Sb5zW2dknRTyJPkYsUpU4,1238
|
3
3
|
jpcli/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
jpcli/parsers/free_parser.py,sha256=XymIi1eafmIElMMVxS3DmlZ-oC4dcYvKmNWDm5tCEEs,721
|
4
5
|
jpcli/parsers/lsmem_parser.py,sha256=wlOInwE_gkrarxvRp-4_tk1zCbb3RDGHyLME56AR7Go,321
|
5
6
|
jpcli/parsers/other_command_parser.py,sha256=G2so9nFluHiyuyEDJouxuN4FHkNheyIY_laDFXxE6xM,134
|
6
7
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
8
|
tests/test_lsmem_parser.py,sha256=maT0mCSFyAHCMdRMl0NEa-FUE_2-MMDoYZS5W67PYZU,791
|
8
9
|
tests/test_other_command_parser.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
jpcli-0.1.
|
10
|
-
jpcli-0.1.
|
11
|
-
jpcli-0.1.
|
12
|
-
jpcli-0.1.
|
13
|
-
jpcli-0.1.
|
14
|
-
jpcli-0.1.
|
10
|
+
jpcli-0.1.1.dist-info/LICENCE,sha256=-unHZSaIlcrVEVD56Ss5dlOvdgK682a2xitz35UlKt4,1069
|
11
|
+
jpcli-0.1.1.dist-info/METADATA,sha256=nbis0NNP6q8GhqNmtckScuiCKD8XHRr8HRYC6HcAG3s,625
|
12
|
+
jpcli-0.1.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
13
|
+
jpcli-0.1.1.dist-info/entry_points.txt,sha256=6wCYs9scOVGFsZE-b2r2geNzy4uST0GgWyHmveiPSxE,43
|
14
|
+
jpcli-0.1.1.dist-info/top_level.txt,sha256=djdbp8mEzCmAEbrMOVEHNW4LIabBwnpLURp2dX_ZQbA,12
|
15
|
+
jpcli-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|