Ratinox 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. """
  3. Perform demented installation tasks with blind rodents.
  4. """
  5. import subprocess, os, time, xvfbwrapper, shutil, argparse
  6. screencap_dir = "/cryptech-builder"
  7. screencap_file = os.path.join(screencap_dir, "Xvfb_screen0")
  8. def snooze(how_long = 15):
  9. time.sleep(how_long)
  10. def click(*coordinates):
  11. assert len(coordinates) in (0, 2)
  12. if coordinates:
  13. subprocess.check_call(("ratpoison", "-c", "ratwarp {:d} {:d}".format(*coordinates)))
  14. shutil.copy(screencap_file, "{}.{:f}.xwd".format(screencap_file, time.time()))
  15. subprocess.check_call(("ratpoison", "-c", "ratclick"))
  16. with xvfbwrapper.Xvfb(fbdir = screencap_dir):
  17. print("DISPLAY={}".format(os.getenv("DISPLAY")))
  18. print("Starting rodent-free window manager")
  19. rat = subprocess.Popen(("ratpoison",))
  20. time.sleep(0.5)
  21. snooze()
  22. print("Starting XiLinx installer")
  23. xsetup = subprocess.Popen(("./xsetup",), cwd = os.getenv("XILINX_PKGDIR"))
  24. snooze()
  25. print("First screen")
  26. click(650, 610)
  27. snooze()
  28. print("Second screen")
  29. click(250, 420)
  30. click(250, 444)
  31. click(650, 610)
  32. snooze()
  33. print("Third screen")
  34. click(600, 560)
  35. click(650, 610)
  36. snooze()
  37. print("Fourth screen")
  38. click(300, 100)
  39. click(650, 610)
  40. for ith in ("Fifth", "Sixth", "Seventh"):
  41. snooze()
  42. print(ith + " screen")
  43. click()
  44. print("Waiting half an hour for XiLinx installer to run, ^C if you get bored")
  45. snooze(1800)
  46. # In theory we could use visgrep to check for the "finish" button.
  47. # In practice ... this is such a kludge, what's one more, let's just
  48. # try blindly clicking where the finish button should be and see
  49. # if that results in a usable image.
  50. print("Blindly clicking where finish button should be")
  51. click(720, 610)
  52. print("xsetup exited with status {}".format(xsetup.wait()))
  53. snooze()
  54. print("Starting XiLinx license manager")
  55. xlcm = subprocess.Popen(". /opt/Xilinx/14.7/ISE_DS/settings64.sh; /opt/Xilinx/14.7/ISE_DS/common/bin/lin64/xlcm -manage",
  56. shell = True, cwd = "/home/builder", env = dict(os.environ, USER = "builder", HOME = "/home/builder"))
  57. snooze()
  58. print("First screen")
  59. click(100, 116)
  60. snooze()
  61. print("Second screen")
  62. click(220, 170)
  63. click(680, 490)
  64. snooze()
  65. print("Third screen")
  66. click(400, 360)
  67. click(750, 650)
  68. print("xlcm exited with status {}".format(xlcm.wait()))
  69. print("Shutting down")
  70. subprocess.check_call(("ratpoison", "-c", "quit"))
  71. print("ratpoison exited with status {}".format(rat.wait()))