Skip to content
Snippets Groups Projects
Commit b7bd5ec0 authored by LouisGendron's avatar LouisGendron
Browse files

structured dwnl file & annotations like pyriricdata

parent dcb72137
No related branches found
Tags 0.76.3
1 merge request!4Draft: Resolve "Restructure checks and download like pyiricdata"
......@@ -77,67 +77,67 @@ setMethod(
#Download file from db_id or slug_id
setGeneric(
name="DL_file",
def=function(object, session, file_id, path_out){
standardGeneric("DL_file")
name="dwnl_file_content",
def=function(object, session, folder_out, filename){
standardGeneric("dwnl_file_content")
}
)
setMethod(
f="DL_file",
f="dwnl_file_content",
signature="IRICData",
definition=function(object, session, file_id, path_out) {
definition=function(object, session, folder_out='', filename='') {
# create directory output
dir.create(path_out, showWarnings = FALSE)
resp = rvest::jump_to(session, paste(object@url, 'secure/datafiles/download', file_id, sep='/'))
file_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
file_name = unlist(strsplit(file_name, "UTF-8''"))[2]
file_out = file.path(path_out, file_name)
cat(paste('Downloading',file_name,'\n'))
dir.create(folder_out, showWarnings = FALSE)
resp = rvest::jump_to(session, paste(object@url, 'secure/datafiles/download', filename, sep='/'))
datafile_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
datafile_name = unlist(strsplit(datafile_name, "UTF-8''"))[2]
file_out = file.path(folder_out, datafile_name)
cat(paste('Downloading', datafile_name,'\n'))
writeBin(resp$response$content, file_out)
}
)
#Download file annotation as JSON from db_id or slug_id
setGeneric(
name="DL_file_annotation",
def=function(object, session, file_id, path_out){
standardGeneric("DL_file_annotation")
name="dwnl_file_annotation",
def=function(object, session, folder_out, filename){
standardGeneric("dwnl_file_annotation")
}
)
setMethod(
f="DL_file_annotation",
f="dwnl_file_annotation",
signature="IRICData",
definition=function(object, session, file_id, path_out) {
# create directory output
dir.create(path_out, showWarnings = FALSE)
annotations = get_file_annotation(object, session, file_id)
file_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
file_name = unlist(strsplit(file_name, "UTF-8''"))[2]
file_out = file.path(path_out, file_name)
cat(paste('Downloading',file_name,'\n'))
definition=function(object, session, folder_out='', filename='') {
dir.create(folder_out, showWarnings = FALSE)
annotations = get_file_annotation(object, session, filename)
datafile_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
datafile_name = unlist(strsplit(datafile_name, "UTF-8''"))[2]
file_out = file.path(folder_out, datafile_name)
cat(paste('Downloading', datafile_name, '\n'))
writeBin(annotations, file_out)
}
)
#Download an entire dataset
setGeneric(
name="DL_dataset",
def=function(object, session, id_dataset, path_out){
standardGeneric("DL_dataset")
name="dwnl_dataset",
def=function(object, session, folder_out, datasetname){
standardGeneric("dwnl_dataset")
}
)
setMethod(
f="DL_dataset",
f="dwnl_dataset",
signature="IRICData",
definition=function(object, session, id_dataset, path_out) {
# create directory output
#Get all files of a dataset
resp = rvest::jump_to(session, paste(object@url,"/secure/dataset/", id_dataset, "/file-list", sep=""))
definition=function(object, session, folder_out='', datasetname='') {
dir.create(folder_out, showWarnings = FALSE)
resp = rvest::jump_to(session, paste(object@url,"/secure/dataset/", datasetname, "/file-list", sep=""))
files_to_DL = unlist(strsplit(rawToChar(resp$response$content), "\n"))
files_id = unique(unlist(lapply(files_to_DL, function(x) tail(unlist(strsplit(x,'/')), 1))))
#DL all file in path_out
if(folder_out !=""){ folder_out=file.path(folder_out, datasetname) }
else{ folder_out=datasetname }
for (id_ in files_id) {
DL_file(object, session, id_, path_out)
dwnl_file_content(object, session, folder_out, id_)
dwnl_file_annotation(object, session, folder_out, id_)
}
}
)
......@@ -283,13 +283,13 @@ setMethod(
#Return a data.table of file_name, file_id and hash for every files in dataset
setGeneric(
name='get_dataset_hash',
name='get_dataset_filelist',
def=function(object, session, dataset_id){
standardGeneric('get_dataset_hash')
standardGeneric('get_dataset_filelist')
}
)
setMethod(
f='get_dataset_hash',
f='get_dataset_filelist',
signature='IRICData',
definition=function(object, session, dataset_id){
ds_details <- data.table()
......@@ -307,7 +307,8 @@ setMethod(
ds_details <- rbind(ds_details,
data.table(file_name = metas[[ix]]$filename,
file_id = files_id[[ix]],
hash = metas[[ix]]$hash))
file_hash = metas[[ix]]$hash,
file_slug = metas[[ix]]$iric_data_id))
}
}
return(ds_details)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment