-
Notifications
You must be signed in to change notification settings - Fork 2
/
linePrepender.py
38 lines (27 loc) · 1.05 KB
/
linePrepender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
"""
Any version of Python
For people using repacks built on Java 7 or earlier,
their scripts are likely interpreted using Rhino.
Java 8+ brings us a new Javascript engine, Nashorn.
This script is one of two scripts
(the other being packageFixer.py)
that can be run on the old scripts in order to make
them function with Nashorn.
Must be run from the root directory of the server with
access to /scripts/.
NOTE: This is a bandaid fix, old scripts should be
further assimilated into Nashorn's style once they are
minimally working, e.g. use ``Java.type()`` for imports.
"""
import os
def lineprepender(filename, line):
with open(filename, "r+") as f:
content = f.read()
f.seek(0, 0)
f.write(line.rstrip("\r\n") + '\n' + content)
for dirpath, dirnames, filenames in os.walk("./scripts"):
for file in filenames:
if file[len(file) - 3:] == ".js":
lineprepender(os.path.join(dirpath, file),
"load('nashorn:mozilla_compat.js');")