Commit 9b125be05c3fd54e1855662f6755489a5810219c
0 parents
First commit
Showing
1 changed file
with
73 additions
and
0 deletions
Show diff stats
| 1 | +++ a/InstallPamCloud.r | |
| 1 | + | |
| 2 | + | |
| 3 | +checkpack <- function(packagename){ | |
| 4 | + if (! (packagename %in% installed.packages() ) ){ | |
| 5 | + install.packages(packagename, repos = "http://cran.rstudio.com/", dependencies = TRUE) | |
| 6 | + } | |
| 7 | + library(packagename,character.only = TRUE) | |
| 8 | +} | |
| 9 | + | |
| 10 | +PamCloud.getBinaryURL= function(url = "https://pamcloud.pamgene.com/jackrabbit/repository/default/PamCloud/BioNavigator/Resources/readme.txt", credentials = login.dialog()){ | |
| 11 | + checkpack("RCurl") | |
| 12 | + if(!is.null(credentials)){ | |
| 13 | + aFile = getBinaryURL(url, userpwd = paste(credentials$user,credentials$pw, sep = ":"), ssl.verifypeer = FALSE) | |
| 14 | + } else{ | |
| 15 | + aFile = getBinaryURL(url, ssl.verifypeer = FALSE) | |
| 16 | + } | |
| 17 | + return(aFile) | |
| 18 | +} | |
| 19 | + | |
| 20 | +PamCloud.checkAccess = function(credentials = login.dialog()){ | |
| 21 | + aFile = PamCloud.getBinaryURL(credentials = credentials) | |
| 22 | + return(substring(rawToChar(aFile),1,33) == "<PamCloud Bionavigator Resources>") | |
| 23 | +} | |
| 24 | + | |
| 25 | +PamCloud.installPackage = function(packageUrl, tmpDir = "C:\\temp"){ | |
| 26 | + nPack = length(packageUrl) | |
| 27 | + print(paste("Installing", nPack, "packages")) | |
| 28 | + credentials = login.dialog() | |
| 29 | + if(!PamCloud.checkAccess(credentials)){ | |
| 30 | + stop("PamCloud access denied or not available") | |
| 31 | + } | |
| 32 | + | |
| 33 | + | |
| 34 | + for (i in 1:nPack){ | |
| 35 | + aFile = PamCloud.getBinaryURL(packageUrl[i], credentials) | |
| 36 | + | |
| 37 | + if (!file.exists("C:\\temp")){ | |
| 38 | + tmpDir = getwd(); | |
| 39 | + } | |
| 40 | + pckFile = file.path(tmpDir, basename(packageUrl[i])) | |
| 41 | + writeBin(aFile, pckFile) | |
| 42 | + install.packages(pckFile, repos = NULL) | |
| 43 | + } | |
| 44 | +} | |
| 45 | + | |
| 46 | +login.dialog = function(){ | |
| 47 | + checkpack("tcltk") | |
| 48 | + credentials = list(user = "PamCloud User Name", pw = "pass") | |
| 49 | + onok = function(){tkcget | |
| 50 | + tkdestroy(tt) | |
| 51 | + } | |
| 52 | + tt = tktoplevel() | |
| 53 | + label.user = tklabel(tt, text = "User Name") | |
| 54 | + userVal = tclVar(init = credentials$user) | |
| 55 | + entry.user = tkentry(tt, textvariable = userVal) | |
| 56 | + label.pw = tklabel(tt, text = "Password") | |
| 57 | + pwVal = tclVar(init = credentials$pw) | |
| 58 | + entry.pw = tkentry(tt, textvariable = pwVal, show = "*") | |
| 59 | + button.ok = tkbutton(tt, text = "OK", command =onok) | |
| 60 | + tkpack(label.user) | |
| 61 | + tkpack(entry.user) | |
| 62 | + tkpack(label.pw) | |
| 63 | + tkpack(entry.pw) | |
| 64 | + tkpack(button.ok) | |
| 65 | + tkfocus(tt) | |
| 66 | + tkwait.window(tt) | |
| 67 | + credentials$user = tclvalue(userVal) | |
| 68 | + credentials$pw = tclvalue(pwVal) | |
| 69 | + return(credentials) | |
| 70 | +} | |
| 71 | + | |
| 72 | +checkpack("RCurl") | |
| 73 | +PamCloud.installPackage(packageUrl = "https://pamcloud.pamgene.com/jackrabbit/repository/default/PamCloud/BioNavigator/Resources/PamCloud_1.0.zip") | |
| 0 | 74 | \ No newline at end of file | ... | ... |