2 ## DOC: cran2deb license
3 ## DOC: add licenses and change acceptance/rejection of licenses
6 suppressPackageStartupMessages(library(cran2deb))
7 suppressPackageStartupMessages(library(digest))
9 exec_cmd <- function(argc, argv) {
11 message(paste('usage: accept <license>'
13 ,' hash <license> (<path>|<hash>)'
14 ,' pkg <license> <pkg>'
25 if (cmd == 'accept' || cmd == 'reject') {
30 action = (cmd == 'accept')
31 db_add_license_override(argv[2],action)
32 } else if (cmd == 'hash') {
39 if (is.null(db_license_override_name(license))) {
40 error('license',license,'is not known; add it first')
43 if (file.exists(path)) {
44 license_sha1 = digest(readChar(path,file.info(path)$size)
45 ,algo='sha1', serialize=FALSE)
46 } else if (length(grep('^[0-9a-f]{40}$',path))) {
49 error(path,'does not exist and does not look like an SHA1 hash')
52 db_add_license_hash(license,license_sha1)
53 } else if (cmd == 'pkg') {
60 current_action <- db_license_override_name(license)
61 if (is.null(current_action)) {
62 notice('license',license,'is not known; add it')
66 if (!current_action) {
69 notice('in future, will',action,'the package',pkg_name,'under license',license)
71 success <- try((function() {
72 pkg <- prepare_pkg(tmp,pkg_name)
73 if (!('License' %in% names(pkg$description[1,]))) {
74 error('package',pkg$name,'has no License: field in DESCRIPTION')
77 first_license = (strsplit(chomp(pkg$description[1,'License'])
78 ,'[[:space:]]*\\|[[:space:]]*')[[1]])[1]
79 license_sha1 <- get_license_hash(pkg,first_license)
80 db_add_license_hash(license,license_sha1)
83 if (inherits(success,'try-error')) {
86 } else if (cmd == 'view') {
93 success <- try((function() {
94 pkg <- prepare_pkg(tmp,pkg_name)
95 if (!('License' %in% names(pkg$description[1,]))) {
96 error('package',pkg$name,'has no License: field in DESCRIPTION')
99 first_license = (strsplit(chomp(pkg$description[1,'License'])
100 ,'[[:space:]]*\\|[[:space:]]*')[[1]])[1]
101 first_license = get_license(pkg,first_license)
102 cat(strwrap(first_license),file='|less')
105 if (inherits(success,'try-error')) {
108 } else if (cmd == 'ls') {
109 for (x in db_license_overrides()) print(x)
110 } else if (cmd == 'help') {
113 } else if (cmd == 'quit') {
120 exec_cmd(argc-1,argv[c(2:argc)])
123 argv <- strsplit(readline('license> '),'[[:space:]]+')[[1]]
124 exec_cmd(length(argv),argv)