From bc8eb6af5934d235e8d8caec853a8ae4d2882382 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Thu, 24 Aug 2023 19:08:44 -0400 Subject: [PATCH 1/4] Partial work towards Google Chrome for Testing update. Does renames. Still doesn't move the driver to the right place... --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/chrome.R | 4 +-- R/predl_chrome_for_testing.R | 50 +++++++++++++++++++++++++++++++++ inst/yaml/chromedriver.yml | 4 +-- man/predl_chrome_for_testing.Rd | 33 ++++++++++++++++++++++ 6 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 R/predl_chrome_for_testing.R create mode 100644 man/predl_chrome_for_testing.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ea86a0b..d82f91c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,5 +29,5 @@ Imports: URL: https://docs.ropensci.org/wdman/, https://github.com/ropensci/wdman URLNote: https://github.com/ropensci/wdman BugReports: https://github.com/ropensci/wdman/issues -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 14c5ad2..f60ecc2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,9 +4,11 @@ export(chrome) export(gecko) export(iedriver) export(phantomjs) +export(predl_chrome_for_testing) export(selenium) importFrom(assertthat,assert_that) importFrom(binman,app_dir) +importFrom(binman,assign_directory) importFrom(binman,list_versions) importFrom(binman,process_yaml) importFrom(binman,rm_platform) diff --git a/R/chrome.R b/R/chrome.R index af6e160..e0cb828 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -100,7 +100,7 @@ chrome <- function(port = 4567L, version = "latest", path = "wd/hub", chrome_check <- function(verbose, check = TRUE) { chromeyml <- system.file("yaml", "chromedriver.yml", package = "wdman") cyml <- yaml::yaml.load_file(chromeyml) - platvec <- c("predlfunction", "binman::predl_google_storage", "platform") + platvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platform") cyml[[platvec]] <- switch(Sys.info()["sysname"], Linux = grep(os_arch("linux"), cyml[[platvec]], value = TRUE), @@ -111,7 +111,7 @@ chrome_check <- function(verbose, check = TRUE) { # Need regex that can tell mac64 and mac64_m1 apart if (cyml[[platvec]] %in% c("mac64", "mac64_m1")) { - platregexvec <- c("predlfunction", "binman::predl_google_storage", "platformregex") + platregexvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platformregex") cyml[[platregexvec]] <- paste0(cyml[[platvec]], "\\.") } diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R new file mode 100644 index 0000000..1e376c9 --- /dev/null +++ b/R/predl_chrome_for_testing.R @@ -0,0 +1,50 @@ +#' Pre-download function for Chrome-for-testing site +#' +#' @param url URL of the JSON to use for files +#' @param platform One of `c("linux64", "mac-arm64", "mac-x64", +#' "win32", "win64") +#' @param history Integer number of recent entries +#' @param appname Name of the app, typically `"chromedriver"` +#' @param platformregex A filter for platforms. Defaults to the platform names. +#' +#' @return A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to +#' be processed. Used as input for `binman::download_files()` or an equivalent. +#' @importFrom binman assign_directory +#' @export +predl_chrome_for_testing <- function(url, platform, history, + appname, + platformregex = platform) { + assert_that(is_URL_file(url)) + assert_that(is_character(platform)) + platform <- c(mac64_m1 = "mac-arm64", + mac64 = "mac-x64", + linux32 = "linux32", + linux64 = "linux64", + win32 = "win64")[platform] + assert_that(is_integer(history)) + assert_that(is_string(appname)) + assert_that(is_character(platformregex)) + ver_data <- jsonlite::fromJSON(url)[[2]] + ver_data <- Filter(function(x) !is.null(x$downloads[[appname]]), + ver_data) + ver_data <- ver_data[order(as.numeric(names(ver_data)))] + unwrap <- function(entry) { + version <- entry$version + downloads <- entry$downloads[[appname]] + if (!is.null(downloads)) { + platform <- downloads$platform + url <- downloads$url + file <- basename(url) + data.frame(version, platform, url, file) + } + } + extracted <- do.call(rbind, lapply(ver_data, unwrap)) + app_links <- tapply(extracted, extracted$platform, identity) + app_links <- app_links[platform] + names(app_links) <- c("mac-arm64" = "mac64_m1", + "mac-x64" = "mac64", + linux32 = "linux32", + linux64 = "linux64", + win64 = "win32")[names(app_links)] + assign_directory(app_links, appname) +} diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index c6ee99c..7f962bf 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -1,7 +1,7 @@ name: chromedriver predlfunction: - "binman::predl_google_storage": - url: https://www.googleapis.com/storage/v1/b/chromedriver/o + "wdman::predl_chrome_for_testing": + url: https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json platform: - mac64_m1 - mac64 diff --git a/man/predl_chrome_for_testing.Rd b/man/predl_chrome_for_testing.Rd new file mode 100644 index 0000000..e8b89e0 --- /dev/null +++ b/man/predl_chrome_for_testing.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/predl_chrome_for_testing.R +\name{predl_chrome_for_testing} +\alias{predl_chrome_for_testing} +\title{Pre-download function for Chrome-for-testing site} +\usage{ +predl_chrome_for_testing( + url, + platform, + history, + appname, + platformregex = platform +) +} +\arguments{ +\item{url}{URL of the JSON to use for files} + +\item{platform}{One of `c("linux64", "mac-arm64", "mac-x64", +"win32", "win64")} + +\item{history}{Integer number of recent entries} + +\item{appname}{Name of the app, typically `"chromedriver"`} + +\item{platformregex}{A filter for platforms. Defaults to the platform names.} +} +\value{ +A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to +be processed. Used as input for `binman::download_files()` or an equivalent. +} +\description{ +Pre-download function for Chrome-for-testing site +} From 51f576bf69bf661deb12cb03ae7644318bf90eab Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Sat, 23 Sep 2023 13:35:28 -0400 Subject: [PATCH 2/4] First pass at fix for new chromedriver location --- NAMESPACE | 1 + R/predl_chrome_for_testing.R | 10 ++++++++++ inst/yaml/chromedriver.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index f60ecc2..c0c0e77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) +export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 1e376c9..cc4967e 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -48,3 +48,13 @@ predl_chrome_for_testing <- function(url, platform, history, win64 = "win32")[names(app_links)] assign_directory(app_links, appname) } + +#' @export +unziptar_dlfiles <- function(...) { + x <- binman::unziptar_dlfiles(...) + for (f in x) { + dir <- tools::file_path_sans_ext(f) + file.copy(list.files(dir, full.names = TRUE), dirname(dir)) + } + x +} diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index 7f962bf..593d4e4 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -13,5 +13,5 @@ predlfunction: dlfunction: "binman::download_files": [] postdlfunction: - "binman::unziptar_dlfiles": + "wdman::unziptar_dlfiles": chmod: TRUE From 3d6fed8cd481e80be12795b87b0bd358e86c2525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20V=C3=B6lkle?= Date: Mon, 23 Oct 2023 11:57:46 +0200 Subject: [PATCH 3/4] fix dependencies --- DESCRIPTION | 5 +++-- NAMESPACE | 1 - R/predl_chrome_for_testing.R | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b35835a..f92f2c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,8 +27,9 @@ Imports: assertthat, processx, yaml, - semver(>= 0.2.0), - utils + semver (>= 0.2.0), + utils, + jsonlite URL: https://docs.ropensci.org/wdman/, https://github.com/ropensci/wdman URLNote: https://github.com/ropensci/wdman BugReports: https://github.com/ropensci/wdman/issues diff --git a/NAMESPACE b/NAMESPACE index c0c0e77..f60ecc2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,6 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) -export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index cc4967e..9111dad 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -49,7 +49,6 @@ predl_chrome_for_testing <- function(url, platform, history, assign_directory(app_links, appname) } -#' @export unziptar_dlfiles <- function(...) { x <- binman::unziptar_dlfiles(...) for (f in x) { From db7b9125e1535ad9890ef02f81e33041ac652d35 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Wed, 25 Oct 2023 06:32:50 -0400 Subject: [PATCH 4/4] Fixes for @ashbythorpe suggestions. --- NAMESPACE | 1 + R/predl_chrome_for_testing.R | 14 +++++++++++++- man/unziptar_dlfiles.Rd | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 man/unziptar_dlfiles.Rd diff --git a/NAMESPACE b/NAMESPACE index f60ecc2..c0c0e77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) +export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 9111dad..6333e1b 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -49,9 +49,21 @@ predl_chrome_for_testing <- function(url, platform, history, assign_directory(app_links, appname) } +#' Unzip/untar downloaded files +#' +#' Unzip or untar downloaded files. Copies files into the +#' expected position. +#' +#' @param ... Passed into [binman::unziptar_dlfiles]. +#' +#' @return The same as [binman::unziptar_dlfiles]: a list of character +#' vectors indicating files processed. +#' +#' @export +#' @md unziptar_dlfiles <- function(...) { x <- binman::unziptar_dlfiles(...) - for (f in x) { + for (f in x$processed) { dir <- tools::file_path_sans_ext(f) file.copy(list.files(dir, full.names = TRUE), dirname(dir)) } diff --git a/man/unziptar_dlfiles.Rd b/man/unziptar_dlfiles.Rd new file mode 100644 index 0000000..ed27db1 --- /dev/null +++ b/man/unziptar_dlfiles.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/predl_chrome_for_testing.R +\name{unziptar_dlfiles} +\alias{unziptar_dlfiles} +\title{Unzip/untar downloaded files} +\usage{ +unziptar_dlfiles(...) +} +\arguments{ +\item{...}{Passed into \link[binman:unziptar_dlfiles]{binman::unziptar_dlfiles}.} +} +\value{ +The same as \link[binman:unziptar_dlfiles]{binman::unziptar_dlfiles}: a list of character +vectors indicating files processed. +} +\description{ +Unzip or untar downloaded files. Copies files into the +expected position. +}