Skip to content

Instantly share code, notes, and snippets.

@bioshazard
Last active June 13, 2018 19:51
Show Gist options
  • Save bioshazard/b5dbee513c1835e1c3ebebd324660b3f to your computer and use it in GitHub Desktop.
Save bioshazard/b5dbee513c1835e1c3ebebd324660b3f to your computer and use it in GitHub Desktop.
# In case you wanted to parse `smart -A ...`
smartAttributesPattern = "".join([
"\n *", # Ignore: Potential whitespace in front of ID#
"([0-9]+)", # Capture: ID# field
"[^A-Z]+", # Ignore: Whitespace before the ATTRIBUTE_NAME
"([a-zA-Z_\-]+)", # Capture: ATTRIBUTE_NAME field
"[^0-9a-fx]+", # Ignore: Whitespace before the FLAG
"([0-9a-fx]+)", # Capture: FLAG field
"[^0-9]+", # Ignore: Whitespace before the VALUE
"([0-9]+)", # Capture: VALUE field
"[^0-9]+", # Ignore: Whitespace before the WORST
"([0-9]+)", # Capture: WORST field
"[^0-9]+", # Ignore: Whitespace before the THRESH
"([0-9]+)", # Capture: THRESH field
"[^A-Z]+", # Ignore: Whitespace before the TYPE
"([A-Za-z_\-]+)", # Capture: TYPE field
"[^A-Z]+", # Ignore: Whitespace before the UPDATED
"([A-Za-z]+)", # Capture: UPDATED field
"[^A-Za-z_\-]+", # Ignore: Whitespace before WHEN_FAILED
"([A-Za-z_\-]+)", # Capture: WHEN_FAILED field
"[^0-9]+", # Ignore: Whitespace before RAW_VALUE
"([ A-Za-z0-9)(/]+)" # Capture: RAW_VALUE field
])
matches = re.findall(smartAttributesPattern, smartDataSection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment