Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Commit f93665e

Browse files
committed
Create update_database for updating metadata
1 parent 09c8d91 commit f93665e

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ Suggests:
106106
knitr,
107107
testthat,
108108
tidySingleCellExperiment,
109-
ggplot2
109+
ggplot2,
110+
basilisk,
111+
arrow
110112
Biarch: true
111113
biocViews:
112114
AssayDomain,

R/dev.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Utility scripts for development purposes, that are not exported to users
2+
3+
#' Update the metadata database in nectar using a newly created data frame
4+
#' @param metadata The data frame to upload
5+
#' @param version The version for the new metadata as a character scalar, e.g.
6+
#' "0.2.3"
7+
#' @param credential_id The OpenStack application credential ID as a character
8+
#' scalar. This is optional because you can alternatively source a
9+
#' `-openrc.sh` file instead of providing it here.
10+
#' @param credential_id The OpenStack application credential secret as a
11+
#' character scalar
12+
#' @noRd
13+
update_database = function(metadata, version, credential_id = NULL, credential_secret = NULL){
14+
# These are optional dev packages
15+
rlang::check_installed(c("arrow", "glue", "basilisk"))
16+
17+
# Create parquet
18+
dir <- tempdir()
19+
parquet_name <- glue::glue("metadata.{version}.parquet")
20+
parquet_path <- file.path(dir, parquet_name)
21+
arrow::write_parquet(metadata, sink=parquet_path)
22+
23+
# Create the basilisk environment
24+
swift_env <- basilisk::BasiliskEnvironment(
25+
envname="swift-nectar-upload",
26+
pkgname=packageName(),
27+
packages=c("python-swiftclient==4.2.0", "python-keystoneclient==5.1.0", "python==3.10.9")
28+
)
29+
proc <- basilisk::basiliskStart(swift_env)
30+
31+
# Build the CLI args
32+
if (!is.null(credential_id) && !is.null(credential_secret)){
33+
auth <- c(
34+
"--os-auth-type",
35+
"v3applicationcredential",
36+
"--os-application-credential-id",
37+
credential_id,
38+
"--os-application-credential-secret",
39+
credential_secret
40+
)
41+
}
42+
else {
43+
auth <- character()
44+
}
45+
args = c(
46+
"-m",
47+
"swiftclient.shell",
48+
"--os-auth-url",
49+
"https://keystone.rc.nectar.org.au:5000/v3/",
50+
"--os-project-id",
51+
"06d6e008e3e642da99d806ba3ea629c5",
52+
auth,
53+
"upload",
54+
"metadata",
55+
parquet_path,
56+
"--object-name",
57+
parquet_name
58+
)
59+
60+
# Perform the upload
61+
system2(reticulate::py_exe(), args=args)
62+
basilisk::basiliskStop(proc)
63+
}

0 commit comments

Comments
 (0)