Skip to content

Commit e2835d8

Browse files
committed
enable log file creation
1 parent ffefb19 commit e2835d8

File tree

4 files changed

+80
-54
lines changed

4 files changed

+80
-54
lines changed

gitlist/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ COPY --from=builder /gitlist /var/www/html/browse
5151
COPY --from=builder /bioconductor /var/www/html/browse/themes/bioconductor
5252
RUN mkdir /var/www/html/browse/cache
5353

54-
RUN ln -s /var/git/packages.json /var/www/html/browse/
54+
RUN ln -s /var/git/packages.json /var/www/html/browse/ && \
55+
ln -s /var/git/status.log /var/www/html/browse/
5556

5657
## map www-data to the same UID as Alpine uses
5758
## then set permissions

mirror-updater/check_rss_feed.R

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
args <- commandArgs(trailingOnly=TRUE)
22

3-
4-
53
#######################
64
## Argument handling ##
75
#######################
@@ -13,6 +11,8 @@ if(length(args) >= 1 && ("--clean" %in% args)) {
1311
CLEAN <- FALSE
1412
}
1513

14+
#CLEAN <- TRUE
15+
1616
## process argument specifying number of packages to initialise with
1717
if(length(args) >= 1 && any(grepl("--npkgs=[0-9]*", args))) {
1818
arg <- args[grepl("--npkgs=[0-9]*", args)]
@@ -59,6 +59,15 @@ suppressPackageStartupMessages(library(tidyRSS))
5959
suppressPackageStartupMessages(library(gert))
6060
suppressPackageStartupMessages(library(jsonlite))
6161

62+
#########################
63+
## Create new log file ##
64+
#########################
65+
lock_file <- file.path(REPO_DIR, "lock")
66+
log_file <- file.path(REPO_DIR, "status.log")
67+
if(file.exists(log_file) && !file.exists(lock_file)) {
68+
unlink(log_file)
69+
}
70+
6271
##############################################
6372
## Find packages on server and local mirror ##
6473
##############################################
@@ -71,16 +80,21 @@ removePackages(manifest, existing_pkgs, index_dir = INDEX_DIR)
7180
#########################################################
7281
if(length(existing_pkgs) == 0 || CLEAN) {
7382
cleanDir(repo_dir = REPO_DIR, index_dir = INDEX_DIR)
83+
createUnderConstruction(repo_dir = REPO_DIR)
7484
createLockFile(repo_dir = REPO_DIR)
7585
updated_pkgs <- initialiseRepositories(repo_dir = REPO_DIR, manifest = manifest)
7686
} else {
7787
## Uncomment these lines to force deletion of the lock file
78-
#lock_file <- file.path(REPO_DIR, "lock")
79-
#if(file.exists(lock_file)) { file.remove(lock_file) }
88+
# lock_file <- file.path(REPO_DIR, "lock")
89+
# if(file.exists(lock_file)) { file.remove(lock_file) }
8090
#UPDATE_ALL <- TRUE
8191
createLockFile(repo_dir = REPO_DIR)
92+
93+
#unlink(x = file.path(REPO_DIR, c("nnSVG", "scp")), recursive = TRUE)
94+
8295
updated_pkgs <- updateRepositories(repo_dir = REPO_DIR, manifest = manifest,
83-
update_all = UPDATE_ALL)
96+
update_all = UPDATE_ALL)
97+
8498
}
8599

86100
##############################################################################

mirror-updater/git_update_functions.R

+34-39
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ clonePackage <- function(pkg_name, repo_dir) {
7575
if(!dir.exists(out_path)) {
7676
printMessage("Cloning repository... ", 2, appendLF = FALSE)
7777
gert::git_clone(paste0("https://git.bioconductor.org/packages/", pkg_name),
78-
path = file.path(repo_dir, pkg_name),
78+
path = out_path,
7979
verbose = FALSE)
80-
message("done")
80+
printMessage(" done", 0, timestamp = FALSE)
8181
} else {
82-
message(" Directory already exists")
82+
printMessage(" Directory already exists", 0, timestamp = FALSE)
8383
}
8484
}
8585

