jpcli 0.1.0__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/__init__.py +0 -0
- jpcli/main.py +34 -0
- jpcli/parsers/__init__.py +0 -0
- jpcli/parsers/lsmem_parser.py +11 -0
- jpcli/parsers/other_command_parser.py +5 -0
- jpcli-0.1.0.dist-info/LICENCE +21 -0
- jpcli-0.1.0.dist-info/METADATA +27 -0
- jpcli-0.1.0.dist-info/RECORD +14 -0
- jpcli-0.1.0.dist-info/WHEEL +5 -0
- jpcli-0.1.0.dist-info/entry_points.txt +3 -0
- jpcli-0.1.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/test_lsmem_parser.py +19 -0
- tests/test_other_command_parser.py +0 -0
jpcli/__init__.py
ADDED
File without changes
|
jpcli/main.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
import argparse
|
3
|
+
import subprocess
|
4
|
+
from .parsers import lsmem_parser, other_command_parser
|
5
|
+
|
6
|
+
def run_command(command):
|
7
|
+
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
8
|
+
if result.returncode != 0:
|
9
|
+
raise RuntimeError(f"Command '{command}' failed with error: {result.stderr.decode()}")
|
10
|
+
return result.stdout.decode()
|
11
|
+
|
12
|
+
def parse_command_output(command_output, parser_name=''):
|
13
|
+
parsers = {
|
14
|
+
'': lsmem_parser.parse,
|
15
|
+
'other_command': other_command_parser.parse,
|
16
|
+
# Add other parsers here
|
17
|
+
}
|
18
|
+
if parser_name in parsers:
|
19
|
+
return parsers[parser_name](command_output)
|
20
|
+
else:
|
21
|
+
raise ValueError(f"No parser found for {parser_name}")
|
22
|
+
|
23
|
+
def main():
|
24
|
+
parser = argparse.ArgumentParser(description='JP - JSON Parser for Linux commands')
|
25
|
+
parser.add_argument('command', type=str, help='The Linux command to run')
|
26
|
+
parser.add_argument('parser_name', type=str, nargs='?', default='', help='The name of the parser to use')
|
27
|
+
|
28
|
+
args = parser.parse_args()
|
29
|
+
result = jpcli(args.command, args.parser_name)
|
30
|
+
print(result)
|
31
|
+
|
32
|
+
def jpcli(command, parser_name):
|
33
|
+
output = run_command(command)
|
34
|
+
return parse_command_output(output, parser_name)
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def parse(command_output):
|
2
|
+
lines = command_output.strip().splitlines()
|
3
|
+
headers = [header.strip() for header in lines[0].split()]
|
4
|
+
data = []
|
5
|
+
|
6
|
+
for line in lines[1:]:
|
7
|
+
values = line.split()
|
8
|
+
entry = {headers[i]: values[i] for i in range(len(values))}
|
9
|
+
data.append(entry)
|
10
|
+
|
11
|
+
return data
|
@@ -0,0 +1,21 @@
|
|
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.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: jpcli
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A library to convert Linux command output to JSON
|
5
|
+
Home-page: https://github.com/JaimeAdanCuevas/jp
|
6
|
+
Author: Jaime Cuevas
|
7
|
+
Author-email: adancuevas@outlook.com
|
8
|
+
License: UNKNOWN
|
9
|
+
Platform: UNKNOWN
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Classifier: Operating System :: OS Independent
|
13
|
+
Requires-Python: >=3.6
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
License-File: LICENCE
|
16
|
+
|
17
|
+
# JP
|
18
|
+
|
19
|
+
JP 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
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
jpcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
jpcli/main.py,sha256=nxYET5ctdYLVxjyVzckMwU2g7te8U12m43kLUlkaDfA,1241
|
3
|
+
jpcli/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
jpcli/parsers/lsmem_parser.py,sha256=wlOInwE_gkrarxvRp-4_tk1zCbb3RDGHyLME56AR7Go,321
|
5
|
+
jpcli/parsers/other_command_parser.py,sha256=G2so9nFluHiyuyEDJouxuN4FHkNheyIY_laDFXxE6xM,134
|
6
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
tests/test_lsmem_parser.py,sha256=maT0mCSFyAHCMdRMl0NEa-FUE_2-MMDoYZS5W67PYZU,791
|
8
|
+
tests/test_other_command_parser.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
jpcli-0.1.0.dist-info/LICENCE,sha256=-unHZSaIlcrVEVD56Ss5dlOvdgK682a2xitz35UlKt4,1069
|
10
|
+
jpcli-0.1.0.dist-info/METADATA,sha256=HRs4zmnRiLinqrU9BgGtqjFfLMXVm1NVl_v-QDWsDls,616
|
11
|
+
jpcli-0.1.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
12
|
+
jpcli-0.1.0.dist-info/entry_points.txt,sha256=6wCYs9scOVGFsZE-b2r2geNzy4uST0GgWyHmveiPSxE,43
|
13
|
+
jpcli-0.1.0.dist-info/top_level.txt,sha256=djdbp8mEzCmAEbrMOVEHNW4LIabBwnpLURp2dX_ZQbA,12
|
14
|
+
jpcli-0.1.0.dist-info/RECORD,,
|
tests/__init__.py
ADDED
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import unittest
|
2
|
+
from jpcli.parsers import lsmem_parser
|
3
|
+
|
4
|
+
class TestLsmemParser(unittest.TestCase):
|
5
|
+
|
6
|
+
def test_parse(self):
|
7
|
+
command_output = """\
|
8
|
+
RANGE SIZE STATE REMOVABLE BLOCK
|
9
|
+
0x0000000000000000-0x000000007fffffff 2G online no 0-15
|
10
|
+
0x0000000100000000-0x000000017fffffff 2G online no 16-31
|
11
|
+
"""
|
12
|
+
expected_output = [
|
13
|
+
{"RANGE": "0x0000000000000000-0x000000007fffffff", "SIZE": "2G", "STATE": "online", "REMOVABLE": "no", "BLOCK": "0-15"},
|
14
|
+
{"RANGE": "0x0000000100000000-0x000000017fffffff", "SIZE": "2G", "STATE": "online", "REMOVABLE": "no", "BLOCK": "16-31"},
|
15
|
+
]
|
16
|
+
self.assertEqual(lsmem_parser.parse(command_output), expected_output)
|
17
|
+
|
18
|
+
if __name__ == '__main__':
|
19
|
+
unittest.main()
|
File without changes
|