Adds md device support, improved file handling, and PEP8 fixes

Replaces the awk command to find devices with some easier-to-read Python, which adds 'md' devices to the list of tracked devices.

Replaces manual opening/closing of file with 'with' statements.

Fixes every warning/error produced by PEP8 except for E501 (line >80 chars). To see a more concise list of changes, use diff -w.