Skip to content

Instantly share code, notes, and snippets.

@WinkelCode
Created June 28, 2023 23:55
Show Gist options
  • Save WinkelCode/00a1a999b07d1fcd6a6d31b130b40300 to your computer and use it in GitHub Desktop.
Save WinkelCode/00a1a999b07d1fcd6a6d31b130b40300 to your computer and use it in GitHub Desktop.
Python script to parse dumped config of Realtek NVMe Enclosures into usable config file
# Usage ./python3 cfgdumpparse.py mydumpedconfig.txt
# Warning: This is not a "end user" tool.
# Warning: Verify output by hand, it may include unwanted values.
# Warning: This tool may produce an incorrect config that can brick your device.
import re
import sys
try:
file = sys.argv[1]
with open(file, 'r') as cfg_file:
config_dump = cfg_file.read()
except IndexError:
print("No file specified")
sys.exit(1)
except FileNotFoundError:
print(f"File {file} not found")
sys.exit(1)
for line in config_dump.splitlines():
k_v_match = re.match(r'^([A-Z0-9_]+)\s*:\s*(.*)$', line)
if k_v_match:
key = k_v_match.group(1)
value = k_v_match.group(2)
if value != 'n/a':
print(f"{key} = {value}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment