jpcli 0.3.0__tar.gz → 0.5.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.
Files changed (37) hide show
  1. {jpcli-0.3.0 → jpcli-0.5.0}/LICENCE +0 -0
  2. {jpcli-0.3.0 → jpcli-0.5.0}/MANIFEST.in +0 -0
  3. {jpcli-0.3.0/jpcli.egg-info → jpcli-0.5.0}/PKG-INFO +5 -1
  4. {jpcli-0.3.0 → jpcli-0.5.0}/README.md +0 -0
  5. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/__init__.py +0 -0
  6. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/main.py +0 -0
  7. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/__init__.py +0 -0
  8. jpcli-0.5.0/jpcli/parsers/cmdline_parser.py +19 -0
  9. jpcli-0.5.0/jpcli/parsers/cpuinfo_parser.py +29 -0
  10. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/df_parser.py +4 -1
  11. jpcli-0.5.0/jpcli/parsers/dmesg_parser.py +13 -0
  12. jpcli-0.5.0/jpcli/parsers/free_parser.py +23 -0
  13. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/ifconfig_parser.py +2 -1
  14. jpcli-0.5.0/jpcli/parsers/journalctl_parser.py +27 -0
  15. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/lscpu_parser.py +4 -14
  16. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/lshw_parser.py +13 -9
  17. jpcli-0.5.0/jpcli/parsers/lsmem_parser.py +34 -0
  18. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/mcelog_parser.py +4 -1
  19. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli/parsers/os_release_parser.py +4 -2
  20. jpcli-0.5.0/jpcli/parsers/uname_parser.py +31 -0
  21. {jpcli-0.3.0 → jpcli-0.5.0/jpcli.egg-info}/PKG-INFO +5 -1
  22. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli.egg-info/SOURCES.txt +0 -0
  23. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli.egg-info/dependency_links.txt +0 -0
  24. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli.egg-info/entry_points.txt +1 -0
  25. {jpcli-0.3.0 → jpcli-0.5.0}/jpcli.egg-info/top_level.txt +0 -0
  26. {jpcli-0.3.0 → jpcli-0.5.0}/setup.cfg +0 -0
  27. {jpcli-0.3.0 → jpcli-0.5.0}/setup.py +1 -1
  28. {jpcli-0.3.0 → jpcli-0.5.0}/tests/__init__.py +0 -0
  29. {jpcli-0.3.0 → jpcli-0.5.0}/tests/test_lsmem_parser.py +0 -0
  30. {jpcli-0.3.0 → jpcli-0.5.0}/tests/test_other_command_parser.py +0 -0
  31. jpcli-0.3.0/jpcli/parsers/cmdline_parser.py +0 -12
  32. jpcli-0.3.0/jpcli/parsers/cpuinfo_parser.py +0 -33
  33. jpcli-0.3.0/jpcli/parsers/dmesg_parser.py +0 -12
  34. jpcli-0.3.0/jpcli/parsers/free_parser.py +0 -22
  35. jpcli-0.3.0/jpcli/parsers/journalctl_parser.py +0 -12
  36. jpcli-0.3.0/jpcli/parsers/lsmem_parser.py +0 -23
  37. jpcli-0.3.0/jpcli/parsers/uname_parser.py +0 -8
File without changes
File without changes
@@ -1,10 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jpcli
3
- Version: 0.3.0
3
+ Version: 0.5.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
@@ -21,3 +23,5 @@ jpcli is a library that converts the output of various Linux commands to JSON fo
21
23
  ```sh
22
24
  pip install jpcli
23
25
 
26
+
27
+
File without changes
File without changes
File without changes
File without changes
@@ -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,23 @@
1
+ import json
2
+
3
+
4
+ def parse(command_output):
5
+ lines = command_output.strip().split("\n")
6
+ headers = lines[0].split()
7
+ memory_data = []
8
+
9
+ for line in lines[1:]:
10
+ values = line.split()
11
+ category = values[0].strip(":") # Extract "Mem" or "Swap"
12
+ values = values[1:] # Remove category from values
13
+
14
+ # Ensure proper key-value matching
15
+ if len(values) == len(headers):
16
+ entry = {headers[i]: values[i] for i in range(len(headers))}
17
+ else:
18
+ entry = {headers[i]: values[i] if i < len(values) else "N/A" for i in range(len(headers))}
19
+
20
+ entry["category"] = category # Add category name separately
21
+ memory_data.append(entry)
22
+
23
+ return json.dumps(memory_data, 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)
@@ -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
- 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)
@@ -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
- # 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)
@@ -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,10 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jpcli
3
- Version: 0.3.0
3
+ Version: 0.5.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
@@ -21,3 +23,5 @@ jpcli is a library that converts the output of various Linux commands to JSON fo
21
23
  ```sh
22
24
  pip install jpcli
23
25
 
26
+
27
+
File without changes
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  jpcli = jpcli.main:main
3
+
File without changes
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="jpcli",
8
- version="0.3.0",
8
+ version="0.5.0",
9
9
  author="Jaime Cuevas",
10
10
  author_email="adancuevas@outlook.com",
11
11
  description="A library to convert Linux command output to JSON",
File without changes
File without changes
@@ -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,22 +0,0 @@
1
- import json
2
-
3
-
4
- def parse(command_output):
5
- lines = command_output.strip().split('\n')
6
- headers = lines[0].split()
7
- memory_data = []
8
-
9
- for line in lines[1:]:
10
- values = line.split()
11
- # Ensure that the length of headers and values are the same
12
- if len(values) == len(headers):
13
- entry = {headers[i]: values[i] for i in range(len(headers))}
14
- else:
15
- # Handle cases where the line might not match header length
16
- entry = {}
17
- for i in range(len(values)):
18
- key = headers[i] if i < len(headers) else f'unknown_{i}'
19
- entry[key] = values[i]
20
- memory_data.append(entry)
21
-
22
- return json.dumps(memory_data, indent=2)
@@ -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))