Skip to content

Instantly share code, notes, and snippets.

@mic-e
Created October 17, 2015 14:07
Show Gist options
  • Save mic-e/0c9c809e76b7b815b0c7 to your computer and use it in GitHub Desktop.
Save mic-e/0c9c809e76b7b815b0c7 to your computer and use it in GitHub Desktop.
floppyrescue.py: ddrescues, re-formats and tests old floppy disks
#!/usr/bin/env python3
import os
import subprocess
import time
def main():
while True:
subprocess.call(['beep'])
try:
name = input("enter disk name: ")
except KeyboardInterrupt:
break
if os.path.exists(name):
print("name already exists")
continue
if subprocess.call(['mount', '/dev/sdb', '/tmp/m', '-oro']) == 0:
subprocess.call(['ls', '-l', '/tmp/m'])
if subprocess.call(['umount', '/dev/sdb']) != 0:
raise OSError("umount failed")
else:
print("could not mount")
if subprocess.call(['ddrescue', '/dev/sdb', name]) != 0:
raise OSError("ddrescue failed")
subprocess.call(['chown', 'mic', name])
if subprocess.call(['ufiformat', '-V', '-f', '1440', '/dev/sdb']) != 0:
for i in range(3):
subprocess.call(['beep'])
time.sleep(0.5)
print("\x1b[31;5mthis disk is broken\x1b[m")
else:
print("\x1b[32;1mthis disk is OK\x1b[m")
subprocess.call(['mkfs.vfat', '-I', '/dev/sdb'])
subprocess.call(['sync'])
subprocess.call(['eject', '/dev/sdb'])
print("\x1b[1mNEXT!\x1b[m")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment