ratinox 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env python
  2. """
  3. Perform demented tasks with blind rodents.
  4. """
  5. import subprocess, os, time, xvfbwrapper, shutil, argparse
  6. class Ratinox(xvfbwrapper.Xvfb):
  7. xvfb_screen_name = "Xvfb_screen0"
  8. def __init__(self, **kwargs):
  9. if kwargs.pop("screencap", True) and "fbdir" in kwargs:
  10. self.screencap_file = os.path.join(kwargs["fbdir"], xvfb_screen_name)
  11. else:
  12. self.screencap_file = None
  13. super(Ratinox, self).__init__(**kwargs)
  14. def __enter__(self):
  15. result = super(Ratinox, self).__enter__()
  16. self.wm = subprocess.Popen(("ratpoison",))
  17. time.sleep(0.5)
  18. return result
  19. def __exit__(self, exc_type, exc_val, exc_tb):
  20. self.rat("quit")
  21. self.wm.wait()
  22. self.wm = None
  23. super(Ratinox, self).__exit__(exc_type, exc_val, exc_tb)
  24. def click(self, *coordinates):
  25. assert len(coordinates) in (0, 2)
  26. if coordinates:
  27. subproccess.check_call(("ratpoison", "-c", "ratwarp {:d} {:d}".format(*coordinates)))
  28. if self.screencap_file:
  29. shutil.copy(self.screencap_file, "{}.{}".format(self.screencap_file, time.time()))
  30. subproccess.check_call(("ratpoison", "-c", "ratclick"))
  31. def snooze(how_long = 15):
  32. time.sleep(how_long)
  33. def installer():
  34. with Ratinox(fbdir = "/framebuf") as rat:
  35. print("DISPLAY={}".format(os.getenv("DISPLAY")))
  36. snooze()
  37. print("Starting XiLinx installer")
  38. xsetup = subprocess.Popen(("./xsetup",), cwd = "/xilinx-unpack/Xilinx_ISE_DS_Lin_14.7_1015_1")
  39. snooze()
  40. print("First screen")
  41. rat.click(650, 610)
  42. snooze()
  43. print("Second screen")
  44. rat.click(250, 420)
  45. rat.click(250, 444)
  46. rat.click(650, 610)
  47. snooze()
  48. print("Third screen")
  49. rat.click(600, 560)
  50. rat.click(650, 610)
  51. snooze()
  52. print("Fourth screen")
  53. rat.click(300, 100)
  54. rat.click(650, 610)
  55. for ith in ("Fifth", "Sixth", "Seventh"):
  56. snooze()
  57. print(ith + " screen")
  58. rat.click()
  59. print("Waiting half an hour for XiLinx installer to run, ^C if you get bored")
  60. snooze(1800)
  61. # In theory we could use visgrep to check for the "finish" button.
  62. # In practice ... this is such a kludge, what's one more, let's just
  63. # try blindly clicking where the finish button should be and see
  64. # if that results in a usable image.
  65. print("Blindly clicking where finish button should be")
  66. rat.click(720, 610)
  67. print("xsetup exited with status {}".format(xsetup.wait()))
  68. def licenser():
  69. with Ratinox(fbdir = "/framebuf") as rat:
  70. print("DISPLAY={}".format(os.getenv("DISPLAY")))
  71. snooze()
  72. print("Starting XiLinx license manager")
  73. xlcm = ". /opt/Xilinx/14.7/ISE_DS/settings64.sh; /opt/Xilinx/14.7/ISE_DS/common/bin/lin64/xlcm -manage"
  74. xlcm = subprocess.Popen(xlcm, shell = True)
  75. snooze()
  76. print("First screen")
  77. rat.click(100, 116)
  78. snooze()
  79. print("Second screen")
  80. rat.click(220, 170)
  81. rat.click(680, 490)
  82. snooze()
  83. print("Third screen")
  84. rat.click(400, 360)
  85. rat.click(750, 650)
  86. print("xlcm exited with status {}".format(xlcm.wait()))
  87. def main():
  88. dispatch = {"ise-install" : installer,
  89. "license-user" : licenser }
  90. ap = argparse.ArgumentParser(description = __doc__)
  91. ap.add_argument("command", choices = tuple(sorted(dispatch)))
  92. args = ap.parse_args()
  93. dispatch[args.command]
  94. if __name__ == "__main__":
  95. main()