addon-sdk/source/python-lib/cuddlefish/tests/test_licenses.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
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 import unittest
michael@0 7 import os.path
michael@0 8
michael@0 9 parent = os.path.dirname
michael@0 10 test_dir = parent(os.path.abspath(__file__))
michael@0 11 sdk_root = parent(parent(parent(test_dir)))
michael@0 12
michael@0 13 def from_sdk_top(fn):
michael@0 14 return os.path.abspath(os.path.join(sdk_root, fn))
michael@0 15
michael@0 16 MPL2_URL = "http://mozilla.org/MPL/2.0/"
michael@0 17
michael@0 18 # These files all come with their own license headers
michael@0 19 skip = [
michael@0 20 "python-lib/cuddlefish/_version.py", # generated, public domain
michael@0 21 "doc/static-files/js/jquery.js", # MIT/GPL dual
michael@0 22 "examples/annotator/data/jquery-1.4.2.min.js", # MIT/GPL dual
michael@0 23 "examples/reddit-panel/data/jquery-1.4.4.min.js", # MIT/GPL dual
michael@0 24 "examples/library-detector/data/library-detector.js", # MIT
michael@0 25 "python-lib/mozrunner/killableprocess.py", # MIT? BSDish?
michael@0 26 "python-lib/mozrunner/winprocess.py", # MIT
michael@0 27 "packages/api-utils/tests/test-querystring.js", # MIT
michael@0 28 "packages/api-utils/lib/promise.js", # MIT
michael@0 29 "packages/api-utils/tests/test-promise.js", # MIT
michael@0 30 ]
michael@0 31 absskip = [from_sdk_top(os.path.join(*fn.split("/"))) for fn in skip]
michael@0 32
michael@0 33 class Licenses(unittest.TestCase):
michael@0 34 def test(self):
michael@0 35 # Examine most SDK files to check if they've got an MPL2 license
michael@0 36 # header. We exclude some files that are known to include different
michael@0 37 # licenses.
michael@0 38 self.missing = []
michael@0 39 self.scan_file(from_sdk_top(os.path.join("python-lib", "jetpack_sdk_env.py")))
michael@0 40 self.scan(os.path.join("python-lib", "cuddlefish"), [".js", ".py"],
michael@0 41 skipdirs=["sdk-docs"], # test_generate.py makes this
michael@0 42 )
michael@0 43 self.scan(os.path.join("python-lib", "mozrunner"), [".py"])
michael@0 44
michael@0 45 for sdk_package in ["addon-kit", "api-utils", "test-harness"]:
michael@0 46 self.scan(os.path.join("packages", sdk_package),
michael@0 47 [".js", ".py", ".md"])
michael@0 48 self.scan("examples", [".js", ".css", ".html", ".md"])
michael@0 49 self.scan("bin", [".bat", ".ps1"])
michael@0 50 for fn in [os.path.join("bin", "activate"),
michael@0 51 os.path.join("bin", "cfx"),
michael@0 52 os.path.join("bin", "integration-scripts", "buildbot-run-cfx-helper"),
michael@0 53 os.path.join("bin", "integration-scripts", "integration-check"),
michael@0 54 ]:
michael@0 55 self.scan_file(from_sdk_top(fn))
michael@0 56 self.scan("doc", [".js", ".css", ".md"], skipdirs=["syntaxhighlighter"])
michael@0 57
michael@0 58 if self.missing:
michael@0 59 print
michael@0 60 print "The following files are missing an MPL2 header:"
michael@0 61 for fn in sorted(self.missing):
michael@0 62 print " "+fn
michael@0 63 self.fail("%d files are missing an MPL2 header" % len(self.missing))
michael@0 64
michael@0 65 def scan(self, start, extensions=[], skipdirs=[]):
michael@0 66 # scan a whole subdirectory
michael@0 67 start = from_sdk_top(start)
michael@0 68 for root, dirs, files in os.walk(start):
michael@0 69 for d in skipdirs:
michael@0 70 if d in dirs:
michael@0 71 dirs.remove(d)
michael@0 72 for fn in files:
michael@0 73 ext = os.path.splitext(fn)[1]
michael@0 74 if extensions and ext not in extensions:
michael@0 75 continue
michael@0 76 absfn = os.path.join(root, fn)
michael@0 77 if absfn in absskip:
michael@0 78 continue
michael@0 79 self.scan_file(absfn)
michael@0 80
michael@0 81 def scan_file(self, fn):
michael@0 82 # scan a single file
michael@0 83 if not MPL2_URL in open(fn, "r").read():
michael@0 84 relfile = fn[len(sdk_root)+1:]
michael@0 85 self.missing.append(relfile)
michael@0 86
michael@0 87 if __name__ == '__main__':
michael@0 88 unittest.main()

mercurial