PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/relic/relic

https://bitbucket.org/bgirard/tiling
Python | 2491 lines | 2324 code | 38 blank | 129 comment | 84 complexity | 7af0a6d52a286b932e70663517416222 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, BSD-2-Clause, LGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception, GPL-2.0, JSON, Apache-2.0, 0BSD, MIT

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

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

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