From 6e9d4006449c27d6c73e7371d2cedf3dd973f700 Mon Sep 17 00:00:00 2001 From: blundellc Date: Sat, 13 Sep 2008 13:20:35 +0000 Subject: [PATCH] license: split out some of the heuristics for reducing poorly formed license fields. in particular, do not remove numbers in just one step. it seems common for people to use: License: X11 (http://blahblah/dfgdfg/) which will be reduce to just 'x' if these steps are not split. Also separate license hashing into getting the license text and then separately hashing via digest. (Useful for for the 'view' command about to be added to cran2deb license.) git-svn-id: svn://svn.r-forge.r-project.org/svnroot/cran2deb@76 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/trunk/R/license.R | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/trunk/R/license.R b/pkg/trunk/R/license.R index c8a3dde..6453524 100644 --- a/pkg/trunk/R/license.R +++ b/pkg/trunk/R/license.R @@ -16,6 +16,12 @@ is_acceptable_license <- function(license) { message(paste('W: Accepting/rejecting wild license as',license,'. FIX THE PACKAGE!')) return(action) } + license <- license_text_extreme_reduce(license) + action = db_license_override_name(license) + if (!is.na(action)) { + message(paste('W: Accepting/rejecting wild license as',license,'. FIX THE PACKAGE!')) + return(action) + } # TODO: file {LICENSE,LICENCE} (+ maybe COPYING?) message(paste('E: Wild license',license,'did not match classic rules; rejecting')) return(F) @@ -56,7 +62,13 @@ license_text_further_reduce <- function(license) { license = gsub('licen[sc]e','',license) license = gsub('(gnu )?(gpl|general public)','gpl',license) license = gsub('(mozilla )?(mpl|mozilla public)','mpl',license) - # remove everything that looks like a version specification + # remove any extra space introduced + license = chomp(gsub('[[:space:]]+',' ',license)) + return(license) +} + +license_text_extreme_reduce <- function(license) { + # remove everything that may or may not be a version specification license = gsub('(ver?sion|v)? *[0-9.-]+ *(or *(higher|later|newer|greater|above))?','' ,license) # remove any extra space introduced @@ -69,8 +81,8 @@ license_text_hash_reduce <- function(text) { return(chomp(tolower(gsub('[[:space:]]+',' ',text)))) } -get_license_hash <- function(pkg,license) { - license <- license_text_reduce(license) +get_license <- function(pkg,license) { + license <- chomp(gsub('[[:space:]]+',' ',license)) if (length(grep('^file ',license))) { if (length(grep('^file LICEN[CS]E$',license))) { path = gsub('file ','',license) @@ -81,7 +93,11 @@ get_license_hash <- function(pkg,license) { return(NA) } } - return(digest(license,algo='sha1',serialize=FALSE)) + return(license) +} + +get_license_hash <- function(pkg,license) { + return(digest(get_license(pkg,license),algo='sha1',serialize=FALSE)) } is_acceptable_hash_license <- function(pkg,license) { -- 2.39.5