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')) {
}
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'
}
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'
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'
}
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')
}
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'
}
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(
# 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)))
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)) {
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))
--- /dev/null
+#!/usr/bin/env r
+
+suppressPackageStartupMessages(library(cran2deb))
+suppressPackageStartupMessages(library(digest))
+
+exec_cmd <- function(argc, argv) {
+ usage <- function()
+ message('usage: add <license> [deny]|file <license> <path>|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)
+ }
+}
--- /dev/null
+#!/usr/bin/env r
+
+suppressPackageStartupMessages(library(cran2deb))
+suppressPackageStartupMessages(library(digest))
+
+exec_cmd <- function(argc, argv) {
+ usage <- function()
+ message('usage: add <debianpkg> <sysreq>|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)
+ }
+}