From b86fef4a3cc3fd9e53b7b20191558933790c474e Mon Sep 17 00:00:00 2001 From: blundellc Date: Sat, 13 Sep 2008 13:18:13 +0000 Subject: [PATCH] db+license+sysreq: frontend for sysreq and license updates. backend for sysreq. just need to modify cran2deb R dependency code to use database for this to be working. exec/license was accidently missing from previous commits. git-svn-id: svn://svn.r-forge.r-project.org/svnroot/cran2deb@57 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/trunk/R/db.R | 20 ++++++++++++-- pkg/trunk/R/license.R | 24 ++++++++--------- pkg/trunk/exec/license | 60 ++++++++++++++++++++++++++++++++++++++++++ pkg/trunk/exec/sysreq | 40 ++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 14 deletions(-) create mode 100755 pkg/trunk/exec/license create mode 100755 pkg/trunk/exec/sysreq diff --git a/pkg/trunk/R/db.R b/pkg/trunk/R/db.R index c72c8c3..8238a3d 100644 --- a/pkg/trunk/R/db.R +++ b/pkg/trunk/R/db.R @@ -5,8 +5,8 @@ db.start <- function() { tables <- dbListTables(con) if (!dbExistsTable(con,'sysreq_override')) { dbGetQuery(con,paste('CREATE TABLE sysreq_override (' - ,' debian_name TEXT UNIQUE NOT NULL' - ,',r_pattern TEXT UNIQUE NOT NULL' + ,' debian_name TEXT NOT NULL' + ,',r_pattern TEXT PRIMARY KEY NOT NULL' ,')')) } if (!dbExistsTable(con,'license_override')) { @@ -33,6 +33,7 @@ db.quote <- function(text) { } db.sysreq.override <- function(sysreq_text) { + sysreq_text <- tolower(sysreq_text) con <- db.start() results <- dbGetQuery(con,paste( 'SELECT debian_name FROM sysreq_override WHERE' @@ -42,6 +43,8 @@ db.sysreq.override <- function(sysreq_text) { } db.add.sysreq.override <- function(pattern,debian_name) { + pattern <- tolower(pattern) + debian_name <- tolower(debian_name) con <- db.start() results <- dbGetQuery(con,paste( 'INSERT OR REPLACE INTO sysreq_override' @@ -52,7 +55,16 @@ db.add.sysreq.override <- function(pattern,debian_name) { db.stop(con) } +db.sysreq.overrides <- function() { + con <- db.start() + overrides <- dbGetQuery(con,paste('SELECT * FROM sysreq_override')) + db.stop(con) + return(overrides) +} + + db.license.override.name <- function(name) { + name <- tolower(name) con <- db.start() results <- dbGetQuery(con,paste( 'SELECT accept FROM license_override WHERE' @@ -65,6 +77,7 @@ db.license.override.name <- function(name) { } db.add.license.override <- function(name,accept) { + name <- tolower(name) message(paste('adding',name,'accept?',accept)) if (accept != TRUE && accept != FALSE) { stop('accept must be TRUE or FALSE') @@ -80,6 +93,7 @@ db.add.license.override <- function(name,accept) { } db.license.override.file <- function(file_sha1) { + file_sha1 <- tolower(file_sha1) con <- db.start() results <- dbGetQuery(con,paste( 'SELECT name,accept FROM license_override' @@ -102,6 +116,8 @@ db.license.overrides <- function() { } db.add.license.file <- function(name,file_sha1) { + name <- tolower(name) + file_sha1 <- tolower(file_sha1) message(paste('adding file',file_sha1,'for',name)) con <- db.start() dbGetQuery(con,paste( diff --git a/pkg/trunk/R/license.R b/pkg/trunk/R/license.R index 06181bf..619147b 100644 --- a/pkg/trunk/R/license.R +++ b/pkg/trunk/R/license.R @@ -3,8 +3,8 @@ is_acceptable_license <- function(license) { # compress spaces into a single space license = gsub('[[:blank:]]+',' ',license) - # make all characters upper case - license = toupper(license) + # make all characters lower case + license = tolower(license) # don't care about versions of licenses license = chomp(sub('\\( ?[<=>!]+ ?[0-9.-]+ ?\\)','' ,sub('-[0-9.-]+','',license))) @@ -12,20 +12,20 @@ is_acceptable_license <- function(license) { return(T) } # uninteresting urls - license = gsub('HTTP://WWW.GNU.ORG/[A-Z/._-]*','',license) - license = gsub('HTTP://WWW.X.ORG/[A-Z/._-]*','',license) - license = gsub('HTTP://WWW.OPENSOURCE.ORG/[A-Z/._-]*','',license) + license = gsub('http://www.gnu.org/[[:alnum:]/._-]*','',license) + license = gsub('http://www.x.org/[[:alnum:]/._-]*','',license) + license = gsub('http://www.opensource.org/[[:alnum]/._-]*','',license) # remove all punctuation license = gsub('[[:punct:]]+','',license) # remove any extra space introduced license = chomp(gsub('[[:space:]]+',' ',license)) # redundant - license = gsub('THE','',license) - license = gsub('SEE','',license) - license = gsub('STANDARD','',license) - license = gsub('LICEN[SC]E','',license) - license = gsub('(GNU )?(GPL|GENERAL PUBLIC)','GPL',license) - license = gsub('(MOZILLA )?(MPL|MOZILLA PUBLIC)','MPL',license) + license = gsub('the','',license) + license = gsub('see','',license) + license = gsub('standard','',license) + license = gsub('licen[sc]e','',license) + license = gsub('(gnu )?(gpl|general public)','gpl',license) + license = gsub('(mozilla )?(mpl|mozilla public)','mpl',license) # remove any extra space introduced license = chomp(gsub('[[:space:]]+',' ',license)) if (db.license.override.name(license)) { @@ -33,7 +33,7 @@ is_acceptable_license <- function(license) { return(T) } # remove everything that looks like a version specification - license = gsub('(VER?SION|V)? *[0-9.-]+ *(OR *(HIGHER|LATER|NEWER|GREATER|ABOVE))?','' + license = gsub('(ver?sion|v)? *[0-9.-]+ *(or *(higher|later|newer|greater|above))?','' ,license) # remove any extra space introduced license = chomp(gsub('[[:space:]]+',' ',license)) diff --git a/pkg/trunk/exec/license b/pkg/trunk/exec/license new file mode 100755 index 0000000..e9fa64a --- /dev/null +++ b/pkg/trunk/exec/license @@ -0,0 +1,60 @@ +#!/usr/bin/env r + +suppressPackageStartupMessages(library(cran2deb)) +suppressPackageStartupMessages(library(digest)) + +exec_cmd <- function(argc, argv) { + usage <- function() + message('usage: add [deny]|file |ls|quit|help') + + cmd = argv[1] + if (argc < 1) { + exit() + } + + if (cmd == 'add') { + if (argc != 2 && (argc != 3 || argv[3] != 'deny')) { + usage() + return() + } + accept = (argc != 3) + db.add.license.override(argv[2],accept) + } else if (cmd == 'file') { + if (argc != 3) { + usage() + return() + } + license = argv[2] + path = argv[3] + if (is.null(db.license.override.name(license))) { + message(paste('license',license,'is not known')) + return() + } + if (file.exists(path)) { + file_sha1 = digest(readChar(path,file.info(path)$size) + ,algo='sha1', serialize=FALSE) + } else if (length(grep('^[0-9a-f]{40}$',path))) { + file_sha1 = path + } else { + stop(paste(path,'does not exist and does not look like an SHA1 hash')) + } + db.add.license.file(license,file_sha1) + } else if (cmd == 'ls') { + for (x in db.license.overrides()) print(x) + } else if (cmd == 'help') { + usage() + return() + } else if (cmd == 'quit') { + exit() + } +} + +argc <- length(argv) +if (argc > 1) { + exec_cmd(argc-1,argv[c(2:argc)]) +} else { + while(T) { + argv <- strsplit(readline('license> '),'[[:space:]]+')[[1]] + exec_cmd(length(argv),argv) + } +} diff --git a/pkg/trunk/exec/sysreq b/pkg/trunk/exec/sysreq new file mode 100755 index 0000000..b9c464e --- /dev/null +++ b/pkg/trunk/exec/sysreq @@ -0,0 +1,40 @@ +#!/usr/bin/env r + +suppressPackageStartupMessages(library(cran2deb)) +suppressPackageStartupMessages(library(digest)) + +exec_cmd <- function(argc, argv) { + usage <- function() + message('usage: add |ls|quit|help') + + cmd = argv[1] + if (argc < 1) { + exit() + } + + if (cmd == 'add') { + if (argc < 3) { + usage() + return() + } + sysreq = paste(argv[3:argc],collapse=' ') + db.add.sysreq.override(sysreq,argv[2]) + } else if (cmd == 'ls') { + print(db.sysreq.overrides()) + } else if (cmd == 'help') { + usage() + return() + } else if (cmd == 'quit') { + exit() + } +} + +argc <- length(argv) +if (argc > 1) { + exec_cmd(argc-1,argv[c(2:argc)]) +} else { + while(T) { + argv <- strsplit(readline('sysreq> '),'[[:space:]]+')[[1]] + exec_cmd(length(argv),argv) + } +} -- 2.39.5