@@ -103,16 +103,10 @@ checkoutBranches <- function(pkg_name, repo_dir) {
103103
gert::git_branch_checkout(branch = basename(b), repo = repo)
104104
)
105105
}
106-
## finish with the devel/master branch checkout
107-
if(any(grepl("devel", branches$name))) {
108-
suppressMessages(
109-
gert::git_branch_checkout(branch = "devel", repo = repo)
110-
)
111-
} else {
112-
suppressMessages(
113-
gert::git_branch_checkout(branch = "master", repo = repo)
114-
)
115-
}
106+
## finish with the devel branch checkout
107+
suppressMessages(
108+
gert::git_branch_checkout(branch = "devel", repo = repo)
109+
)
116110
printMessage("done", 2)
117111
}
118112
}
@@ -137,16 +131,11 @@ updateBranches <- function(pkg_name, repo_dir) {
137131
gert::git_pull(repo = repo, verbose = FALSE)
138132
)
139133
}
140-
## finish with the devel/master branch checkout
141-
if(any(grepl("devel", branches$name))) {
142-
suppressMessages(
143-
gert::git_branch_checkout(branch = "devel", repo = repo)
144-
)
145-
} else {
146-
suppressMessages(
147-
gert::git_branch_checkout(branch = "master", repo = repo)
148-
)
149-
}
134+
## finish with the devel branch checkout
135+
suppressMessages(
136+
gert::git_branch_checkout(branch = "devel", repo = repo)
137+
)
138+
150139
printMessage("done", 2)
151140
}
152141

@@ -158,23 +147,15 @@ processMostRecentCommit <- function(pkg_name, repo_dir) {
158147
stop("directory doesn't exist")
159148
}
160149

161-
## sort branches by commit time. Sometimes RELEASE and master will be identical
150+
## sort branches by commit time. Sometimes RELEASE and devel will be identical
162151
## Sorting on branch isn't reliable, so we resolve this below
163-
top3commits <- gert::git_branch_list(local = TRUE, repo = repo) %>%
152+
top2commits <- gert::git_branch_list(local = TRUE, repo = repo) %>%
153+
filter(grepl("(RELEASE_[1-9]_[0-9]{1,2}$|devel)", name)) %>%
164154
arrange(desc(updated)) %>%
165-
slice(1:3)
166-
167-
## remove the master branch from this test if devel exists
168-
if("devel" %in% top3commits$name) {
169-
top2commits <- top3commits %>% filter(name != "master")
170-
devel_branch <- "devel"
171-
} else {
172-
top2commits <- top3commits %>% slice(1:2)
173-
devel_branch <- "master"
174-
}
155+
slice(1:2)
175156

176157
if(identical(top2commits$updated[1], top2commits$updated[2])) {
177-
most_recent_commit <- filter(top2commits, name == devel_branch)
158+
most_recent_commit <- filter(top2commits, name == "devel")
178159
} else {
179160
most_recent_commit <- slice(top2commits, 1)
180161
}
@@ -201,6 +182,19 @@ processMostRecentCommit <- function(pkg_name, repo_dir) {
201182
return(json_content)
202183
}
203184

185+
## create a placeholder table when the site is being updated
186+
createUnderConstruction <- function(repo_dir) {
187+
188+
json_content <- c(
189+
"The code browser is undergoing maintenance",
190+
"It will return soon"
191+
)
192+
193+
message <- toJSON(list(data = list(json_content)), pretty = TRUE)
194+
195+
writeLines(message, con = file.path(repo_dir, "packages.json"))
196+
}
197+
204198

