Todo: Use a regular expression to breakdown drives
drives = "8:20-24,30,31,32,10:20-24,30,31,32"
Final output will look like this:
formatted_drives = [{8: [20,21,22,23,24,30,31,32]}, {10: [20,21,22,23,24,30,31,32]}]
Here is what the regex currently looks like:
regex_static_multiple_with_singles = re.match(r"""
(?P<enc>\d{1,3}): # Enclosure ID:
(?P<start>\d+) # Drive Start
- # Range -
(?P<end>\d+) # Drive End
(?P<singles>,\d+)+ # Drive Singles - todo resolve issue here
""", drives, (re.IGNORECASE | re.VERBOSE))
and what is returned:
[DEBUG ] All Drive Sequences: ['8:20-24,30,31,32', '10:20-24,30,31,32']
[DEBUG ] Enclosure ID : 8
[DEBUG ] Drive Start : 20
[DEBUG ] Drive End : 24
[DEBUG ] Drive List : [20, 21, 22, 23, 24]
[DEBUG ] Drive Singles : ,32
[DEBUG ] Enclosure ID : 10
[DEBUG ] Drive Start : 20
[DEBUG ] Drive End : 24
[DEBUG ] Drive List : [20, 21, 22, 23, 24]
[DEBUG ] Drive Singles : ,32
The issue is with drive singles only returning the last group. In this case there are 3x single drives, however, it is a variable quantity. What is the best method to return all single drives?
(?P<singles>(?:,\d+)+)and after getting a match, split that value with,.