1 is_acceptable_license <- function(license) {
2 # determine if license text is acceptable
4 if (length(grep('^file ',license))) {
8 license <- license_text_reduce(license)
9 action = db_license_override_name(license)
13 license <- license_text_further_reduce(license)
14 action = db_license_override_name(license)
16 warn('Accepting/rejecting wild license as',license,'. FIX THE PACKAGE!')
19 license <- license_text_extreme_reduce(license)
20 action = db_license_override_name(license)
22 warn('Accepting/rejecting wild license as',license,'. FIX THE PACKAGE!')
25 # TODO: file {LICENSE,LICENCE} (+ maybe COPYING?)
26 error('Wild license',license,'did not match classic rules; rejecting')
30 license_text_reduce <- function(license) {
31 # these reduction steps are sound for all conformant R license
34 # compress spaces into a single space
35 license = gsub('[[:space:]]+',' ',license)
36 # make all characters lower case
37 license = tolower(license)
38 # don't care about versions of licenses
39 license = chomp(sub('\\( ?[<=>!]+ ?[0-9.-]+ ?\\)',''
40 ,sub('-[0-9.-]+','',license)))
41 # remove any extra space introduced
42 license = chomp(gsub('[[:space:]]+',' ',license))
46 license_text_further_reduce <- function(license) {
47 # these reduction steps are heuristic and may lead to
48 # in correct acceptances, if care is not taken.
51 license = gsub('http://www.gnu.org/[[:alnum:]/._-]*','',license)
52 license = gsub('http://www.x.org/[[:alnum:]/._-]*','',license)
53 license = gsub('http://www.opensource.org/[[:alnum:]/._-]*','',license)
54 # remove all punctuation
55 license = gsub('[[:punct:]]+','',license)
56 # remove any extra space introduced
57 license = chomp(gsub('[[:space:]]+',' ',license))
59 license = gsub('the','',license)
60 license = gsub('see','',license)
61 license = gsub('standard','',license)
62 license = gsub('licen[sc]e','',license)
63 license = gsub('(gnu )?(gpl|general public)','gpl',license)
64 license = gsub('(mozilla )?(mpl|mozilla public)','mpl',license)
65 # remove any extra space introduced
66 license = chomp(gsub('[[:space:]]+',' ',license))
70 license_text_extreme_reduce <- function(license) {
71 # remove everything that may or may not be a version specification
72 license = gsub('(ver?sion|v)? *[0-9.-]+ *(or *(higher|later|newer|greater|above))?',''
74 # remove any extra space introduced
75 license = chomp(gsub('[[:space:]]+',' ',license))
79 license_text_hash_reduce <- function(text) {
80 # reduction of license text, suitable for hashing.
81 return(chomp(tolower(gsub('[[:space:]]+',' ',text))))
84 get_license <- function(pkg,license) {
85 license <- chomp(gsub('[[:space:]]+',' ',license))
86 if (length(grep('^file ',license))) {
87 if (length(grep('^file LICEN[CS]E$',license))) {
88 path = gsub('file ','',license)
89 path = file.path(pkg$path, path)
90 license <- license_text_reduce(readChar(path,file.info(path)$size))
92 error('invalid license file specification',license)
99 get_license_hash <- function(pkg,license) {
100 return(digest(get_license(pkg,license),algo='sha1',serialize=FALSE))
103 is_acceptable_hash_license <- function(pkg,license) {
104 license_sha1 <- get_license_hash(pkg,license)
105 if (is.na(license_sha1)) {
108 action = db_license_override_hash(license_sha1)
113 warn('Wild license',license,'accepted via hash',license_sha1)
119 accept_license <- function(pkg) {
121 if (!('License' %in% names(pkg$description[1,]))) {
122 fail('package has no License: field in description!')
125 for (license in strsplit(chomp(pkg$description[1,'License'])
126 ,'[[:space:]]*\\|[[:space:]]*')[[1]]) {
127 if (is_acceptable_license(license)) {
131 if (is_acceptable_hash_license(pkg,license)) {
136 if (is.null(accept)) {
137 fail('No acceptable license:',pkg$description[1,'License'])
139 notice('Auto-accepted license',accept)
141 if (accept == 'Unlimited') {
142 # definition of Unlimited from ``Writing R extensions''
143 accept=paste('Unlimited (no restrictions on distribution or'
144 ,'use other than those imposed by relevant laws)')