Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: abp_rewrite.py

Issue 29350236: Issue 4373 - Made jshydra compatible with Python 3 (Closed)
Patch Set: Created Aug. 28, 2016, 10:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgignore ('k') | autotest.py » ('j') | tox.ini » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp_rewrite.py
===================================================================
old mode 100755
new mode 100644
--- a/abp_rewrite.py
+++ b/abp_rewrite.py
@@ -1,34 +1,22 @@
-#!/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-
-# coding: utf-8
-
# This Source Code is subject to the terms of the Mozilla Public License
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
-import sys
+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.
+
import os
import subprocess
+
import utils
-def doRewrite(files, args):
- application = utils.ensureJSShell()
+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.
+ jsshell = utils.ensureJSShell()
+ env = {'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(jsshell))}
+ base_dir = os.path.dirname(__file__)
- env = {
- 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)),
- }
+ if not script:
+ script = os.path.join(base_dir, 'scripts', 'abprewrite.js')
- baseDir = os.path.dirname(utils.__file__)
- command = [
- application, os.path.join(baseDir, 'jshydra.js'),
- os.path.join(baseDir, 'scripts', 'abprewrite.js'),
- '--arg', ' '.join(args)
- ] + files
- 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
-
-if __name__ == '__main__':
- try:
- scriptArgsStart = sys.argv.index('--arg')
- except ValueError:
- scriptArgsStart = len(sys.argv)
- print doRewrite(sys.argv[1:scriptArgsStart], sys.argv[scriptArgsStart + 1:])
+ command = [jsshell, os.path.join(base_dir, 'jshydra.js'), script] + args
+ return subprocess.check_output(command, env=env, universal_newlines=True)
« no previous file with comments | « .hgignore ('k') | autotest.py » ('j') | tox.ini » ('J')

Powered by Google App Engine
This is Rietveld