Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | # Usage: check_source_count.py SEARCH_TERM COUNT ERROR_LOCATION REPLACEMENT [FILES...] |
michael@0 | 8 | # Checks that FILES contains exactly COUNT matches of SEARCH_TERM. If it does |
michael@0 | 9 | # not, an error message is printed, quoting ERROR_LOCATION, which should |
michael@0 | 10 | # probably be the filename and line number of the erroneous call to |
michael@0 | 11 | # check_source_count.py. |
michael@0 | 12 | from __future__ import print_function |
michael@0 | 13 | import sys |
michael@0 | 14 | import os |
michael@0 | 15 | import re |
michael@0 | 16 | |
michael@0 | 17 | search_string = sys.argv[1] |
michael@0 | 18 | expected_count = int(sys.argv[2]) |
michael@0 | 19 | error_location = sys.argv[3] |
michael@0 | 20 | replacement = sys.argv[4] |
michael@0 | 21 | files = sys.argv[5:] |
michael@0 | 22 | |
michael@0 | 23 | details = {} |
michael@0 | 24 | |
michael@0 | 25 | count = 0 |
michael@0 | 26 | for f in files: |
michael@0 | 27 | text = file(f).read() |
michael@0 | 28 | match = re.findall(search_string, text) |
michael@0 | 29 | if match: |
michael@0 | 30 | num = len(match) |
michael@0 | 31 | count += num |
michael@0 | 32 | details[f] = num |
michael@0 | 33 | |
michael@0 | 34 | if count == expected_count: |
michael@0 | 35 | print("TEST-PASS | check_source_count.py {0} | {1}" |
michael@0 | 36 | .format(search_string, expected_count)) |
michael@0 | 37 | |
michael@0 | 38 | else: |
michael@0 | 39 | print("TEST-UNEXPECTED-FAIL | check_source_count.py {0} | " |
michael@0 | 40 | .format(search_string), |
michael@0 | 41 | end='') |
michael@0 | 42 | if count < expected_count: |
michael@0 | 43 | print("There are fewer occurrences of /{0}/ than expected. " |
michael@0 | 44 | "This may mean that you have removed some, but forgotten to " |
michael@0 | 45 | "account for it {1}.".format(search_string, error_location)) |
michael@0 | 46 | else: |
michael@0 | 47 | print("There are more occurrences of /{0}/ than expected. We're trying " |
michael@0 | 48 | "to prevent an increase in the number of {1}'s, using {2} if " |
michael@0 | 49 | "possible. If it is unavoidable, you should update the expected " |
michael@0 | 50 | "count {3}.".format(search_string, search_string, replacement, |
michael@0 | 51 | error_location)) |
michael@0 | 52 | |
michael@0 | 53 | print("Expected: {0}; found: {1}".format(expected_count, count)) |
michael@0 | 54 | for k in sorted(details): |
michael@0 | 55 | print("Found {0} occurences in {1}".format(details[k],k)) |
michael@0 | 56 | sys.exit(-1) |
michael@0 | 57 |