205199
initialiseRepositories <- function(repo_dir, manifest, n_pkgs) {
206200

@@ -257,7 +251,7 @@ updateCommitMessages <- function(repo_dir, manifest, pkgs) {
257251
## munging to get json in the format for DataTable HTML
258252
json_pkg_list <- toJSON(list(data = do.call(rbind, commit_messages)), pretty = TRUE)
259253
writeLines(json_pkg_list, con = file.path(repo_dir, "packages.json"))
260-
message("done")
254+
printMessage(" done", 0, timestamp = FALSE)
261255

262256
}
263257

@@ -298,7 +292,7 @@ updateRepositories <- function(repo_dir, manifest, update_all = FALSE) {
298292
clonePackage(pkg, repo_dir = repo_dir)
299293
},
300294
error = function(cond) {
301-
message("Failed!")
295+
printMessage("Failed to clone package!", 0, timestamp = FALSE )
302296
return(TRUE)
303297
})
304298
if(isTRUE(skip)) {
@@ -311,7 +305,8 @@ updateRepositories <- function(repo_dir, manifest, update_all = FALSE) {
311305
updateBranches(pkg, repo_dir = repo_dir)
312306
},
313307
error = function(cond) {
314-
printMessage("Failed!", 4)
308+
printMessage(sprintf("Failed to update branches! Message: %s", cond),
309+
0, timestamp = TRUE)
315310
return(TRUE)
316311
})
317312
if(isTRUE(skip)) { pkgs <- setdiff(pkgs, pkg) }

mirror-updater/utils.R

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
## Print log with date and message
2-
printMessage <- function(msg, n = 0, appendLF = TRUE) {
3-
message("[ ", Sys.time(), " ] ", rep(" ", n), msg, appendLF = appendLF)
2+
printMessage <- function(msg, n = 0, appendLF = TRUE, timestamp = TRUE) {
3+
4+
REPO_DIR <- Sys.getenv("GIT_REPOS_DIR")
5+
log_file <- file.path(REPO_DIR, "status.log")
6+
7+
text <- sprintf("%s%s%s%s",
8+
if(timestamp) timestamp(prefix = "[ ", suffix = " ] ", quiet = TRUE) else "",
9+
strrep(" ", n),
10+
msg,
11+
if(appendLF) "\n" else "")
12+
message(text, appendLF = FALSE)
13+
cat(text, file = log_file, append = TRUE)
414
}
515

616
## Get a vector containing the names of all packages currently part of
@@ -27,7 +37,7 @@ getManifest <- function(repo_dir = tempdir(), n_pkgs, extra_pkgs = NULL) {
2737
if(is.finite(n_pkgs)) {
2838
manifest <- manifest[seq_len(n_pkgs)]
2939
}
30-
message("done")
40+
printMessage(" done", 0, timestamp = FALSE)
3141
return(manifest)
3242
}
3343

@@ -61,26 +71,32 @@ createLockFile <- function(repo_dir) {
6171
file.create(lock_file)
6272
}
6373

64-
cleanDir <- function(repo_dir, index_dir) {
74+
cleanDir <- function(repo_dir, index_dir, exclude_log = TRUE) {
6575
existing_pkgs <- list.dirs(repo_dir, recursive = FALSE)
6676
if(length(existing_pkgs)) {
6777
printMessage("Deleting existing packages... ", 0, appendLF = FALSE)
6878
unlink(existing_pkgs, recursive = TRUE)
69-
message("done")
79+
printMessage(" done", 0, timestamp = FALSE)
7080
}
7181

7282
existing_files <- list.files(repo_dir, full.names = TRUE)
83+
84+
if(exclude_log) {
85+
idx <- grep("status.log", existing_files)
86+
if(length(idx) > 0) { existing_files <- existing_files[-idx] }
87+
}
88+
7389
if(length(existing_files)) {
7490
printMessage("Deleting existing files... ", 0, appendLF = FALSE)
7591
file.remove(existing_files)
76-
message("done")
92+
printMessage(" done", 0, timestamp = FALSE)
7793
}
7894

7995
index_files <- list.files(index_dir, full.names = TRUE)
8096
if(length(index_files)) {
8197
printMessage("Deleting index files... ", 0, appendLF = FALSE)
8298
file.remove(index_files)
83-
message("done")
99+
printMessage(" done", 0, timestamp = FALSE)
84100
}
85101
}
86102

@@ -101,9 +117,9 @@ cleanUp <- function(repo_dir) {
101117
}
102118
invisible(file.rename(from = tmp_hash, to = old_hash))
103119
}
104-
message("done")
120+
printMessage(" done", 0, timestamp = FALSE)
105121

106122
printMessage("Removing lock file... ", 0, appendLF = FALSE)
107123
file.remove(lock_file)
108-
message("done")
124+
printMessage(" done", 0, timestamp = FALSE)
109125
}

0 commit comments

Comments
 (0)