]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/exec/update_cache
e9bb8900f5e54a3ce41e39283d81d132657ce4a8
[cran2deb.git] / trunk / exec / update_cache
1 #!/usr/bin/r -t
2
3 # Note: everything in the case needs to be system-independent!
4 library(cran2deb)
5 library(ctv)
6
7 #argv <- commandArgs()
8 #argv <- argv[-(1:match("--args", argv))]
9
10 #mirror <- 'http://cran.uk.r-project.org/'
11
12 available <- NULL
13 ctv.available <- NULL
14
15 mirrors <- NULL
16 mirrors <- c(mirrors,CRAN='http://cran.r-project.org')
17 #mirrors <- c(mirrors,BioC='http://www.bioconductor.org/packages/2.2')
18 mirrors <- c(mirrors,BioC='http://www.bioconductor.org/packages/2.7')
19
20 verbose<-TRUE
21 debug<-FALSE
22
23 for (mirror.name in names(mirrors)) {
24         mirror.url<-mirrors[mirror.name]
25         message(paste("Updating list of available R packages from ",mirror.name," [",mirror.url,"].\n",sep=""))
26         packages.retrieved <- NULL
27         if ("CRAN" == mirror.name) {
28                 packages.retrieved <- available.packages(contrib.url(mirror.url))
29         } else if ("BioC" == mirror.name) {
30                 repos <- c(
31                         "bioc"
32                         ,"data/annotation"
33                         ,"data/experiment"
34                         ,"extra"
35                 )
36                 for (s in repos) {
37                         packages.retrieved <- rbind(
38                                 packages.retrieved,
39                                 available.packages(contrib.url(paste(mirror.url,s,sep="/")))
40                         )
41                 }
42         } else {
43                 packages.retrieved <- available.packages(mirror.url)
44         }
45         if (verbose) message(paste("Retrieved ",nrow(packages.retrieved)," package descriptions.\n",sep=""))
46         available <- rbind(available, packages.retrieved)
47         message('updating list of available R task views...')
48         ctv.available <- rbind(ctv.available,available.views(repo=mirror.url))
49 }
50
51 #available <- rbind(available,available.packages(contrib.url('http://www.bioconductor.org/')))
52
53 dupes <- duplicated(rownames(available), fromLast=T)
54 if (sum(dupes)>0) {
55         if (verbose) cat("Found ",sum(dupes)," packages with the same name in different distributions. Those are now removed.\n",sep="")
56         available <- available[!dupes,,drop=F]
57 } else {
58         if (length(mirrors)>1) cat("All packages have different names.")
59 }
60
61 # TODO: Check if not better a dedicated tool should be called for this
62 message('updating list of base R packages...')
63 base_pkgs <- readLines(pipe(paste('sudo pbuilder --execute --override-config --configfile'
64                                  ,shQuote(pbuilder_config),'-- /usr/bin/R --vanilla 2>&1 >/dev/null <'
65                                  ,shQuote(file.path(root,'exec/get_base_pkgs'))
66                                  ,'| grep -v ^W:')))
67
68 if (any(grep("^E:",base_pkgs,value=FALSE))) {
69         cat("Cannot continue, the following error occurred:\n")
70         cat(paste(grep("^E:",base_pkgs,value=TRUE),collapse="\n"))
71         cat("\n")
72         q(save="no")
73 }
74
75
76 if (debug) {
77         cat("The following base packages were determined:\n")
78         print(base_pkgs)
79 }
80
81 message('updating list of existing Debian packages...')
82 debian_pkgs <- readLines(pipe('apt-cache rdepends r-base-core | sed -e "/^  r-cran/{s/^[[:space:]]*r/r/;p}" -e d | sort -u'))
83
84 if (any(grep("^E:",debian_pkgs,value=FALSE))) {
85         cat("Cannot continue, the following error occurred:\n")
86         cat(paste(grep("^E:",debian_pkgs,value=TRUE),collapse="\n"))
87         cat("\n")
88         q(save="no")
89 }
90
91 if (verbose) {
92         cat("The following packages were found to be available:\n")
93         print(debian_pkgs)
94 }
95
96 save(debian_pkgs, base_pkgs, available, ctv.available, file=file.path(cache_root,'cache.rda'),eval.promises=T)
97
98 message('synchronising database...')
99 db_update_package_versions()