-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsite.R
129 lines (98 loc) · 3.95 KB
/
website.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
############## host on github ################
library(GetoptLong)
library(gh)
username = "simplifyEnrichment"
token =
delete_repo = function(repo, dir, where = c("remote", "local")) {
qqcat("delete repo @{repo}\n")
if("remote" %in% where) {
gh("DELETE /repos/:owner/:repo", owner = username, repo = repo, .token = token)
}
if("local" %in% where) {
owd = getwd()
on.exit(setwd(owd))
setwd(dir)
if(file.exists(".git")) {
unlink(".git", recursive = TRUE, force = TRUE)
}
}
}
create_repo = function(repo, dir, ignore = c("rds", "rds/", "^.*", "Rplots.pdf"),
where = c("remote", "local")) {
all_repos = gh(qq("GET /users/@{username}/repos"))
all_repos = vapply(all_repos, "[[", "", "name")
if(repo %in% all_repos) {
delete_repo(repo, dir)
} else {
delete_repo(repo, dir, where = "local")
}
qqcat("creating repo for @{repo}\n")
if("remote" %in% where) {
new_repo = gh("POST /user/repos", name = repo, owner = username, .token = token)
}
if("local" %in% where) {
owd = getwd()
on.exit(setwd(owd))
setwd(dir)
system("git init")
cat(c(ignore, "core*"), sep = "\n", file = ".gitignore")
system("git add .gitignore")
system("git commit -m 'add .gitignore'")
if(!file.exists("readme.md")) {
qqcat("figures for @{repo}", file = "readme.md")
system("git add readme.md")
system("git commit -m 'add readme.md'")
}
branch = system("git branch", intern = TRUE)
if(!any(grepl("gh-pages", branch))) {
system("git branch gh-pages")
}
}
}
update_repo = function(repo, dir) {
qqcat("------------ upload for @{repo} -------------\n")
owd = getwd()
on.exit(setwd(owd))
setwd(dir)
system("git add --all")
system(qq("git commit -m 'add files for @{repo}'"))
system(qq("git push https://@{username}:@{token}@github.com/@{username}/@{repo}.git master"))
system("git checkout gh-pages")
system("git merge master")
system(qq("git push https://@{username}:@{token}@github.com/@{username}/@{repo}.git gh-pages"))
system("git checkout master")
}
sub_dirs = function(dir, pattern = NULL) {
owd = getwd()
on.exit(setwd(owd))
setwd(dir)
files = list.files(pattern = pattern)
files[file.info(files)$isdir]
}
dir = sub_dirs("/omics/groups/OE0246/internal/guz/simplifyGO_test/examples")
for(repo in dir) {
try(delete_repo(repo, qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/examples/@{repo}")))
}
for(repo in dir) {
create_repo(repo, qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/examples/@{repo}"))
update_repo(repo, qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/examples/@{repo}"))
}
################### similarity comparisons ###################
dir = sub_dirs("/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity")
dir = setdiff(dir, "rds")
for(repo in dir) {
delete_repo(qq("cmp_sim_@{repo}"), qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity/@{repo}"))
}
for(repo in dir) {
create_repo(qq("cmp_sim_@{repo}"), qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity/@{repo}"))
update_repo(qq("cmp_sim_@{repo}"), qq("/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity/@{repo}"))
}
################# test partition methods ###########
create_repo("test_partition_methods", "/omics/groups/OE0246/internal/guz/simplifyGO_test/test_partition_methods")
update_repo("test_partition_methods", "/omics/groups/OE0246/internal/guz/simplifyGO_test/test_partition_methods")
create_repo("compare_similarity", "/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity",
ignore = sub_dirs("/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity", pattern = "EBI|random|rds"))
update_repo("compare_similarity", "/omics/groups/OE0246/internal/guz/simplifyGO_test/compare_similarity")
create_repo("examples", "/omics/groups/OE0246/internal/guz/simplifyGO_test/examples",
ignore = sub_dirs("/omics/groups/OE0246/internal/guz/simplifyGO_test/examples"))
update_repo("examples", "/omics/groups/OE0246/internal/guz/simplifyGO_test/examples")