Skip to content

Commit 471e912

Browse files
authored
Add option to show progress bar for webdav downloads (#113)
1 parent 59bb219 commit 471e912

4 files changed

Lines changed: 30 additions & 21 deletions

File tree

Rlabkey/R/labkey.webdav.R

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# limitations under the License.
1515
##
1616

17-
labkey.webdav.get <- function(baseUrl=NULL, folderPath, remoteFilePath, localFilePath, overwrite=TRUE, fileSet="@files")
17+
labkey.webdav.get <- function(baseUrl=NULL, folderPath, remoteFilePath, localFilePath, overwrite=TRUE, fileSet="@files", showProgressBar=FALSE)
1818
{
19-
baseUrl=labkey.getBaseUrl(baseUrl);
19+
baseUrl <- labkey.getBaseUrl(baseUrl);
2020

2121
## check required parameters
2222
if (missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(remoteFilePath) || missing(localFilePath)){
@@ -33,15 +33,15 @@ labkey.webdav.get <- function(baseUrl=NULL, folderPath, remoteFilePath, localFil
3333

3434
url <- paste(baseUrl, "_webdav", folderPath, fileSet, "/", remoteFilePath, sep="");
3535

36-
ret <- labkey.webdav.getByUrl(url, localFilePath, overwrite)
36+
ret <- labkey.webdav.getByUrl(url, localFilePath, overwrite, showProgressBar = showProgressBar)
3737
if (!is.null(ret) && !is.na(ret) && ret == FALSE) {
3838
return(FALSE)
3939
}
4040

4141
return(file.exists(localFilePath))
4242
}
4343

44-
labkey.webdav.getByUrl <- function(url, localFilePath, overwrite=TRUE)
44+
labkey.webdav.getByUrl <- function(url, localFilePath, overwrite=TRUE, showProgressBar=FALSE)
4545
{
4646
# dont bother querying if this file already exists, since we wont overwrite it
4747
if (!overwrite & file.exists(localFilePath)) {
@@ -59,11 +59,16 @@ labkey.webdav.getByUrl <- function(url, localFilePath, overwrite=TRUE)
5959

6060
options <- labkey.getRequestOptions(method="GET")
6161

62+
progressBar <- NULL
63+
if (showProgressBar) {
64+
progressBar <- httr::progress()
65+
}
66+
6267
if (!is.null(.lkdefaults[["debug"]]) && .lkdefaults[["debug"]] == TRUE){
6368
print(paste0("URL: ", url))
64-
response <- GET(url=url, write_disk(localFilePath, overwrite=overwrite), config=options, verbose(data_in=TRUE, info=TRUE, ssl=TRUE))
69+
response <- GET(url=url, write_disk(localFilePath, overwrite=overwrite), config=options, verbose(data_in=TRUE, info=TRUE, ssl=TRUE), progressBar)
6570
} else {
66-
response <- GET(url=url, write_disk(localFilePath, overwrite=overwrite), config=options)
71+
response <- GET(url=url, write_disk(localFilePath, overwrite=overwrite), config=options, progressBar)
6772
}
6873

6974
processResponse(response)
@@ -120,7 +125,7 @@ labkey.webdav.mkDir <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSe
120125

121126
labkey.webdav.validateAndBuildRemoteUrl <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSet="@files")
122127
{
123-
baseUrl=labkey.getBaseUrl(baseUrl);
128+
baseUrl <- labkey.getBaseUrl(baseUrl);
124129

125130
## check required parameters
126131
if (missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(fileSet) || missing(remoteFilePath)){
@@ -143,7 +148,7 @@ encodeRemotePath <- function(path, splitSlash = TRUE) {
143148

144149
labkey.webdav.pathExists <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSet="@files")
145150
{
146-
baseUrl=labkey.getBaseUrl(baseUrl);
151+
baseUrl <- labkey.getBaseUrl(baseUrl);
147152

148153
if (missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(remoteFilePath)) {
149154
stop (paste("A value must be specified for each of baseUrl, folderPath, fileSet, and remoteFilePath"));
@@ -162,7 +167,7 @@ labkey.webdav.isDirectory <- function(baseUrl=NULL, folderPath, remoteFilePath,
162167

163168
labkey.webdav.listDir <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSet="@files", haltOnError = TRUE)
164169
{
165-
baseUrl=labkey.getBaseUrl(baseUrl);
170+
baseUrl <- labkey.getBaseUrl(baseUrl);
166171

167172
url <- labkey.webdav.validateAndBuildRemoteUrl(baseUrl=baseUrl, folderPath=folderPath, fileSet=fileSet, remoteFilePath=remoteFilePath)
168173
url <- paste0(url, "?method=JSON")
@@ -191,7 +196,7 @@ labkey.webdav.listDir <- function(baseUrl=NULL, folderPath, remoteFilePath, file
191196

192197
labkey.webdav.delete <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSet="@files")
193198
{
194-
baseUrl=labkey.getBaseUrl(baseUrl);
199+
baseUrl <- labkey.getBaseUrl(baseUrl);
195200

196201
url <- labkey.webdav.validateAndBuildRemoteUrl(baseUrl=baseUrl, folderPath=folderPath, fileSet=fileSet, remoteFilePath=remoteFilePath)
197202
url <- paste0(url, "?method=DELETE")
@@ -206,7 +211,7 @@ labkey.webdav.delete <- function(baseUrl=NULL, folderPath, remoteFilePath, fileS
206211

207212
labkey.webdav.mkDirs <- function(baseUrl=NULL, folderPath, remoteFilePath, fileSet="@files")
208213
{
209-
baseUrl=labkey.getBaseUrl(baseUrl);
214+
baseUrl <- labkey.getBaseUrl(baseUrl);
210215

211216
if (missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(remoteFilePath)){
212217
stop (paste("A value must be specified for each of baseUrl, folderPath, fileSet, and remoteFilePath"))
@@ -226,7 +231,7 @@ labkey.webdav.mkDirs <- function(baseUrl=NULL, folderPath, remoteFilePath, fileS
226231
return(TRUE)
227232
}
228233

229-
labkey.webdav.downloadFolder <- function(localBaseDir, baseUrl=NULL, folderPath, remoteFilePath, overwriteFiles=TRUE, mergeFolders=TRUE, fileSet="@files") {
234+
labkey.webdav.downloadFolder <- function(localBaseDir, baseUrl=NULL, folderPath, remoteFilePath, overwriteFiles=TRUE, mergeFolders=TRUE, fileSet="@files", showProgressBar=FALSE) {
230235
if (missing(localBaseDir) || missing(baseUrl) || is.null(baseUrl) || missing(folderPath) || missing(remoteFilePath)){
231236
stop (paste("A value must be specified for each of localBaseDir, baseUrl, folderPath, fileSet, and remoteFilePath"))
232237
}
@@ -257,7 +262,7 @@ labkey.webdav.downloadFolder <- function(localBaseDir, baseUrl=NULL, folderPath,
257262
return(F)
258263
}
259264

260-
labkey.webdav.doDownloadFolder(localDir = localBaseDir, baseUrl = baseUrl, folderPath = folderPath, remoteFilePath = remoteFilePath, overwriteFiles = overwriteFiles, mergeFolders = mergeFolders, fileSet = fileSet)
265+
labkey.webdav.doDownloadFolder(localDir = localBaseDir, baseUrl = baseUrl, folderPath = folderPath, remoteFilePath = remoteFilePath, overwriteFiles = overwriteFiles, mergeFolders = mergeFolders, fileSet = fileSet, showProgressBar = showProgressBar)
261266
}
262267

263268
normalizeFolder <- function(localDir){
@@ -277,7 +282,7 @@ logMessage <- function(msg) {
277282
}
278283
}
279284

280-
labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, remoteFilePath, depth, overwriteFiles=TRUE, mergeFolders=TRUE, fileSet="@files")
285+
labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, remoteFilePath, overwriteFiles=TRUE, mergeFolders=TRUE, fileSet="@files", showProgressBar=FALSE)
281286
{
282287
baseUrl <- normalizeSlash(baseUrl, leading = F, trailing = F)
283288
folderPath <- encodeFolderPath(folderPath);
@@ -312,14 +317,14 @@ labkey.webdav.doDownloadFolder <- function(localDir, baseUrl=NULL, folderPath, r
312317
next
313318
}
314319

315-
labkey.webdav.doDownloadFolder(localDir=localPath, baseUrl=baseUrl, folderPath=folderPath, fileSet=fileSet, remoteFilePath=relativeToRemoteRoot, overwriteFiles=overwriteFiles, mergeFolders=mergeFolders)
320+
labkey.webdav.doDownloadFolder(localDir=localPath, baseUrl=baseUrl, folderPath=folderPath, fileSet=fileSet, remoteFilePath=relativeToRemoteRoot, overwriteFiles=overwriteFiles, mergeFolders=mergeFolders, showProgressBar=showProgressBar)
316321
} else {
317322
url <- paste0(baseUrl, trimLeadingPath(file[["href"]]))
318323

319324
logMessage(paste0("Downloading file: ", relativeToRemoteRoot))
320325
logMessage(paste0("to: ", localPath))
321326

322-
labkey.webdav.getByUrl(url, localPath, overwriteFiles)
327+
labkey.webdav.getByUrl(url, localPath, overwriteFiles, showProgressBar=showProgressBar)
323328
}
324329
}
325330

@@ -341,7 +346,7 @@ prepareDirectory <- function(localPath, overwriteFiles, mergeFolders) {
341346

342347
if (!mergeFolders && overwriteFiles) {
343348
logMessage('deleting existing folder')
344-
unlink(localPath, recursive = T)
349+
unlink(localPath, recursive = TRUE)
345350
}
346351
else if (!mergeFolders && !overwriteFiles) {
347352
logMessage('skipping existing folder')
@@ -354,5 +359,5 @@ prepareDirectory <- function(localPath, overwriteFiles, mergeFolders) {
354359
dir.create(localPath, recursive=TRUE)
355360
}
356361

357-
return(T)
362+
return(TRUE)
358363
}

Rlabkey/man/labkey.webdav.downloadFolder.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ labkey.webdav.downloadFolder(
1212
remoteFilePath,
1313
overwriteFiles=TRUE,
1414
mergeFolders=TRUE,
15-
fileSet='@files'
15+
fileSet='@files',
16+
showProgressBar=FALSE
1617
)
1718
}
1819
\arguments{
@@ -23,6 +24,7 @@ labkey.webdav.downloadFolder(
2324
\item{overwriteFiles}{(optional) if true, any pre-existing file at this location will be overwritten. Defaults to TRUE }
2425
\item{mergeFolders}{(optional) if false, any pre-existing local folders in the target location will be deleted if there is an incoming folder of the same name. If true, these existing folders will be left alone, and remote files downloaded into them. Existing file conflicts will be handled based on the overwriteFiles parameter. Defaults to TRUE }
2526
\item{fileSet}{(optional) the name of file server fileSet, which is typically "@files" (the default value for this argument). In some cases this might be "@pipeline" or "@fileset". }
27+
\item{showProgressBar}{(optional) if true, a progress bar will be shown for all file downloads }
2628
}
2729
\details{
2830
This will recursively download a folder from a LabKey Server using WebDAV. This is essentially a wrapper that recursively calls

Rlabkey/man/labkey.webdav.get.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ labkey.webdav.get(
1111
remoteFilePath,
1212
localFilePath,
1313
overwrite=TRUE,
14-
fileSet='@files'
14+
fileSet='@files',
15+
showProgressBar=FALSE
1516
)
1617
}
1718
\arguments{
@@ -21,6 +22,7 @@ labkey.webdav.get(
2122
\item{localFilePath}{the local filepath where this file will be saved }
2223
\item{overwrite}{(optional) if true, any pre-existing file at this location will be overwritten. Defaults to TRUE }
2324
\item{fileSet}{(optional) the name of file server fileSet, which is typically "@files" (the default value for this argument). In some cases this might be "@pipeline" or "@fileset". }
25+
\item{showProgressBar}{(optional))if true, a progress bar will be shown for all file downloads }
2426
}
2527
\details{
2628
Download a single file from a LabKey Server to the local machine using WebDAV.

docs/build_windows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Click next. There is then an editable preview of the new system path. Leave as is.
1212
* If reinstalling Rtools, make sure there is only one copy of the new entries in the path
1313

14-
* Install [MiKTeX](http://www.miktex.org/download) for Latex support
14+
* Install [MiKTeX](https://miktex.org/download) for Latex support
1515
* After installation, open the MiKTeX package manager and install these additional packages:
1616
* fancyvrb
1717
* inconsolata

0 commit comments

Comments
 (0)