patch_selenium.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os.path
  2. import re
  3. import subprocess
  4. PATCH_FILE_PATTERN = (
  5. (
  6. "scripts/patches/chrome_options.diff",
  7. ".venv/lib/python3.8/site-packages/selenium/webdriver/chrome/options.py",
  8. re.compile(r"path to the \\\*\.crx file"),
  9. ),
  10. (
  11. "scripts/patches/firefox_profile.diff",
  12. ".venv/lib/python3.8/site-packages/selenium/webdriver/firefox/firefox_profile.py",
  13. re.compile(r"setting is ''"),
  14. ),
  15. (
  16. "scripts/patches/remote_webdriver.diff",
  17. ".venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py",
  18. re.compile(r' """Finds an element by id'),
  19. ),
  20. (
  21. "scripts/patches/remote_webelement.diff",
  22. ".venv/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py",
  23. re.compile(r' """Finds element within this element\'s children by ID'),
  24. ),
  25. (
  26. "scripts/patches/support_wait.diff",
  27. ".venv/lib/python3.8/site-packages/selenium/webdriver/support/wait.py",
  28. re.compile(r"\.\\ \\n"),
  29. ),
  30. )
  31. def main() -> int:
  32. for patch, filename, pattern in PATCH_FILE_PATTERN:
  33. if not os.path.exists(filename):
  34. print(f"patch_selenium: ignoring {filename} (does not exist)")
  35. continue
  36. with open(filename) as f:
  37. for line in f:
  38. if pattern.search(line):
  39. break
  40. else: # did not find the pattern
  41. continue
  42. print(f"patching {filename}, you will only see this once")
  43. sentry_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
  44. patch = os.path.join(sentry_root, patch)
  45. if subprocess.call(("patch", "-f", "-p0", "-i", patch)):
  46. return 1
  47. return 0
  48. if __name__ == "__main__":
  49. raise SystemExit(main())