[Pkg-mozext-commits] [adblock-plus] 339/464: Generalized rewriting script, files to rewrite are specified as parameters now
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:31 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit b56ce700e533c365f8a8ccc665e8ca4ba89e799d
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon Dec 17 14:05:35 2012 +0100
Generalized rewriting script, files to rewrite are specified as parameters now
---
abp_rewrite.py | 57 +++++++++++++++++----------------------------------------
autotest.py | 21 +++++++++------------
utils.py | 5 +++--
3 files changed, 29 insertions(+), 54 deletions(-)
diff --git a/abp_rewrite.py b/abp_rewrite.py
index 0e829ff..9d2150a 100644
--- a/abp_rewrite.py
+++ b/abp_rewrite.py
@@ -5,50 +5,27 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
-import sys, os, subprocess
-from utils import ensureJSShell
+import sys, os, subprocess, utils
-def doRewrite():
- if len(sys.argv) < 4:
- print '''Usage:
+def doRewrite(files, args):
+ application = utils.ensureJSShell()
-%s <abp_firefox_dir> <abptests_dir> <abp_chrome_dir>
-''' % sys.argv[0]
- sys.exit(2)
-
- sourceDir = sys.argv[1]
- testsDir = sys.argv[2]
- targetDir = sys.argv[3]
-
- basedir = os.path.dirname(sys.argv[0])
- if not basedir:
- basedir = '.'
-
- application = ensureJSShell(basedir)
env = {
- 'LD_LIBRARY_PATH': os.path.dirname(application),
+ 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)),
}
- command = [application, '-U', os.path.join(basedir, 'jshydra.js'), os.path.join(basedir, 'scripts', 'abprewrite.js'), '--arg', 'module=true source_repo=https://hg.adblockplus.org/adblockplus/']
- for module in ('filterNotifier', 'filterClasses', 'subscriptionClasses', 'filterStorage', 'elemHide', 'matcher', 'filterListener', 'synchronizer'):
- sourceFile = os.path.join(sourceDir, 'lib', module + '.js')
- if not os.path.exists(sourceFile):
- print 'Source file %s could not be found' % sourceFile
- sys.exit(2)
- command.append(sourceFile)
-
- out = open(os.path.join(targetDir, 'lib', 'adblockplus.js'), 'wb')
- subprocess.Popen(command, stdout=out, env=env).communicate()
-
- command = [application, '-U', os.path.join(basedir, 'jshydra.js'), os.path.join(basedir, 'scripts', 'abprewrite.js'), '--arg', 'source_repo=https://hg.adblockplus.org/adblockplustests/']
- for test in ('domainRestrictions', 'filterClasses', 'filterNotifier', 'filterStorage', 'matcher', 'regexpFilters_matching', 'subscriptionClasses'):
- sourceFile = os.path.join(testsDir, 'chrome', 'content', 'tests', test + '.js')
- if not os.path.exists(sourceFile):
- print 'Source file %s could not be found' % sourceFile
- sys.exit(2)
- command.append(sourceFile)
- out = open(os.path.join(targetDir, 'qunit', 'tests', 'adblockplus.js'), 'wb')
- subprocess.Popen(command, stdout=out, env=env).communicate()
+ baseDir = os.path.dirname(utils.__file__)
+ command = [
+ application, '-U', os.path.join(baseDir, 'jshydra.js'),
+ os.path.join(baseDir, 'scripts', 'abprewrite.js'),
+ '--arg', ' '.join(args)
+ ] + files
+ result, dummy = subprocess.Popen(command, stdout=subprocess.PIPE, env=env).communicate()
+ return result
if __name__ == '__main__':
- doRewrite()
+ try:
+ scriptArgsStart = sys.argv.index('--arg')
+ except ValueError:
+ scriptArgsStart = len(sys.argv)
+ print doRewrite(sys.argv[1:scriptArgsStart], sys.argv[scriptArgsStart + 1:])
diff --git a/autotest.py b/autotest.py
index 5946745..80d2cbf 100644
--- a/autotest.py
+++ b/autotest.py
@@ -5,24 +5,21 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
-import sys, os, subprocess, re, difflib
-from utils import ensureJSShell
+import sys, os, subprocess, re, difflib, utils
def run_tests():
- basedir = os.path.dirname(sys.argv[0])
- if not basedir:
- basedir = '.'
-
- application = ensureJSShell(basedir)
+ application = utils.ensureJSShell()
env = {
- 'LD_LIBRARY_PATH': os.path.dirname(application),
+ 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)),
}
- testdir = os.path.join(basedir, 'autotest')
- for file in os.listdir(testdir):
+
+ baseDir = os.path.dirname(utils.__file__)
+ testDir = os.path.join(baseDir, 'autotest')
+ for file in os.listdir(testDir):
if not re.search(r'^test_.*\.js$', file):
continue
- file = os.path.join(testdir, file)
+ file = os.path.join(testDir, file)
handle = open(file, 'r')
name = None
arguments = None
@@ -37,7 +34,7 @@ def run_tests():
if arguments == None:
continue
- command = [application, '-U', os.path.join(basedir, 'jshydra.js'), file] + arguments
+ command = [application, '-U', os.path.join(baseDir, 'jshydra.js'), file] + arguments
out = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env).communicate()[0].replace('\r', '')
expected = open(file + '.expected', 'r').read().replace('\r', '')
if out == expected:
diff --git a/utils.py b/utils.py
index fe28d79..a6a9353 100644
--- a/utils.py
+++ b/utils.py
@@ -7,8 +7,9 @@
import sys, os, urllib, zipfile
from StringIO import StringIO
-def ensureJSShell(basedir):
- shell_dir = os.path.join(basedir, 'mozilla')
+def ensureJSShell():
+ baseDir = os.path.dirname(__file__)
+ shell_dir = os.path.join(baseDir, 'mozilla')
if not os.path.exists(shell_dir):
os.makedirs(shell_dir)
if sys.platform == 'win32':
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list