Skip to content

Commit

Permalink
Document and clean up functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbythorpe committed Oct 25, 2023
1 parent 2407d5d commit c1c874f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 46 deletions.
59 changes: 37 additions & 22 deletions R/predl_chrome_for_testing.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
#' Pre-download function for Chrome-for-testing site
#' Pre-download function for Chrome for Testing site
#'
#' @param url URL of the JSON to use for files
#' Prepare to download Chromedriver from the Chrome for Testing site.
#'
#' @param url URL containing the JSON used to locate 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.
#' "win32", "win64")`.
#'
#' @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 equivalent.
#'
#' @examples
#' \dontrun{
#' # predl_chrome_for_testing() is used by chrome()
#' chrome <- chrome()
#' chrome$stop()
#' }
#'
#' @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) {
predl_chrome_for_testing <- function(url, platform) {
assert_that(is_URL_file(url))
assert_that(is_character(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]]),
function(x) !is.null(x$downloads[["chromedriver"]]),
ver_data
)
ver_data <- ver_data[order(as.numeric(names(ver_data)))]
unwrap <- function(entry) {
version <- entry$version
downloads <- entry$downloads[[appname]]
downloads <- entry$downloads[["chromedriver"]]
if (!is.null(downloads)) {
platform <- downloads$platform
url <- downloads$url
Expand All @@ -38,7 +43,7 @@ predl_chrome_for_testing <- function(url, platform, history,
extracted <- do.call(rbind, lapply(ver_data, unwrap))
app_links <- tapply_identity(extracted, extracted$platform)
app_links <- app_links[platform]
assign_directory(app_links, appname)
assign_directory(app_links, "chromedriver")
}

# The same as tapply(x, y, identity), but works on older versions of R.
Expand All @@ -55,14 +60,24 @@ tapply_identity <- function(x, y) {
#' Unzip or untar a downloaded chromedriver file, then extract it from
#' its folder.
#'
#' @param ... Passed into [binman::unziptar_dlfiles].
#' @param dlfiles Passed into [binman::unziptar_dlfiles]: A data frame of
#' files.
#' @param chmod If `TRUE`, the files are made executable.
#'
#' @returns The same as [binman::unziptar_dlfiles()]: a list of character
#' vectors representing the processed files.
#'
#' @return The same as [binman::unziptar_dlfiles].
#' @examples
#' \dontrun{
#' # unziptar_chromedriver() is used by chrome()
#' chrome <- chrome()
#' chrome$stop()
#' }
#'
#' @export
unziptar_chromedriver <- function(...) {
chmod <- list(...)$chmod
x <- binman::unziptar_dlfiles(...)
unziptar_chromedriver <- function(dlfiles, chmod = TRUE) {
x <- binman::unziptar_dlfiles(dlfiles, chmod = chmod)

for (f in x$processed) {
dir <- tools::file_path_sans_ext(f)
file.copy(list.files(dir, full.names = TRUE), dirname(dir), copy.mode = TRUE)
Expand Down
1 change: 1 addition & 0 deletions inst/etc/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tries$chrome <- tryCatch(

tries$chrome_old <- tryCatch(
{
# Version of chrome that is not on the Chrome for Testing site
print("chrome (old)")
tmp <- chrome(verbose = TRUE, version = "114.0.5735.90")
print(tmp$log())
Expand Down
2 changes: 0 additions & 2 deletions inst/yaml/chromedriver_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ predlfunction:
- linux64
- win32
- win64
history: 3
appname: "chromedriver"
dlfunction:
"binman::download_files": []
postdlfunction:
Expand Down
35 changes: 16 additions & 19 deletions man/predl_chrome_for_testing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions man/unziptar_chromedriver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1c874f

Please sign in to comment.