erase.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # greaseweazle/tools/erase.py
  2. #
  3. # Greaseweazle control script: Erase a Disk.
  4. #
  5. # Written & released by Keir Fraser <keir.xen@gmail.com>
  6. #
  7. # This is free and unencumbered software released into the public domain.
  8. # See the file COPYING for more details, or visit <http://unlicense.org>.
  9. description = "Erase a disk."
  10. import sys
  11. from greaseweazle.tools import util
  12. from greaseweazle import usb as USB
  13. def erase(usb, args):
  14. # @drive_ticks is the time in Greaseweazle ticks between index pulses.
  15. # We will adjust the flux intervals per track to allow for this.
  16. drive_ticks = usb.read_track(2).ticks_per_rev
  17. for t in args.tracks:
  18. cyl, head = t.cyl, t.head
  19. print("\rErasing Track %u.%u..." % (cyl, head), end="")
  20. usb.seek(t.physical_cyl, head)
  21. usb.erase_track(drive_ticks * 1.1)
  22. print()
  23. def main(argv):
  24. parser = util.ArgumentParser(usage='%(prog)s [options]')
  25. parser.add_argument("--device", help="greaseweazle device name")
  26. parser.add_argument("--drive", type=util.drive_letter, default='A',
  27. help="drive to write (A,B,0,1,2)")
  28. parser.add_argument("--tracks", type=util.TrackSet,
  29. help="which tracks to erase")
  30. parser.description = description
  31. parser.prog += ' ' + argv[1]
  32. args = parser.parse_args(argv[2:])
  33. try:
  34. usb = util.usb_open(args.device)
  35. tracks = util.TrackSet('c=0-81:h=0-1')
  36. if args.tracks is not None:
  37. tracks.update_from_trackspec(args.tracks.trackspec)
  38. args.tracks = tracks
  39. print("Erasing %s" % (args.tracks))
  40. util.with_drive_selected(erase, usb, args)
  41. except USB.CmdError as error:
  42. print("Command Failed: %s" % error)
  43. if __name__ == "__main__":
  44. main(sys.argv)
  45. # Local variables:
  46. # python-indent: 4
  47. # End: