jpcli 0.3.0__py3-none-any.whl → 0.4.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.
@@ -1,12 +1,19 @@
1
- def parse(cmdline_output):
2
- """
3
- Parse the contents of /proc/cmdline.
4
- """
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
5
9
  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
+
11
+ for param in params:
12
+ if '=' in param:
13
+ key, value = param.split('=', 1)
10
14
  else:
11
- cmdline_dict[item] = None
12
- return cmdline_dict
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)
@@ -1,33 +1,29 @@
1
- # cpuinfo_parser.py
1
+ import json
2
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
3
 
11
- Returns:
12
- list: A list of dictionaries, each representing a CPU core's information.
13
- """
4
+ def parse(command_output):
14
5
  processors = []
15
6
  current_processor = {}
7
+
16
8
  lines = command_output.splitlines()
17
9
  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
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
26
19
  else:
27
- # Handle new processor block (empty line)
20
+ # Empty line indicates the end of one processor's info
28
21
  if current_processor:
29
22
  processors.append(current_processor)
30
23
  current_processor = {}
24
+
25
+ # Append the last processor if exists
31
26
  if current_processor:
32
27
  processors.append(current_processor)
33
- return processors
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)
@@ -1,12 +1,13 @@
1
+ import json
2
+
3
+
1
4
  def parse(dmesg_output):
2
5
  """
3
6
  Parse the contents of dmesg output.
4
7
  """
5
8
  try:
6
9
  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
10
+ dmesg_list = [{"message": line} for line in dmesg_lines]
11
+ return json.dumps(dmesg_list, indent=2)
11
12
  except Exception as e:
12
- return {"error": str(e), "message": "Failed to parse dmesg output"}
13
+ return json.dumps({"error": str(e), "message": "Failed to parse dmesg output"}, indent=2)
@@ -1,4 +1,5 @@
1
1
  import re
2
+ import json
2
3
 
3
4
 
4
5
  def parse(ifconfig_output):
@@ -37,4 +38,4 @@ def parse(ifconfig_output):
37
38
  if current_interface:
38
39
  interfaces[current_interface['name']] = current_interface
39
40
 
40
- return interfaces
41
+ return json.dumps(interfaces, indent=2)
@@ -1,12 +1,27 @@
1
+ import json
2
+
3
+
1
4
  def parse(journalctl_output):
2
5
  """
3
6
  Parse the contents of journalctl output.
4
7
  """
5
8
  try:
9
+ # Split the output into individual lines
6
10
  journalctl_lines = journalctl_output.strip().split('\n')
11
+
12
+ # Initialize a list to store JSON objects
7
13
  journalctl_list = []
14
+
15
+ # Process each line
8
16
  for line in journalctl_lines:
9
- journalctl_list.append(line)
10
- return journalctl_list
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)
11
26
  except Exception as e:
12
- return {"error": str(e), "message": "Failed to parse journalctl output"}
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
- def parse(command_output):
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 here
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
- result = list(parse_section(lines, 0))
33
- return result
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)
@@ -1,7 +1,11 @@
1
+ import json
2
+
3
+
1
4
  def parse(command_output):
2
5
  lines = command_output.splitlines()
3
- data = []
6
+ memory_blocks = []
4
7
  headers = []
8
+ summary = {}
5
9
 
6
10
  # Extract headers from the first line
7
11
  if lines:
@@ -12,12 +16,19 @@ def parse(command_output):
12
16
  if not line.strip(): # Skip empty lines
13
17
  continue
14
18
 
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
+ # Check if the line contains summary information
20
+ if ':' in line:
21
+ key, value = line.split(':')
22
+ summary[key.strip().lower().replace(' ', '_')] = value.strip()
19
23
  else:
20
- entry = {headers[i]: values[i] for i in range(len(headers))}
21
- data.append(entry)
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
+ }
22
33
 
23
- return data
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
- # jpcli/parsers/os_release_parser.py
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)
@@ -1,8 +1,31 @@
1
- # jpcli/parsers/uname_parser.py
2
- def parse(uname_output):
1
+ import json
2
+
3
+
4
+ def parse(command_output):
3
5
  """
4
- Parse the output of the `uname` command.
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.
5
13
  """
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))
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,16 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jpcli
3
- Version: 0.3.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
+ License: UNKNOWN
9
+ Platform: UNKNOWN
8
10
  Classifier: Programming Language :: Python :: 3
9
11
  Classifier: License :: OSI Approved :: MIT License
10
12
  Classifier: Operating System :: OS Independent
11
13
  Requires-Python: >=3.6
12
14
  Description-Content-Type: text/markdown
13
- License-File: LICENCE
14
15
 
15
16
  # jpcli
16
17
 
@@ -21,3 +22,5 @@ jpcli is a library that converts the output of various Linux commands to JSON fo
21
22
  ```sh
22
23
  pip install jpcli
23
24
 
25
+
26
+
@@ -0,0 +1,25 @@
1
+ jpcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ jpcli/main.py,sha256=yBIyZLm16x3sEI3iBw3uUHjFnJLzUd7evS1qN85M1HU,2610
3
+ jpcli/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ jpcli/parsers/cmdline_parser.py,sha256=S8PZjDTkxyz2IAY3hBvHDekWRGCkj9MHiLi2haupUZM,562
5
+ jpcli/parsers/cpuinfo_parser.py,sha256=aL6NZ-_O_wmGRdZSzm7SttCngWoW7eqWckubxPWFpJk,973
6
+ jpcli/parsers/df_parser.py,sha256=E2s8c6i60iKrS4IcCv_L_Fu5vDE_xnOTklAk_PFM5T4,549
7
+ jpcli/parsers/dmesg_parser.py,sha256=v4i7inWGRKycyDIvjTyGaSBIYQZf7tNTJ4lxKKvKSN4,397
8
+ jpcli/parsers/free_parser.py,sha256=GJuJKCT4cIN4O5D-rHjalx-6FzDT6-lpUurmh9PnUKE,721
9
+ jpcli/parsers/ifconfig_parser.py,sha256=zEfTi8zdYnpQ4QNgZh1I31Z-mY9F1uAXGV9f6knJeJ0,1353
10
+ jpcli/parsers/journalctl_parser.py,sha256=z9_6_8Gu798pQekosMCfoieCDGxbNcxOGcbteg4fzQk,949
11
+ jpcli/parsers/lscpu_parser.py,sha256=b_OzMysCshP2lXY2Vmc-MJlxlYXocNTOvr7DHUeWkvQ,661
12
+ jpcli/parsers/lshw_parser.py,sha256=0zoSIvYax2Ut_cNxQ8krPMPmiUyaV9n4sOIkXjtMrCA,1623
13
+ jpcli/parsers/lsmem_parser.py,sha256=czWYUx6gwy2Z0nrLM5rJxBDz2HFQC9HSew2cenC-1vA,985
14
+ jpcli/parsers/mcelog_parser.py,sha256=GLZlj_Yl1KAzuTFotosudWPBAi_VhkBGdeKUbjNFhuk,412
15
+ jpcli/parsers/os_release_parser.py,sha256=XQetNqNxmjMMdQPgqKS9XLQIoa5T7DMAcOTJJ0gmhCo,352
16
+ jpcli/parsers/uname_parser.py,sha256=Yx59k9JzzfNgKZ9pt3hhfSwk0o9Ow1kqQdQNWUF6asc,1040
17
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ tests/test_lsmem_parser.py,sha256=mRlHTmU2ZmcxPGgcqAv_LNGs56yrwDBiw2-aHKrpuEo,793
19
+ tests/test_other_command_parser.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ jpcli-0.4.0.dist-info/LICENCE,sha256=-unHZSaIlcrVEVD56Ss5dlOvdgK682a2xitz35UlKt4,1069
21
+ jpcli-0.4.0.dist-info/METADATA,sha256=3KfCVsK1e1wxOccgV0JAOhSVhXQqIL2CirEhh5JyIB0,603
22
+ jpcli-0.4.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
23
+ jpcli-0.4.0.dist-info/entry_points.txt,sha256=6wCYs9scOVGFsZE-b2r2geNzy4uST0GgWyHmveiPSxE,43
24
+ jpcli-0.4.0.dist-info/top_level.txt,sha256=djdbp8mEzCmAEbrMOVEHNW4LIabBwnpLURp2dX_ZQbA,12
25
+ jpcli-0.4.0.dist-info/RECORD,,
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  jpcli = jpcli.main:main
3
+
@@ -1,25 +0,0 @@
1
- jpcli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- jpcli/main.py,sha256=yBIyZLm16x3sEI3iBw3uUHjFnJLzUd7evS1qN85M1HU,2610
3
- jpcli/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- jpcli/parsers/cmdline_parser.py,sha256=HKiI_iGS1Iy6JKJFLUFPsfxyqYo57rPonKfvFfmQTqg,336
5
- jpcli/parsers/cpuinfo_parser.py,sha256=weYBoGBL8e82kkRAtAJvmWOMx-R3L72gRNKmgAg3DWQ,1177
6
- jpcli/parsers/df_parser.py,sha256=NC377ld_uUo9MxkGrxYjCAyFq2BdAQL4pgJtz4u3kL8,513
7
- jpcli/parsers/dmesg_parser.py,sha256=76AkYlcVvo3_5qzuPreTQaelPsExaEct1NDfniiySM0,367
8
- jpcli/parsers/free_parser.py,sha256=GJuJKCT4cIN4O5D-rHjalx-6FzDT6-lpUurmh9PnUKE,721
9
- jpcli/parsers/ifconfig_parser.py,sha256=KgtXPGG6QKKFID4YjHwJbL-jbTVoFB8SBjIyop2ICL4,1319
10
- jpcli/parsers/journalctl_parser.py,sha256=1pGAlrM7oe2vOCnspjdHk_RqDUDxlL2sBpfJJXlWxDU,412
11
- jpcli/parsers/lscpu_parser.py,sha256=8kAqrFLyVR-vEW6ODlx1fwF1HRNeCTt2CHQ2ZI1bQWg,881
12
- jpcli/parsers/lshw_parser.py,sha256=QUHE3ya64aaH9Md0VqMK-YQo457W8V8RgClxS41zRx8,1558
13
- jpcli/parsers/lsmem_parser.py,sha256=vdIyK0xsbrfkqxWOx6jLz-2gsrH5Ii-8mwx-PkL_fXI,744
14
- jpcli/parsers/mcelog_parser.py,sha256=z62xUwSy_DU-KlPh6d-Xmrz2qMQYVG8JDs7aZE7i7Gk,376
15
- jpcli/parsers/os_release_parser.py,sha256=5x_tjsG2Jvw1Lx-hVHHbuAMc3d8POPXDQ7Kt9Ux6GG4,353
16
- jpcli/parsers/uname_parser.py,sha256=dSPRtiSVxeBt7fdQCjU_zVvf63eU-lwxoOPMlahWkfQ,311
17
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- tests/test_lsmem_parser.py,sha256=mRlHTmU2ZmcxPGgcqAv_LNGs56yrwDBiw2-aHKrpuEo,793
19
- tests/test_other_command_parser.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- jpcli-0.3.0.dist-info/LICENCE,sha256=-unHZSaIlcrVEVD56Ss5dlOvdgK682a2xitz35UlKt4,1069
21
- jpcli-0.3.0.dist-info/METADATA,sha256=1n8NhyvwN28olreU2U7kSTdN0CEaQdmJsRxOktO1m_Y,588
22
- jpcli-0.3.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
23
- jpcli-0.3.0.dist-info/entry_points.txt,sha256=HhCHDzZ91U7qT2KJDi76ewNFC1rehEQyD1sP0nIvDw0,42
24
- jpcli-0.3.0.dist-info/top_level.txt,sha256=djdbp8mEzCmAEbrMOVEHNW4LIabBwnpLURp2dX_ZQbA,12
25
- jpcli-0.3.0.dist-info/RECORD,,
File without changes
File without changes