Created
May 27, 2020 17:02
-
-
Save slopp/46a34c87a8d4db287251fe8e749a70b0 to your computer and use it in GitHub Desktop.
Check PPM for a binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(httr) | |
check_binary <- function(pkg, | |
version, | |
distro, # one of windows, xenial, bionic, centos7, centos8, opensuse42, opensuse15 | |
r_version, | |
repo_base = "https://packagemanager.rstudio.com/cran/", | |
verbose = FALSE){ | |
pkg_url <- get_pkgurl(pkg, version, repo_base, distro, r_version) | |
ua <- sprintf("R/%s R (%s %s)", r_version, r_version, "x86_64-pc-linux-gnu x86_64 linux-gnu") | |
#ua <- "R/3.6.2 R (3.6.2 x86_64-pc-linux-gnu x86_64 linux-gnu)" | |
if (verbose) { | |
print(sprintf("User Agent: %s", ua)) | |
print(sprintf("Package URL: %s", pkg_url)) | |
} | |
res <- HEAD(url = pkg_url, httr::add_headers(`User-Agent`=ua)) | |
if(res[["status_code"]] != 200) { | |
"failed" | |
} else { | |
res[["headers"]][["x-package-type"]] | |
} | |
} | |
get_pkgurl <- function(pkg, version, repo_base, distro, r_version){ | |
if(is_latest(pkg, version, repo_base)) { | |
if (distro == "windows") { | |
r_majmin <- substr(r_version, 1, 3) | |
return(sprintf("%slatest/bin/windows/contrib/%s/%s_%s.zip", repo_base, r_majmin, pkg, version)) | |
} else { | |
return(sprintf("%s__linux__/%s/latest/src/contrib/%s_%s.tar.gz", repo_base, distro, pkg, version)) | |
} | |
} else { | |
if (distro == "windows") { | |
return(sprintf("%slatest/src/contrib/Archive/%s/%s_%s.tar.gz", repo_base, pkg, pkg, version)) | |
} else { | |
return(sprintf("%s__linux__/%s/latest/src/contrib/Archive/%s/%s_%s.tar.gz", repo_base, distro, pkg, pkg, version)) | |
} | |
} | |
} | |
is_latest <- function(pkg, version, repo_base){ | |
ap <- available.packages(repos = paste0(repo_base,"latest"), type = "source", ignore_repo_cache = TRUE) | |
pkgid <- which(rownames(ap) == pkg) | |
latest_vers <- ap[pkg, colnames(ap) == "Version"] | |
latest_vers == version | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment