jpcli 0.1.1__py3-none-any.whl → 0.1.3__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 +15 -4
- jpcli/parsers/lsmem_parser.py +19 -6
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/METADATA +1 -1
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/RECORD +8 -8
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/LICENCE +0 -0
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/WHEEL +0 -0
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/entry_points.txt +0 -0
- {jpcli-0.1.1.dist-info → jpcli-0.1.3.dist-info}/top_level.txt +0 -0
jpcli/main.py
CHANGED
@@ -23,12 +23,23 @@ def parse_command_output(command_output, parser_name):
|
|
23
23
|
def main():
|
24
24
|
parser = argparse.ArgumentParser(description='JP - JSON Parser for Linux commands')
|
25
25
|
parser.add_argument('command', type=str, help='The Linux command to run')
|
26
|
-
parser.add_argument('parser_name', type=str, nargs='?', default=
|
26
|
+
parser.add_argument('parser_name', type=str, nargs='?', default=None, help='The name of the parser to use')
|
27
27
|
|
28
28
|
args = parser.parse_args()
|
29
29
|
result = jpcli(args.command, args.parser_name)
|
30
30
|
print(result)
|
31
31
|
|
32
|
-
def jpcli(command, parser_name):
|
33
|
-
|
34
|
-
|
32
|
+
def jpcli(command, parser_name=None):
|
33
|
+
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
34
|
+
if result.returncode != 0:
|
35
|
+
print(f"Error: {result.stderr}", file=sys.stderr)
|
36
|
+
sys.exit(result.returncode)
|
37
|
+
|
38
|
+
command_output = result.stdout
|
39
|
+
if parser_name is None:
|
40
|
+
parser_name = command.split()[0] # Use the first word of the command as the parser name
|
41
|
+
return parse_command_output(command_output, parser_name)
|
42
|
+
|
43
|
+
if __name__ == '__main__':
|
44
|
+
main()
|
45
|
+
|
jpcli/parsers/lsmem_parser.py
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
def parse(command_output):
|
2
|
-
lines = command_output.
|
3
|
-
headers = [header.strip() for header in lines[0].split()]
|
2
|
+
lines = command_output.splitlines()
|
4
3
|
data = []
|
4
|
+
headers = []
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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)
|
10
22
|
|
11
23
|
return data
|
24
|
+
|
@@ -1,15 +1,15 @@
|
|
1
1
|
jpcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
jpcli/main.py,sha256=
|
2
|
+
jpcli/main.py,sha256=yqnw53CJ6cBFtV6X1ujy3sfKGu9I3Tp9Rrrm1gcOauU,1653
|
3
3
|
jpcli/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
jpcli/parsers/free_parser.py,sha256=XymIi1eafmIElMMVxS3DmlZ-oC4dcYvKmNWDm5tCEEs,721
|
5
|
-
jpcli/parsers/lsmem_parser.py,sha256=
|
5
|
+
jpcli/parsers/lsmem_parser.py,sha256=EFGZISeaH9esGOnj_lYX0_biZjKnWo23dtDY9-LZ42s,745
|
6
6
|
jpcli/parsers/other_command_parser.py,sha256=G2so9nFluHiyuyEDJouxuN4FHkNheyIY_laDFXxE6xM,134
|
7
7
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
tests/test_lsmem_parser.py,sha256=maT0mCSFyAHCMdRMl0NEa-FUE_2-MMDoYZS5W67PYZU,791
|
9
9
|
tests/test_other_command_parser.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
jpcli-0.1.
|
11
|
-
jpcli-0.1.
|
12
|
-
jpcli-0.1.
|
13
|
-
jpcli-0.1.
|
14
|
-
jpcli-0.1.
|
15
|
-
jpcli-0.1.
|
10
|
+
jpcli-0.1.3.dist-info/LICENCE,sha256=-unHZSaIlcrVEVD56Ss5dlOvdgK682a2xitz35UlKt4,1069
|
11
|
+
jpcli-0.1.3.dist-info/METADATA,sha256=UKRlNwr6g41gzrQT1zw2xNbiVun-CZ0NU-uoyAhu--w,625
|
12
|
+
jpcli-0.1.3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
13
|
+
jpcli-0.1.3.dist-info/entry_points.txt,sha256=6wCYs9scOVGFsZE-b2r2geNzy4uST0GgWyHmveiPSxE,43
|
14
|
+
jpcli-0.1.3.dist-info/top_level.txt,sha256=djdbp8mEzCmAEbrMOVEHNW4LIabBwnpLURp2dX_ZQbA,12
|
15
|
+
jpcli-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|