erase.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. flux = usb.read_track(2)
  17. drive_ticks = (flux.index_list[0] + flux.index_list[1]) / 2
  18. del flux
  19. for t in args.tracks:
  20. cyl, head = t.cyl, t.head
  21. print("\rErasing Track %u.%u..." % (cyl, head), end="")
  22. usb.seek(t.physical_cyl, head)
  23. usb.erase_track(drive_ticks * 1.1)
  24. print()
  25. def main(argv):
  26. parser = util.ArgumentParser(usage='%(prog)s [options]')
  27. parser.add_argument("--device", help="greaseweazle device name")
  28. parser.add_argument("--drive", type=util.drive_letter, default='A',
  29. help="drive to write (A,B,0,1,2)")
  30. parser.add_argument("--tracks", type=util.TrackSet,
  31. help="which tracks to erase")
  32. parser.description = description
  33. parser.prog += ' ' + argv[1]
  34. args = parser.parse_args(argv[2:])
  35. try:
  36. usb = util.usb_open(args.device)
  37. tracks = util.TrackSet('c=0-81:h=0-1')
  38. if args.tracks is not None:
  39. tracks.update_from_trackspec(args.tracks.trackspec)
  40. args.tracks = tracks
  41. print("Erasing %s" % (args.tracks))
  42. util.with_drive_selected(erase, usb, args)
  43. except USB.CmdError as error:
  44. print("Command Failed: %s" % error)
  45. if __name__ == "__main__":
  46. main(sys.argv)
  47. # Local variables:
  48. # python-indent: 4
  49. # End: