Left: | ||
Right: |
OLD | NEW |
---|---|
1 #!/usr/bin/env python | |
Sebastian Noack
2016/08/28 22:36:13
In all environments (except for a Python 3 virtual
Vasily Kuznetsov
2016/08/29 15:29:52
I'm not sure if it's always better to run Python3-
| |
2 # coding: utf-8 | |
3 | |
4 # This Source Code is subject to the terms of the Mozilla Public License | 1 # This Source Code is subject to the terms of the Mozilla Public License |
5 # version 2.0 (the "License"). You can obtain a copy of the License at | 2 # version 2.0 (the "License"). You can obtain a copy of the License at |
6 # http://mozilla.org/MPL/2.0/. | 3 # http://mozilla.org/MPL/2.0/. |
7 | 4 |
8 import sys | 5 from __future__ import print_function |
Sebastian Noack
2016/08/30 11:44:38
I just noticed that this future import here isn't
Vasily Kuznetsov
2016/08/30 13:16:30
Acknowledged.
| |
6 | |
9 import os | 7 import os |
10 import subprocess | 8 import subprocess |
9 | |
11 import utils | 10 import utils |
12 | 11 |
13 | 12 |
14 def doRewrite(files, args): | 13 def rewrite_js(args, script=None): |
Sebastian Noack
2016/08/28 22:36:13
Yes, this is a breaking change that needs to be ad
Vasily Kuznetsov
2016/08/30 13:16:30
Acknowledged.
| |
15 application = utils.ensureJSShell() | 14 jsshell = utils.ensureJSShell() |
15 env = {'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(jsshell))} | |
16 base_dir = os.path.dirname(__file__) | |
16 | 17 |
17 env = { | 18 if not script: |
18 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)), | 19 script = os.path.join(base_dir, 'scripts', 'abprewrite.js') |
19 } | |
20 | 20 |
21 baseDir = os.path.dirname(utils.__file__) | 21 command = [jsshell, os.path.join(base_dir, 'jshydra.js'), script] + args |
22 command = [ | 22 return subprocess.check_output(command, env=env, universal_newlines=True) |
23 application, os.path.join(baseDir, 'jshydra.js'), | |
24 os.path.join(baseDir, 'scripts', 'abprewrite.js'), | |
25 '--arg', ' '.join(args) | |
26 ] + files | |
27 return subprocess.check_output(command, env=env).replace('\r', '') | |
Sebastian Noack
2016/08/28 22:36:14
For reference, this failed in Python 3, because we
| |
28 | |
29 if __name__ == '__main__': | |
30 try: | |
31 scriptArgsStart = sys.argv.index('--arg') | |
32 except ValueError: | |
33 scriptArgsStart = len(sys.argv) | |
34 print doRewrite(sys.argv[1:scriptArgsStart], sys.argv[scriptArgsStart + 1:]) | |
OLD | NEW |