PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/tools/relic/relic

https://bitbucket.org/lahabana/mozilla-central
Python | 2457 lines | 2324 code | 38 blank | 95 comment | 84 complexity | 5b9034b45760e048515e2881c9d79d2e MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, JSON, 0BSD, MIT, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. #!/usr/bin/python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. # Adapted from the 'lick' and 'ripl' Python scripts. (See:
  6. # <http://bugzilla.mozilla.org/show_bug.cgi?id=98089>)
  7. """
  8. relic - RE-LICense a given file, set of files, or directory of files
  9. from the Mozilla source tree
  10. Usage:
  11. relic [options...] [files...]
  12. relic [options...] < files...
  13. Options to Select Mode (use one):
  14. <none> List the licenses in each file.
  15. -s, --statistics Should a summary table of licenses in each file.
  16. The -x, --extended option may be added to show
  17. some additional detail to the stats.
  18. -r, --relicense Modify the given files to include to
  19. appropriate Mozilla license, where
  20. "appropriate" is either the NPL/GPL/LPGL
  21. tri-license if was already under the NPL or
  22. the MPL/LPGL/GPL license in all other cases.
  23. -R, --force-relicense
  24. Relicenses files (as -r|--relicense), but
  25. does NOT skip files that already appear to
  26. have a complete license.
  27. -A, --add Add a license to files that do not appear to
  28. have one.
  29. -I, --initial-developers
  30. Display initial developer for each file.
  31. General Options:
  32. -h, --help dump this help and exit
  33. -V, --version dump this script's version and exit
  34. -v, --verbose verbose output
  35. -d, --debug more verbose output
  36. -f, --force Continue processing after an error. (Errors
  37. are summarized at end.)
  38. -q, --quick Quick scanning. Use only basic license checks
  39. (only use in report mode).
  40. -M, --MPL Replace NPL licenses with MPL ones.
  41. -a, --all Check all files (only skip CVS directories).
  42. --dry-run Go through motions but don't actually change
  43. any files.
  44. --backup Make backups of changes files with
  45. relicensing. Backup filenames are the
  46. original filename suffixed with a ~# where
  47. "#" is the lowest number to avoid a file
  48. conflict.
  49. -o <orig_code_is> Provide fallback value for the "Original
  50. Code is" block.
  51. -D <orig_code_date> Provide fallback value for the date
  52. that is part of the "Original Code is" block.
  53. -i <initial_dev> Provide fallback value for the "Initial
  54. Developer of the Original Code is" block.
  55. -y <year> Provide fallback value for "Initial
  56. Developer" copyright year.
  57. --defaults Use the following default fallback values:
  58. original_code_is: "mozilla.org Code"
  59. initial_copyright_date: "2001"
  60. initial_developer: "Netscape Communications
  61. Corporation"
  62. Note: the "Original Code" date is generally
  63. not required, so a default is not included
  64. here.
  65. Examples:
  66. # List license in files under mozilla/js/src.
  67. relic mozilla/js/src # list licenses in files
  68. relic -s mozilla/js/src # show summary stats on licenses
  69. relic -r mozilla/js/src # re-license files
  70. """
  71. import os
  72. import sys
  73. import re
  74. import getopt
  75. import pprint
  76. import shutil
  77. class RelicError(Exception):
  78. pass
  79. #---- setup logging
  80. try:
  81. # This package will be std in Python 2.3, but many Python 2.2
  82. # installation will not have it.
  83. import logging
  84. logging.basicConfig()
  85. except ImportError:
  86. # Local fallback logging module.
  87. try:
  88. import _logging as logging
  89. except ImportError:
  90. sys.stderr.write("Your Python installation does not have the logging "
  91. "package, nor could the fallback _logging module be "
  92. "found. One of the two is required to run this "
  93. "script.\n\n")
  94. raise
  95. log = logging.getLogger("relic")
  96. #---- globals
  97. _version_ = (0, 7, 2)
  98. # When processing files, 'relic' skips files and directories according
  99. # to these settings. Note: files identified in .cvsignore files are also
  100. # skipped.
  101. _g_skip_exts = [".mdp", ".order", ".dsp", ".dsw", ".uf"]
  102. _g_skip_file_basenames = [
  103. # Used by CVS (and this script)
  104. ".cvsignore",
  105. # GPL with autoconf exception
  106. "config.guess",
  107. "config.sub",
  108. # Auto-generated from other files
  109. "configure",
  110. # license and readme files
  111. "license",
  112. "readme",
  113. "copyright",
  114. "LICENSE-MPL",
  115. "MPL-1.1.txt",
  116. ]
  117. _g_skip_files = [
  118. # TODO: update with MPL block - or CVS remove (check history)
  119. "tools/wizards/templates/licenses/MPL/lic.mak",
  120. "tools/wizards/templates/licenses/MPL/lic.pl",
  121. ###########################################################################
  122. # Everything in _g_skip_files below this line needs no further work.
  123. ###########################################################################
  124. # Files containing copies of licence text which confuses the script
  125. "LICENSE",
  126. "js2/COPYING",
  127. "security/svrcore/LICENSE",
  128. "extensions/xmlterm/doc/MPL",
  129. "gfx/cairo/cairo/COPYING-LGPL-2.1",
  130. "gfx/cairo/cairo/COPYING-MPL-1.1",
  131. # Files containing global licensing information
  132. "xpfe/global/resources/content/license.html",
  133. "toolkit/content/license.html",
  134. # Ben Bucksch - files are tri-licensed with an extra clause.
  135. "netwerk/streamconv/converters/mozTXTToHTMLConv.cpp",
  136. "netwerk/streamconv/converters/mozTXTToHTMLConv.h",
  137. "netwerk/streamconv/public/mozITXTToHTMLConv.idl",
  138. # GPLed build tools
  139. "config/preprocessor.pl",
  140. "intl/uconv/tools/parse-mozilla-encoding-table.pl",
  141. "intl/uconv/tools/gen-big5hkscs-2001-mozilla.pl",
  142. "js2/missing",
  143. # Files which the script doesn't handle well. All have been relicensed
  144. # manually.
  145. "xpinstall/wizard/windows/builder/readme.txt",
  146. "xpfe/bootstrap/icons/windows/readme.txt",
  147. "embedding/qa/testembed/README.TXT",
  148. "security/nss/lib/freebl/ecl/README.FP",
  149. "nsprpub/pkg/linux/sun-nspr.spec",
  150. "security/nss/pkg/linux/sun-nss.spec",
  151. "security/jss/pkg/linux/sun-jss.spec",
  152. "security/nss/lib/freebl/mpi/utils/README",
  153. "security/nss/lib/freebl/ecl/README",
  154. "security/nss/lib/freebl/mpi/README",
  155. "lib/mac/UserInterface/Tables/TableClasses.doc",
  156. "parser/htmlparser/tests/html/bug23680.html",
  157. "security/nss/lib/freebl/mpi/montmulfv9.s",
  158. "tools/performance/pageload/base/lxr.mozilla.org/index.html",
  159. "testing/performance/win32/page_load_test/" +\
  160. "base/lxr.mozilla.org/index.html",
  161. "testing/performance/win32/page_load_test/" +\
  162. "base/lxr.mozilla.org/20001028.html.orig",
  163. # Not sure what to do with this...
  164. "gfx/cairo/stdint.diff",
  165. # GPL with autoconf exception (same license as files distributed with)
  166. "build/autoconf/codeset.m4",
  167. "toolkit/airbag/airbag/autotools/depcomp",
  168. "toolkit/airbag/airbag/autotools/missing",
  169. "toolkit/airbag/airbag/autotools/ltmain.sh",
  170. "js/tamarin/pcre/ltmain.sh",
  171. "security/svrcore/compile",
  172. "security/svrcore/ltmain.sh",
  173. "security/svrcore/missing",
  174. "security/svrcore/depcomp",
  175. "security/svrcore/aclocal.m4",
  176. # Public domain or equivalent
  177. "nsprpub/config/nspr.m4",
  178. "toolkit/airbag/airbag/aclocal.m4",
  179. "security/nss/lib/freebl/mpi/mp_comba_amd64_sun.s",
  180. # GSSAPI has BSD-like licence requiring some attribution
  181. "extensions/auth/gssapi.h",
  182. # This script
  183. "tools/relic/relic",
  184. ]
  185. _g_skip_dir_basenames = [
  186. "CVS",
  187. ]
  188. _g_skip_dir_basenames_cvs_only = [
  189. "CVS",
  190. ]
  191. # Complete path from mozilla dir to a dir to skip.
  192. _g_skip_dirs = [
  193. # Test files for this script, which cause it to crash!
  194. "tools/relic/test",
  195. # License template files (TODO: this directory may disappear)
  196. "tools/wizards/templates/licenses",
  197. # As per the "New Original Source Files" section of:
  198. # http://www.mozilla.org/MPL/license-policy.html
  199. # with obsolete or now-relicensed directories removed
  200. "apache", # Obsolete mod_gzip code
  201. "cck", # mkaply's baby; not core code anyway.
  202. "dbm",
  203. "js/rhino", # Currently MPL/GPL - may end up BSD
  204. "webtools", # Various MPLed webtools
  205. # These could be done, but no-one's clamouring for it, and it's a hassle
  206. # sorting it all out, so let sleeping dogs lie.
  207. "msgsdk",
  208. "java",
  209. "privacy",
  210. # These have their own BSD-like license
  211. "media/libjpeg",
  212. # The following are not supposed to be relicensed, but they do have a
  213. # few files in we care about (like makefiles)
  214. "media/libpng",
  215. "modules/zlib",
  216. "gc/boehm",
  217. "other-licenses",
  218. # Copy of GPLed tool
  219. "tools/buildbot",
  220. # Other directories we want to exclude
  221. "embedding/tests", # Agreed as BSD
  222. "calendar/libical", # LGPL/MPL
  223. "gfx/cairo/cairo/src", # LGPL/MPL
  224. ]
  225. _g_basename_to_comment_info = {
  226. "configure": (["dnl"], ),
  227. "Makefile": (["#"], ),
  228. "makefile": (["#"], ),
  229. "nfspwd": (["#"], ),
  230. "typemap": (["#"], ),
  231. "xmplflt.conf": (["#"], ),
  232. "ldapfriendly": (["#"], ),
  233. "ldaptemplates.conf": (["#"], ),
  234. "ldapsearchprefs.conf": (["#"], ),
  235. "ldapfilter.conf": (["#"], ),
  236. "README.configure": (["#"], ),
  237. "Options.txt": (["#"], ),
  238. "fdsetsize.txt": (["#"], ),
  239. "prototype": (["#"], ),
  240. "prototype_i386": (["#"], ),
  241. "prototype3_i386": (["#"], ),
  242. "prototype_com": (["#"], ),
  243. "prototype3_com": (["#"], ),
  244. "prototype_sparc": (["#"], ),
  245. "prototype3_sparc": (["#"], ),
  246. "nglayout.mac": (["#"], ),
  247. "pkgdepend": (["#"], ),
  248. "Maketests": (["#"], ),
  249. "depend": (["#"], ),
  250. "csh-aliases": (["#"], ),
  251. "csh-env": (["#"], ),
  252. ".cshrc": (["#"], ),
  253. "MANIFEST": (["#"], ),
  254. "mozconfig": (["#"], ),
  255. "makecommon": (["#"], ),
  256. "bld_awk_pkginfo": (["#"], ),
  257. "prototype_i86pc": (["#"], ),
  258. "pkgdepend_5_6": (["#"], ),
  259. "awk_pkginfo-i386": (["#"], ),
  260. "awk_pkginfo-sparc": (["#"], ),
  261. "pkgdepend_64bit": (["#"], ),
  262. "WIN32": (["#"], ),
  263. "WIN16": (["#"], ),
  264. "Makefile.linux": (["#"], ),
  265. "README": ([""], ["#"]),
  266. "copyright": ([""], ),
  267. "xptcstubs_asm_ppc_darwin.s.m4": (["/*", "*", "*/"], ),
  268. "xptcstubs_asm_mips.s.m4": (["/*", "*", "*/"], ),
  269. "nsIDocCharsetTest.txt": (["<!--", "-", "-->"], ),
  270. "nsIFontListTest.txt": (["<!--", "-", "-->"], ),
  271. "ComponentListTest.txt": (["<!--", "-", "-->"], ),
  272. "nsIWebBrowserPersistTest1.txt": (["<!--", "-", "-->"], ),
  273. "nsIWebBrowserPersistTest2.txt": (["<!--", "-", "-->"], ),
  274. "nsIWebBrowserPersistTest3.txt": (["<!--", "-", "-->"], ),
  275. "plugins.txt": (["<!--", "-", "-->"], ),
  276. "NsISHistoryTestCase1.txt": (["<!--", "-", "-->"], ),
  277. "EmbedSmokeTest.txt": (["<!--", "-", "-->"], ),
  278. "lineterm_LICENSE": (["/*", "*", "*/"], ),
  279. "XMLterm_LICENSE": (["/*", "*", "*/"], ),
  280. "BrowserView.cpp.mod": (["/*", "*", "*/"], ),
  281. "header_template": (["/*", "*", "*/"], ),
  282. "cpp_template": (["/*", "*", "*/"], ),
  283. "abcFormat470.txt": (["//"], ),
  284. "opcodes.tbl": (["//"], ),
  285. }
  286. _g_ext_to_comment_info = {
  287. ".txt": (["##", "#", ], ["#"]),
  288. ".TXT": (["##", "#", ]),
  289. ".doc": (["", ]),
  290. ".build": (["", ]),
  291. ".1st": (["", ]),
  292. ".lsm": (["", ]),
  293. ".FP": (["", ]),
  294. ".spec": (["", ]),
  295. ".CPP": (["/*", "*", "*/"], ),
  296. ".cpp": (["/*", "*", "*/"], ),
  297. ".H": (["/*", "*", "*/"], ),
  298. ".h": (["/*", "*", "*/"], ),
  299. ".hxx": (["/*", "*", "*/"], ),
  300. ".c": (["/*", "*", "*/"], ),
  301. ".css": (["/*", "*", "*/"], ['#']),
  302. ".js": (["/*", "*", "*/"], ['#']),
  303. ".idl": (["/*", "*", "*/"], ),
  304. ".ut": (["/*", "*", "*/"], ),
  305. ".rc": (["/*", "*", "*/"], ),
  306. ".rc2": (["/*", "*", "*/"], ),
  307. ".RC": (["/*", "*", "*/"], ),
  308. ".Prefix": (["/*", "*", "*/"], ),
  309. ".prefix": (["/*", "*", "*/"], ),
  310. ".cfg": (["/*", "*", "*/"], ["#"]),
  311. ".cp": (["/*", "*", "*/"], ),
  312. ".cs": (["/*", "*", "*/"], ),
  313. ".java": (["/*", "*", "*/"], ),
  314. ".jst": (["/*", "*", "*/"], ),
  315. ".tbl": (["/*", "*", "*/"], ),
  316. ".tab": (["/*", "*", "*/"], ),
  317. ".cc": (["/*", "*", "*/"], ),
  318. ".msg": (["/*", "*", "*/"], ),
  319. ".y": (["/*", "*", "*/"], ),
  320. ".r": (["/*", "*", "*/"], ),
  321. ".mm": (["/*", "*", "*/"], ),
  322. ".x-ccmap":(["/*", "*", "*/"], ),
  323. ".ccmap": (["/*", "*", "*/"], ),
  324. ".sql": (["/*", "*", "*/"], ),
  325. ".pch++": (["/*", "*", "*/"], ),
  326. ".xpm": (["/*", "*", "*/"], ),
  327. ".uih": (["/*", "*", "*/"], ),
  328. ".uil": (["/*", "*", "*/"], ),
  329. ".ccmap": (["/*", "*", "*/"], ),
  330. ".map": (["/*", "*", "*/"], ),
  331. ".win98": (["/*", "*", "*/"], ),
  332. ".php": (["/*", "*", "*/"], ),
  333. ".m": (["/*", "*", "*/"], ),
  334. ".jnot": (["/*", "*", "*/"], ),
  335. ".l": (["/*", "*", "*/"], ),
  336. ".htp": (["/*", "*", "*/"], ),
  337. ".xs": (["/*", "*", "*/"], ),
  338. ".as": (["/*", "*", "*/"], ),
  339. ".api": (["/*", "*", "*/"], ['#']),
  340. ".applescript": (["(*", "*", "*)"], ["--"], ["#"]),
  341. ".html": (["<!--", "-", "-->"], ["#"]),
  342. ".xml": (["<!--", "-", "-->"], ["#"]),
  343. ".xbl": (["<!--", "-", "-->"], ["#"]),
  344. ".xsl": (["<!--", "-", "-->"], ),
  345. ".xul": (["<!--", "-", "-->"], ["#"]),
  346. ".dtd": (["<!--", "-", "-->"], ["#"]),
  347. ".rdf": (["<!--", "-", "-->"], ["#"]),
  348. ".htm": (["<!--", "-", "-->"], ),
  349. ".out": (["<!--", "-", "-->"], ),
  350. ".resx": (["<!--", "-", "-->"], ),
  351. ".bl": (["<!--", "-", "-->"], ),
  352. ".xif": (["<!--", "-", "-->"], ),
  353. ".xhtml":(["<!--", "-", "-->"], ["#"]),
  354. ".inc": (["<!--", "-", "-->"],
  355. ["#"],
  356. ["@!"],
  357. ["/*", "*", "*/"]),
  358. ".properties": (["#"], ),
  359. ".win": (["#"], ),
  360. ".dsp": (["#"], ),
  361. ".exp": (["#"], ),
  362. ".mk": (["#"], ),
  363. ".mn": (["#"], ),
  364. ".mak": (["#"], ),
  365. ".MAK": (["#"], ),
  366. ".perl": (["#"], ),
  367. ".pl": (["#"], ),
  368. ".PL": (["#"], ),
  369. ".sh": (["#"], ),
  370. ".dsw": (["#"], ),
  371. ".cgi": (["#"], ),
  372. ".pm": (["#"], ),
  373. ".pod": (["#"], ),
  374. ".src": (["#"], ),
  375. ".csh": (["#"], ),
  376. ".DLLs": (["#"], ),
  377. ".ksh": (["#"], ),
  378. ".toc": (["#"], ),
  379. ".am": (["#"], ),
  380. ".df": (["#"], ),
  381. ".client": (["#"], ),
  382. ".ref": (["#"], ), # all of them "Makefile.ref"
  383. ".ldif": (["#"], ),
  384. ".ex": (["#"], ),
  385. ".reg": (["#"], ),
  386. ".py": (["#"], ),
  387. ".adb": (["#"], ),
  388. ".dtksh": (["#"], ),
  389. ".pkg": (["#"], ),
  390. ".et": (["#"], ),
  391. ".stub": (["#"], ),
  392. ".nss": (["#"], ),
  393. ".os2": (["#"], ),
  394. ".Solaris": (["#"], ),
  395. ".rep": (["#"], ),
  396. ".NSS": (["#"], ),
  397. ".server": (["#"], ),
  398. ".awk": (["#"], ),
  399. ".targ": (["#"], ),
  400. ".gnuplot": (["#"], ),
  401. ".bash": (["#"], ),
  402. ".tmpl": (["#"], ),
  403. ".com": (["#"], ),
  404. ".dat": (["#"], ),
  405. ".rpm": (["#"], ),
  406. ".nsi": (["#"], ),
  407. ".nsh": (["#"], ),
  408. ".template": (["#"], ),
  409. ".ldkd": (["#"], ),
  410. ".ldku": (["#"], ),
  411. ".arm": (["#"], ),
  412. ".tdf": ([";"], ),
  413. ".def": ([";+#"], [";"]),
  414. ".DEF": ([";+#"], [";"]),
  415. ".ini": ([";"], ),
  416. ".it": ([";"], ),
  417. ".lisp": ([";;;"], ),
  418. ".cmd": (["rem"], ["REM"]),
  419. ".bat": (["rem"], ["REM"]),
  420. ".tex": (["%"], ),
  421. ".texi": (["%"], ),
  422. ".m4": (["dnl"], ),
  423. ".asm": ([";"], ),
  424. ".vbs": (["'"], ),
  425. ".il": (["!"], ),
  426. ".ad": (["!"], ),
  427. ".script": (["(*", " *", "*)"], ),
  428. ".3x": (['.\\"'], ),
  429. # What a mess...
  430. ".s": (["#"], ["//"], ["/*", "*", "*/"], ["!"], [";"], ["/"]),
  431. }
  432. _g_shebang_pattern_to_comment_info = [
  433. (re.compile(ur'\A#!.*/bin/(ba)?sh.*$', re.IGNORECASE), (["#"], )),
  434. (re.compile(ur'\A#!.*perl.*$', re.IGNORECASE), (["#"], )),
  435. (re.compile(ur'\A#!.*php.*$', re.IGNORECASE), (["#"], )),
  436. (re.compile(ur'\A#!.*python.*$', re.IGNORECASE), (["#"], )),
  437. (re.compile(ur'\A#!.*ruby.*$', re.IGNORECASE), (["#"], )),
  438. (re.compile(ur'\A#!.*tclsh.*$', re.IGNORECASE), (["#"], )),
  439. (re.compile(ur'\A#!.*wish.*$', re.IGNORECASE), (["#"], )),
  440. (re.compile(ur'\A#!.*expect.*$', re.IGNORECASE), (["#"], )),
  441. ]
  442. _g_trilicense_parts = {
  443. "mpl": """\
  444. ***** BEGIN LICENSE BLOCK *****
  445. Version: MPL 1.1/GPL 2.0/LGPL 2.1
  446. The contents of this file are subject to the Mozilla Public License Version
  447. 1.1 (the "License"); you may not use this file except in compliance with
  448. the License. You may obtain a copy of the License at
  449. http://www.mozilla.org/MPL/
  450. Software distributed under the License is distributed on an "AS IS" basis,
  451. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  452. for the specific language governing rights and limitations under the
  453. License.
  454. """,
  455. "npl": """\
  456. ***** BEGIN LICENSE BLOCK *****
  457. Version: NPL 1.1/GPL 2.0/LGPL 2.1
  458. The contents of this file are subject to the Netscape Public License
  459. Version 1.1 (the "License"); you may not use this file except in
  460. compliance with the License. You may obtain a copy of the License at
  461. http://www.mozilla.org/NPL/
  462. Software distributed under the License is distributed on an "AS IS" basis,
  463. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  464. for the specific language governing rights and limitations under the
  465. License.
  466. """,
  467. "original_code_is": """\
  468. The Original Code is %(original_code_is)s.
  469. """,
  470. "original_code_is_with_date": """\
  471. The Original Code is %(original_code_is)s, released
  472. %(original_code_date)s.
  473. """,
  474. "initial_developer": """\
  475. The Initial Developer of the Original Code is
  476. %(initial_developer)s.
  477. Portions created by the Initial Developer are Copyright (C) %(initial_copyright_date)s
  478. the Initial Developer. All Rights Reserved.
  479. """,
  480. "contributors": """\
  481. Contributor(s):
  482. %s
  483. """,
  484. "gpl for mpl": """\
  485. Alternatively, the contents of this file may be used under the terms of
  486. the GNU General Public License Version 2 or later (the "GPL"), in which
  487. case the provisions of the GPL are applicable instead of those above. If
  488. you wish to allow use of your version of this file only under the terms of
  489. the GPL and not to allow others to use your version of this file under the
  490. MPL, indicate your decision by deleting the provisions above and replacing
  491. them with the notice and other provisions required by the GPL. If you do
  492. not delete the provisions above, a recipient may use your version of this
  493. file under either the MPL or the GPL.
  494. ***** END LICENSE BLOCK *****""",
  495. "gpl for npl": """\
  496. Alternatively, the contents of this file may be used under the terms of
  497. the GNU General Public License Version 2 or later (the "GPL"), in which
  498. case the provisions of the GPL are applicable instead of those above. If
  499. you wish to allow use of your version of this file only under the terms of
  500. the GPL and not to allow others to use your version of this file under the
  501. NPL, indicate your decision by deleting the provisions above and replacing
  502. them with the notice and other provisions required by the GPL. If you do
  503. not delete the provisions above, a recipient may use your version of this
  504. file under either the NPL or the GPL.
  505. ***** END LICENSE BLOCK *****""",
  506. "gpl/lgpl for mpl": """\
  507. Alternatively, the contents of this file may be used under the terms of
  508. either the GNU General Public License Version 2 or later (the "GPL"), or
  509. the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  510. in which case the provisions of the GPL or the LGPL are applicable instead
  511. of those above. If you wish to allow use of your version of this file only
  512. under the terms of either the GPL or the LGPL, and not to allow others to
  513. use your version of this file under the terms of the MPL, indicate your
  514. decision by deleting the provisions above and replace them with the notice
  515. and other provisions required by the GPL or the LGPL. If you do not delete
  516. the provisions above, a recipient may use your version of this file under
  517. the terms of any one of the MPL, the GPL or the LGPL.
  518. ***** END LICENSE BLOCK *****""",
  519. "gpl/lgpl for npl": """\
  520. Alternatively, the contents of this file may be used under the terms of
  521. either the GNU General Public License Version 2 or later (the "GPL"), or
  522. the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  523. in which case the provisions of the GPL or the LGPL are applicable instead
  524. of those above. If you wish to allow use of your version of this file only
  525. under the terms of either the GPL or the LGPL, and not to allow others to
  526. use your version of this file under the terms of the NPL, indicate your
  527. decision by deleting the provisions above and replace them with the notice
  528. and other provisions required by the GPL or the LGPL. If you do not delete
  529. the provisions above, a recipient may use your version of this file under
  530. the terms of any one of the NPL, the GPL or the LGPL.
  531. ***** END LICENSE BLOCK *****""",
  532. }
  533. _g_dry_run = 0 # iff true, don't modify any files
  534. _g_force = 0
  535. _g_check_all = 0
  536. #---- internal support routines
  537. def _is_binary(filename):
  538. """Return true iff the given filename is binary.
  539. Raises an EnvironmentError if the file does not exist or cannot be
  540. accessed.
  541. """
  542. fin = open(filename, 'rb')
  543. try:
  544. CHUNKSIZE = 1024
  545. while 1:
  546. chunk = fin.read(CHUNKSIZE)
  547. if '\0' in chunk: # found null byte
  548. return 1
  549. if len(chunk) < CHUNKSIZE:
  550. break # done
  551. finally:
  552. fin.close()
  553. return 0
  554. _g_cvsignore_cache = {} # optimization: keep a cache of .cvsignore content
  555. def _should_skip_according_to_cvsignore(path):
  556. dirname, basename = os.path.split(path)
  557. cvsignore = os.path.join(dirname, ".cvsignore")
  558. if not os.path.exists(cvsignore):
  559. return 0
  560. elif cvsignore not in _g_cvsignore_cache:
  561. fin = open(cvsignore, 'r')
  562. to_ignore = []
  563. try:
  564. for f in fin:
  565. if f[-1] == "\n": f = f[:-1] # chomp
  566. if not f: continue # skip empty lines
  567. to_ignore.append(f)
  568. finally:
  569. fin.close()
  570. _g_cvsignore_cache[cvsignore] = to_ignore
  571. # At this point .cvsignore exists and its contents are in the cache.
  572. to_ignore = _g_cvsignore_cache[cvsignore]
  573. if basename in to_ignore:
  574. return 1
  575. else:
  576. return 0
  577. _g_backup_pattern = re.compile("~\d+$")
  578. def _should_skip_file(path):
  579. log.debug("_should_skip_file(path='%s')", path)
  580. if _g_check_all:
  581. return 0
  582. ext = os.path.splitext(path)[1]
  583. if ext in _g_skip_exts:
  584. log.info("Skipping '%s' (according to '_g_skip_exts').", path)
  585. return 1
  586. xpath = '/'.join(path.split(os.sep)) # use same sep as in _g_skip_files
  587. for sf in _g_skip_files:
  588. if xpath.endswith(sf):
  589. log.info("Skipping '%s' (according to '_g_skip_files').", path)
  590. return 1
  591. if os.path.basename(path) in _g_skip_file_basenames:
  592. log.info("Skipping '%s' (according to '_g_skip_file_basenames').", path)
  593. return 1
  594. if _should_skip_according_to_cvsignore(path):
  595. log.info("Skipping '%s' (according to .cvsignore).", path)
  596. return 1
  597. if _g_backup_pattern.search(path):
  598. log.info("Skipping '%s' (looks like backup file).", path)
  599. return 1
  600. return 0
  601. def _should_skip_dir(path):
  602. log.debug("_should_skip_dir(path='%s')", path)
  603. if _g_check_all:
  604. if os.path.basename(path) in _g_skip_dir_basenames_cvs_only:
  605. return 1
  606. return 0
  607. if os.path.basename(path) in _g_skip_dir_basenames:
  608. log.info("Skipping '%s' (according to _g_skip_dir_basenames).", path)
  609. return 1
  610. xpath = '/'.join(path.split(os.sep)) # use same sep as in _g_skip_dirs
  611. # These could do with being a proper path canonicalisation function...
  612. if xpath[-1] == '/': xpath = xpath[:-1] # treat "calendar/" the same as "calendar"
  613. if xpath[0:2] == './': xpath = xpath[2:] # treat "./calendar" the same as "calendar"
  614. for sd in _g_skip_dirs:
  615. # Changed by gerv to make skip_dirs require whole path
  616. if xpath == sd:
  617. log.info("Skipping '%s' (according to _g_skip_dirs).", path)
  618. return 1
  619. if _should_skip_according_to_cvsignore(path):
  620. log.info("Skipping '%s' (according to .cvsignore).", path)
  621. return 1
  622. return 0
  623. def _get_license_info(filename, show_initial=0, quick=0):
  624. """Return license block information for the given file.
  625. "filename" is the path to the file to scan.
  626. "show_initial" is a boolean that indicates if initial developer info
  627. should be displayed.
  628. "quick" is a boolean that can be set for a quick scan. In this
  629. case, only the "parts" field of the return dictionary will
  630. be filled out.
  631. Returns a dictionary adequately describing the license block in the
  632. given file for the purpose of determining whether to patch the
  633. license block and how. Returns a dictionary of the following form:
  634. {"parts": <list of zero or more of "mpl", "npl", "gpl", "lgpl",
  635. "unknown", "block_begin", "block_end" in the
  636. order in which they were found>,
  637. # if necessary, the following keys are included as well
  638. "begin_line": <(0-based) index at which license block starts>,
  639. "end_line": <(0-based) index at which license block ends>,
  640. "first_prefix": <prefix to use for new license block first line>,
  641. "subsequent_prefix": <prefix to use for subsequent lines>,
  642. "last_suffix": <suffix to use for last line>,
  643. # The following fields are correspond to the file specific
  644. # portions of the license template as described here:
  645. # http://www.mozilla.org/MPL/relicensing-faq.html#new-license
  646. # If the associated block is not found, then the value is None.
  647. "original_code_is": ...,
  648. "original_code_date": ...,
  649. "initial_developer": ...,
  650. "initial_copyright_date": ...,
  651. "contributors": ...,
  652. }
  653. precondition: should not be called on binary files
  654. """
  655. lic_info = {
  656. "parts": [],
  657. }
  658. fin = open(filename, 'r')
  659. try:
  660. content = fin.read()
  661. finally:
  662. fin.close()
  663. # Help me find filena
  664. log.info("Next file is: %s", filename)
  665. # do quick search to see if any of the desired licenses is in here
  666. # - if it looks like all the parts are there, good, done
  667. # - if some but not all parts, continue
  668. parts_pattern = re.compile("""(
  669. (?P<block_begin>\*\*\*\*\*\ BEGIN\ LICENSE\ BLOCK\ \*\*\*\*\*)
  670. | (?P<mpl>The\ contents\ of\ this\ file\ are\ subject\ to\ the\ Mozilla)
  671. | (?P<npl>The\ contents\ of\ this\ file\ are\ subject\ to\ the\ Netscape)
  672. | (?P<gpl>GNU\ (General\ )?Public\ License)
  673. | (?P<lgpl>(Library|Lesser)\ General\ Public\ License)
  674. | (?P<block_end>\*\*\*\*\*\ END\ LICENSE\ BLOCK\ \*\*\*\*\*)
  675. )""",
  676. re.VERBOSE)
  677. parts = [] # found license parts in this file
  678. start = 0
  679. blocks = 0
  680. while 1:
  681. match = parts_pattern.search(content, start)
  682. if match:
  683. # Skip this block, if the last license block is more than 10 lines
  684. # away (file is probably used for autogeneration of files then).
  685. if blocks == 1 and (match.start()-start) > 10:
  686. break
  687. else:
  688. parts = match.groupdict()
  689. for part in parts:
  690. if parts[part]:
  691. lic_info["parts"].append(part)
  692. log.info("%s license/delimeter found", part)
  693. start = match.end()
  694. if part == "block_end":
  695. blocks = blocks + 1
  696. else:
  697. blocks = 0
  698. break
  699. else:
  700. raise RelicError("unexpected license part: %r" % parts)
  701. else:
  702. break
  703. # no license block at all
  704. if not parts:
  705. # - if not, check to see if License or Copyright shows up in the
  706. # file; if so, then error out; if not, skip out
  707. any_lic_pattern = re.compile("(Copyright|Licen[sc]e)", re.IGNORECASE)
  708. match = any_lic_pattern.search(content)
  709. if match:
  710. lic_info["parts"].append("unknown")
  711. log.info("unknown license found: %r",
  712. content[max(match.start()-20,0):match.end()+20])
  713. else:
  714. log.info("no license found")
  715. return lic_info
  716. # license block with non-tri-license version headers
  717. elif lic_info["parts"] == ["block_begin", "block_end"]:
  718. lic_info["parts"].append("unknown")
  719. log.info("unknown license found (license block with non-tri-license)")
  720. return lic_info
  721. # license block with tri-license version headers
  722. elif (lic_info["parts"] == ["block_begin", "mpl", "gpl", "lgpl", "block_end"] or
  723. lic_info["parts"] == ["block_begin", "npl", "gpl", "lgpl", "block_end"]):
  724. log.info("license looks good, no changes necessary")
  725. if quick:
  726. return lic_info
  727. # Otherwise, the license needs to be fixed, so gather more detailed
  728. # information. Here is the algorithm we will use:
  729. # - find first license line
  730. # - find the end of this comment block (assumption: from the first
  731. # license line to the end of the comment block is the full
  732. # license block)
  733. # This is a bad assumption in two cases and steps have been taken
  734. # to try to deal with those cases:
  735. # - There could be a trailing part bit of comment that is
  736. # NOT part of the license but is part of the same comment
  737. # block. A common example are the:
  738. # This Original Code has been modified by IBM...
  739. # files (about 130 of them in the moz tree).
  740. # (c.f. test_relicense_ibm_copyright_suffix.c)
  741. # - Some files have split up the license paragraphs into
  742. # multiple comment blocks, e.g.
  743. # "mozilla/build/unix/abs2rel.pl":
  744. # # The contents of this file are subject to the
  745. # # ...
  746. # # the License at http://www.mozilla.org/MPL/
  747. #
  748. # # The Initial Developer of the Original Code
  749. # # ...
  750. # # Rights Reserved.
  751. # (c.f. test_relicense_separated_license_comment_blocks.pl)
  752. # - these are the lines to replace
  753. # - gather embedded lic data
  754. # - use second line to determine line prefix
  755. # ? Should we only allow processing of unknown-delimiter-files with
  756. # an option?
  757. # Get comment delimiter info for this file.
  758. comment_delim_sets = _get_comment_delim_sets(filename)
  759. # - find first license line (and determine which set of comment
  760. # delimiters are in use)
  761. lines = content.splitlines()
  762. for comment_delims in comment_delim_sets:
  763. if len(comment_delims) == 3:
  764. # Note: allow for whitespace before continuation character
  765. prefix_pattern = "%s|\s*%s|" % (re.escape(comment_delims[0]),
  766. re.escape(comment_delims[1]))
  767. suffix_pattern = "%s" % re.escape(comment_delims[2])
  768. elif len(comment_delims) == 2:
  769. prefix_pattern = "%s|" % re.escape(comment_delims[0])
  770. suffix_pattern = "%s" % re.escape(comment_delims[1])
  771. elif len(comment_delims) == 1:
  772. prefix_pattern = re.escape(comment_delims[-1])
  773. suffix_pattern = ""
  774. else: # len(comment_delims) == 0
  775. prefix_pattern = ""
  776. suffix_pattern = ""
  777. lic_begin_pattern = re.compile("""
  778. ^(?P<prefix>%s)
  779. (?P<space>\s*)
  780. (\*+\ BEGIN\ LICENSE\ BLOCK\ \*+
  781. |\-+\ BEGIN\ LICENSE\ BLOCK\ \-+
  782. | Version:\ MPL\ \d+\.\d+/GPL\ \d+\.\d+/LGPL\ \d+\.\d+
  783. | The\ contents\ of\ this\ file\ are\ subject\ to\ the\ Mozilla[\w ]*
  784. | The\ contents\ of\ this\ file\ are\ subject\ to\ the\ Netscape[\w ]*
  785. | Alternatively,\ the\ contents\ of\ this\ file\ may\ be\ used\ under\ the[\w ]*)
  786. (?P<suffix>%s|)\s*?$
  787. """ % (prefix_pattern, suffix_pattern), re.VERBOSE)
  788. for i in range(len(lines)):
  789. match = lic_begin_pattern.search(lines[i])
  790. if match:
  791. beginline = {
  792. "content": lines[i],
  793. "linenum": i,
  794. "prefix": match.group("prefix"),
  795. "space": match.group("space"),
  796. "suffix": match.group("suffix")
  797. }
  798. # Optimization: If the line before the "beginline" is simply
  799. # a block comment open the include that line in parsed out
  800. # license block. E.g.,
  801. # <!--
  802. # - ***** BEGIN LICENSE BLOCK *****
  803. # ...
  804. if (len(comment_delims) > 1 # only for block comments
  805. and beginline["prefix"] != comment_delims[0]
  806. and i-1 >= 0
  807. and lines[i-1].strip() == comment_delims[0]):
  808. beginline["linenum"] -= 1
  809. beginline["prefix"] = comment_delims[0]
  810. break
  811. if match: break
  812. else:
  813. raise RelicError("couldn't find start line with this pattern (even "
  814. "though it looks like there is a license block in "
  815. "%s): %s" % (filename, lic_begin_pattern.pattern))
  816. log.info("comment delimiters: %s", comment_delims)
  817. log.debug("beginline dict: %s", beginline)
  818. lic_info["comment_delims"] = comment_delims
  819. lic_info["begin_line"] = beginline["linenum"]
  820. lic_info["first_prefix"] = beginline["prefix"]
  821. log.info("prefix for first line: '%s'", beginline["prefix"])
  822. # - get second license line
  823. lic_middle_pattern = re.compile("""
  824. ^(?P<prefix>%s|)
  825. (?P<space>\s*)
  826. (?P<content>.*)
  827. (?P<suffix>%s|)\s*?$
  828. """ % (prefix_pattern, suffix_pattern),
  829. re.VERBOSE)
  830. # skip empty lines which might result in bogus scanning later, e.g.:
  831. # mozilla/layout/html/tests/table/marvin/x_thead_align_center.xml
  832. second_linenum = beginline["linenum"]+1
  833. while second_linenum < len(lines):
  834. if lines[second_linenum].strip():
  835. break
  836. log.debug("skip blank 'second' line: %d", second_linenum)
  837. second_linenum +=1
  838. else:
  839. raise RelicError("all lines after the first license block line (%d) "
  840. "were empty" % (beginline["linenum"]+1))
  841. match = lic_middle_pattern.search(lines[second_linenum])
  842. if match:
  843. secondline = {
  844. "content": lines[second_linenum],
  845. "linenum": second_linenum,
  846. "prefix": match.group("prefix"),
  847. "space": match.group("space"),
  848. "suffix": match.group("suffix")
  849. }
  850. else:
  851. raise RelicError("didn't find second line with pattern: %s"
  852. % lic_middle_pattern.pattern)
  853. log.debug("secondline dict: %s", secondline)
  854. lic_info["subsequent_prefix"] = secondline["prefix"]
  855. log.info("prefix for subsequent lines: '%s'", secondline["prefix"])
  856. # - find block comment end
  857. orig_code_modified_pattern = re.compile("This Original Code has been "
  858. "modified", re.I)
  859. non_lic_content_in_same_comment_block = 0
  860. if len(comment_delims) == 1:
  861. # line-style comments: The comment block "end" is defined as the
  862. # last line before a line NOT using the block comment delimiter.
  863. #XXX:BUG: This is not good enough for:
  864. # test/inputs/separated_license_comment_blocks.pl
  865. if comment_delims[0] == "":
  866. raise RelicError(
  867. "Don't know how to find the end of a line-style comment "
  868. "block when the delimiter is the empty string. (Basically "
  869. "this script cannot handle this type of file.)")
  870. for i in range(beginline["linenum"]+1, len(lines)):
  871. if not lines[i].startswith(comment_delims[0]):
  872. endlinenum = i-1
  873. break
  874. elif lines[i].find("END LICENSE BLOCK") != -1:
  875. endlinenum = i
  876. break
  877. # As per "test_relicense_trailing_orig_code_modified.pl", a
  878. # paragraph starting with:
  879. # This Original Code has been modified
  880. # is deemed to be OUTside the license block, i.e. it is not
  881. # replaced for relicensing.
  882. if orig_code_modified_pattern.search(lines[i]):
  883. non_lic_content_in_same_comment_block = 1
  884. # The endline is the first non-blank line before this one.
  885. endlinenum = i-1
  886. while 1:
  887. line = lines[endlinenum]
  888. match = lic_middle_pattern.search(line)
  889. if not match:
  890. raise RelicError("Line did not match lic_middle_pattern "
  891. "unexpectedly: %r" % line)
  892. if match.group("content").strip(): # non-empty line
  893. break
  894. endlinenum -= 1
  895. break
  896. else:
  897. raise RelicError("Could not find license comment block end "
  898. "line in '%s'." % filename)
  899. elif len(comment_delims) >= 2: # block-style comments
  900. for i in range(beginline["linenum"]+1, len(lines)):
  901. if lines[i].find(comment_delims[-1]) != -1:
  902. endlinenum = i
  903. break
  904. elif lines[i].find("END LICENSE BLOCK") != -1:
  905. endlinenum = i
  906. non_lic_content_in_same_comment_block = 1
  907. break
  908. # As per "test_relicense_ibm_copyright_suffix.c", a
  909. # paragraph starting with:
  910. # This Original Code has been modified
  911. # is deemed to be OUTside the license block, i.e. it is not
  912. # replaced for relicensing.
  913. if orig_code_modified_pattern.search(lines[i]):
  914. non_lic_content_in_same_comment_block = 1
  915. # The endline is the first non-blank line before this one.
  916. endlinenum = i-1
  917. while 1:
  918. line = lines[endlinenum]
  919. match = lic_middle_pattern.search(line)
  920. if not match:
  921. raise RelicError("Line did not match lic_middle_pattern "
  922. "unexpectedly: %r" % line)
  923. if match.group("content").strip(): # non-empty line
  924. break
  925. endlinenum -= 1
  926. break
  927. else:
  928. raise RelicError("Could not find license comment block end "
  929. "line in '%s'." % filename)
  930. if not non_lic_content_in_same_comment_block\
  931. and not lines[endlinenum].strip().endswith(comment_delims[-1]):
  932. raise RelicError(
  933. "There is text AFTER the license block comment end "
  934. "delimiter, but on the SAME LINE. This is unexpected. "
  935. "Bailing.\n%s:%s:%r"
  936. % (filename, endlinenum, lines[endlinenum]))
  937. else: # len(comment_delims) == 0
  938. # For files without a comment character to help out, we ONLY
  939. # successfully break one the full correct "END LICENSE BLOCK"
  940. # token.
  941. for i in range(beginline["linenum"]+1, len(lines)):
  942. if lines[i].find("END LICENSE BLOCK") != -1:
  943. endlinenum = i
  944. break
  945. elif i > beginline["linenum"]+1+50:
  946. raise RelicError("Haven't found 'END LICENSE BLOCK' marker "
  947. "within 50 lines of the start of the "
  948. "license block on line %d. Aborting."
  949. % (beginline["linenum"]+1))
  950. # As per "test_relicense_trailing_orig_code_modified.pl", a
  951. # paragraph starting with:
  952. # This Original Code has been modified
  953. # is deemed to be OUTside the license block, i.e. it is not
  954. # replaced for relicensing.
  955. if orig_code_modified_pattern.search(lines[i]):
  956. non_lic_content_in_same_comment_block = 1
  957. # The endline is the first non-blank line before this one.
  958. endlinenum = i-1
  959. while 1:
  960. line = lines[endlinenum]
  961. match = lic_middle_pattern.search(line)
  962. if not match:
  963. raise RelicError("Line did not match lic_middle_pattern "
  964. "unexpectedly: %r" % line)
  965. if match.group("content").strip(): # non-empty line
  966. break
  967. endlinenum -= 1
  968. break
  969. else:
  970. raise RelicError("Could not find license comment block end "
  971. "line in '%s'." % filename)
  972. # Test case: test_relicense_separated_license_comment_blocks.pl
  973. # It is possible that a separate comment block immediately following
  974. # the license block we just parsed should be included in the license
  975. # block.
  976. if (not non_lic_content_in_same_comment_block
  977. and len(comment_delims) == 1): # only do this for line-style comments
  978. lic_indicators = [
  979. re.compile("^The content of this file are subject to", re.I),
  980. re.compile("^Software distributed under the License", re.I),
  981. re.compile("^The Original Code is", re.I),
  982. re.compile("^The Initial Developer", re.I),
  983. re.compile("^Contributor", re.I),
  984. re.compile("^Alternatively, the content of this file", re.I),
  985. ]
  986. comment_line_pattern = re.compile("""
  987. ^(?P<prefix>%s|)
  988. (?P<space>\s*)
  989. (?P<content>.*)
  990. (?P<suffix>%s|)\s*?$
  991. """ % (prefix_pattern, suffix_pattern),
  992. re.VERBOSE)
  993. i = endlinenum
  994. while i+1 < len(lines):
  995. i += 1; line = lines[i]
  996. comment_index = line.find(comment_delims[0])
  997. if comment_index != -1:
  998. content = line[:comment_index].strip()
  999. comment = line[comment_index+len(comment_delims[0]):].strip()
  1000. else:
  1001. content = line.strip()
  1002. comment = ""
  1003. if content: # if non-comment content, then skip out
  1004. break
  1005. if not comment:
  1006. continue
  1007. for indicator in lic_indicators:
  1008. if indicator.search(comment):
  1009. # include this paragraph in the lic block
  1010. while i < len(lines):
  1011. i += 1; line = lines[i]
  1012. if not line.strip().startswith(comment_delims[0]):
  1013. break
  1014. if not line.strip()[len(comment_delims[0]):]:
  1015. break
  1016. endlinenum = i-1
  1017. break
  1018. else:
  1019. break # this is a non-lic-related comment
  1020. # Get the end-line data.
  1021. if non_lic_content_in_same_comment_block:
  1022. lic_end_pattern = re.compile(
  1023. "^(?P<prefix>%s)(?P<space>\s*).*?\s*?$"
  1024. % prefix_pattern)
  1025. else:
  1026. lic_end_pattern = re.compile(
  1027. "^(?P<prefix>%s)(?P<space>\s*).*?(?P<suffix>%s)\s*?$"
  1028. % (prefix_pattern, suffix_pattern))
  1029. match = lic_end_pattern.match(lines[endlinenum])
  1030. if match:
  1031. endline = {
  1032. "content": lines[endlinenum],
  1033. "linenum": endlinenum,
  1034. "prefix": match.group("prefix"),
  1035. "space": match.group("space"),
  1036. "suffix": match.groupdict().get("suffix", ""),
  1037. }
  1038. else:
  1039. raise RelicError("license block end line did not match: line='%s', "
  1040. "pattern='%s'"
  1041. % (lines[endlinenum], lic_end_pattern.pattern))
  1042. log.debug("endline dict: %s", endline)
  1043. lic_info["last_suffix"] = endline["suffix"]
  1044. log.info("suffix for last line: '%s'", endline["suffix"])
  1045. lic_info["end_line"] = endline["linenum"]
  1046. log.info("license lines: %d-%d", beginline["linenum"], endline["linenum"])
  1047. # So at this point we have the beginline, secondline, and endline
  1048. # dicts describing and bounding the license block.
  1049. # - gather embedded lic data
  1050. # As described here:
  1051. # http://www.mozilla.org/MPL/relicensing-faq.html#new-license
  1052. # we have to parse out the following possible fields:
  1053. # original_code_is
  1054. # original_code_date
  1055. # initial_developer
  1056. # initial_copyright_date
  1057. # contributors
  1058. lic_line_pattern = re.compile( # regex to parse out the line _body_
  1059. "^(?P<prefix>%s)(?P<space>\s*)(?P<body>.*?)(?P<suffix>%s|)\s*?$"
  1060. % (prefix_pattern, suffix_pattern))
  1061. original_code_is = None
  1062. original_code_date = None
  1063. # Parse out the "The Original Code is ..." paragraph _content_.
  1064. paragraph = ""
  1065. in_paragraph = 0
  1066. for i in range(beginline["linenum"], endline["linenum"]+1):
  1067. body = lic_line_pattern.match(lines[i]).group("body")
  1068. if (not in_paragraph and body.startswith("The Original Code is")):
  1069. in_paragraph = 1
  1070. if in_paragraph:
  1071. if not body.strip(): # i.e. a blank line, end of paragraph
  1072. break
  1073. # ensure one space btwn lines
  1074. if paragraph: paragraph = paragraph.rstrip() + " "
  1075. paragraph += body
  1076. if paragraph:
  1077. pattern1 = re.compile('^The Original Code is (.*), released (.*)\.')
  1078. match = pattern1.search(paragraph)
  1079. if match:
  1080. original_code_is = match.group(1)
  1081. original_code_date = match.group(2)
  1082. else:
  1083. pattern2 = re.compile('^The Original Code is (.*?)\.?$')
  1084. match = pattern2.search(paragraph)
  1085. if match:
  1086. original_code_is = match.group(1)
  1087. else:
  1088. raise RelicError(
  1089. "%s: 'The Original Code is' paragraph did not match the "
  1090. "expected patterns. paragraph=\n\t%r\n"
  1091. "pattern1=\n\t%r\npattern2=\n\t%r"
  1092. % (filename, paragraph, pattern1.pattern, pattern2.pattern))
  1093. lic_info["original_code_is"] = original_code_is
  1094. lic_info["original_code_date"] = original_code_date
  1095. log.info("original code is: %s", original_code_is)
  1096. log.info("original_code_date: %s", original_code_date)
  1097. initial_developer = None
  1098. initial_copyright_date = None
  1099. # Parse out the "The Initial Developer..." paragraph _content_.
  1100. paragraph = ""
  1101. in_paragraph = 0
  1102. for i in range(beginline["linenum"], endline["linenum"]+1):
  1103. body = lic_line_pattern.match(lines[i]).group("body")
  1104. if (not in_paragraph and
  1105. (body.startswith("The Initial Developer of") or
  1106. body.startswith("The Initial Developers of"))):
  1107. in_paragraph = 1
  1108. if in_paragraph:
  1109. if not body.strip(): # i.e. a blank line, end of paragraph
  1110. # Catch the possible case where there is an empty line
  1111. # but the paragraph picks up on the next line with
  1112. # "Portions created by"
  1113. # (test_relicense_no_period_after_origcodeis.cpp).
  1114. try:
  1115. nextlinebody = lic_line_pattern.match(lines[i+1]).group("body")
  1116. except:
  1117. nextlinebody = ""
  1118. if not nextlinebody.startswith("Portions created by"):
  1119. break
  1120. # ensure one space btwn lines
  1121. if paragraph: paragraph = paragraph.rstrip() + " "
  1122. paragraph += body
  1123. if paragraph:
  1124. pattern = re.compile("""^
  1125. The\ Initial\ Developers?\ of\
  1126. (the\ Original\ Code\ (is\ |are\ |is\.)|this\ code\ under\ the\ [MN]PL\ (is|are)\ )
  1127. (?P<developer>.*?)
  1128. \.? # maybe a trailing period
  1129. (
  1130. \s+Portions\ created\ by\ .*?
  1131. are\ Copyright\ \(C\)\[?\ (?P<date>[\d-]+)
  1132. .*? # maybe a trailing period
  1133. (\s+All\ Rights\ Reserved\.)?
  1134. )?
  1135. $""", re.VERBOSE)
  1136. match = pattern.search(paragraph)
  1137. if not match:
  1138. raise RelicError(
  1139. "%s: 'This Initial Develo…

Large files files are truncated, but you can click here to view the full file