Browse Source

Consolidate voodoo

Rob Austein 6 years ago
parent
commit
6cf7d84730
2 changed files with 129 additions and 1 deletions
  1. 1 1
      .gitignore
  2. 128 0
      ratinox

+ 1 - 1
.gitignore

@@ -1,5 +1,5 @@
 framebuf/Xvfb_screen0
-screenlog.*
+*.log
 *.stamp
 Xilinx_ISE_DS_Lin_14.7_1015_1.tar
 Xilinx.lic

+ 128 - 0
ratinox

@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+
+"""
+Perform demented tasks with blind rodents.
+"""
+
+import subprocess, os, time, xvfbwrapper, shutil, argparse
+
+class Ratinox(xvfbwrapper.Xvfb):
+
+    xvfb_screen_name = "Xvfb_screen0"
+
+    def __init__(self, **kwargs):
+        if kwargs.pop("screencap", True) and "fbdir" in kwargs:
+            self.screencap_file = os.path.join(kwargs["fbdir"], xvfb_screen_name)
+        else:
+            self.screencap_file = None
+        super(Ratinox, self).__init__(**kwargs)
+
+    def __enter__(self):
+        result = super(Ratinox, self).__enter__()
+        self.wm = subprocess.Popen(("ratpoison",))
+        time.sleep(0.5)
+        return result
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        self.rat("quit")
+        self.wm.wait()
+        self.wm = None
+        super(Ratinox, self).__exit__(exc_type, exc_val, exc_tb)
+
+    def click(self, *coordinates):
+        assert len(coordinates) in (0, 2)
+        if coordinates:
+            subproccess.check_call(("ratpoison", "-c", "ratwarp {:d} {:d}".format(*coordinates)))
+        if self.screencap_file:
+            shutil.copy(self.screencap_file, "{}.{}".format(self.screencap_file, time.time()))
+        subproccess.check_call(("ratpoison", "-c", "ratclick"))
+
+def snooze(how_long = 15):
+    time.sleep(how_long)
+
+def installer():
+
+    with Ratinox(fbdir = "/framebuf") as rat:
+        print("DISPLAY={}".format(os.getenv("DISPLAY")))
+
+        snooze()
+        print("Starting XiLinx installer")
+        xsetup = subprocess.Popen(("./xsetup",), cwd = "/xilinx-unpack/Xilinx_ISE_DS_Lin_14.7_1015_1")
+
+        snooze()
+        print("First screen")
+        rat.click(650, 610)
+
+        snooze()
+        print("Second screen")
+        rat.click(250, 420)
+        rat.click(250, 444)
+        rat.click(650, 610)
+
+        snooze()
+        print("Third screen")
+        rat.click(600, 560)
+        rat.click(650, 610)
+
+        snooze()
+        print("Fourth screen")
+        rat.click(300, 100)
+        rat.click(650, 610)
+
+        for ith in ("Fifth", "Sixth", "Seventh"):
+            snooze()
+            print(ith + " screen")
+            rat.click()
+
+        print("Waiting half an hour for XiLinx installer to run, ^C if you get bored")
+        snooze(1800)
+
+        # In theory we could use visgrep to check for the "finish" button.
+        # In practice ... this is such a kludge, what's one more, let's just
+        # try blindly clicking where the finish button should be and see
+        # if that results in a usable image.
+
+        print("Blindly clicking where finish button should be")
+        rat.click(720, 610)
+
+        print("xsetup exited with status {}".format(xsetup.wait()))
+
+def licenser():
+
+    with Ratinox(fbdir = "/framebuf") as rat:
+        print("DISPLAY={}".format(os.getenv("DISPLAY")))
+
+        snooze()
+        print("Starting XiLinx license manager")
+        xlcm = ". /opt/Xilinx/14.7/ISE_DS/settings64.sh; /opt/Xilinx/14.7/ISE_DS/common/bin/lin64/xlcm -manage"
+        xlcm = subprocess.Popen(xlcm, shell = True)
+
+        snooze()
+        print("First screen")
+        rat.click(100, 116)
+
+        snooze()
+        print("Second screen")
+        rat.click(220, 170)
+        rat.click(680, 490)
+
+        snooze()
+        print("Third screen")
+        rat.click(400, 360)
+        rat.click(750, 650)
+
+        print("xlcm exited with status {}".format(xlcm.wait()))
+
+def main():
+
+    dispatch = {"ise-install"  : installer,
+                "license-user" : licenser }
+
+    ap = argparse.ArgumentParser(description = __doc__)
+    ap.add_argument("command", choices = tuple(sorted(dispatch)))
+    args = ap.parse_args()
+
+    dispatch[args.command]
+
+if __name__ == "__main__":
+    main()