Skip to content

Instantly share code, notes, and snippets.

@evilpie
Created June 7, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilpie/50f63f485799c3ac9db3e93142562bca to your computer and use it in GitHub Desktop.
Save evilpie/50f63f485799c3ac9db3e93142562bca to your computer and use it in GitHub Desktop.
import re
import os
paths = [
"testing/web-platform/tests/eventsource/shared-worker/eventsource-constructor-url-bogus.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-onmesage.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-eventtarget.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-onopen.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-close.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-url.htm",
"testing/web-platform/tests/eventsource/shared-worker/eventsource-prototype.htm",
"testing/web-platform/tests/eventsource/dedicated-worker/eventsource-constructor-url-bogus.htm",
"testing/web-platform/tests/eventsource/dedicated-worker/eventsource-onopen.htm",
# .... rg -F "Worker('"
]
for path in paths:
print path
path = "/home/tom/projects/central/" + path
f = open(path)
data = f.read()
before, after = re.split("\<\!doctype html\>", data, 0, re.I)
javascript = before.strip().strip("<>!-\n/*")
html = "<!doctype html>" + after.split("<!--")[0].rstrip()
new = re.sub("\.html?", ".js", path)
html = html.replace("Worker('#')", "Worker('" + os.path.basename(new) + "')")
open(path, "w").write(html)
print new
assert not os.path.exists(new)
open(new, "w").write(javascript)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment