Commit 9f60b35d authored by Julien Veyssier's avatar Julien Veyssier
Browse files

first add

parents
<?php
// base URL that prefixes start.php, view.php
$base_url = "http://my.server.org/r-package-checker/";
//$email_addr = "Emmanuel.Paradis@univ-montp2.fr";
$email_addr = "your@email.address";
// path to rtest bash script
$rtest_location = "/home/user/rcheck/rtest.sh";
// where you want to install packages
$rlib_location = "/home/user/Rlib_test";
// path to xvfb-run
$xvfbrun_location = "/home/user/xvfb-run";
// directory containing all results directories
$all_results_dir = "/home/user/rcheck_results/";
// name of the package to test
$package_to_test = "mypkg";
// repository to use to get last version of the package to test
$package_to_test_repo = "http://my.pkg.repo.org/";
// number of threads used for parallel checking
$nb_threads = 4;
?>
old <- getOption("defaultPackages"); r <- getOption("repos")
r["CRAN"] <- "http://cran.irsn.fr/"
options(defaultPackages = c(old, "MASS"), repos = r)
require("tools")
reverse_dependencies_with_maintainers <-
function(packages, which = c("Depends", "Imports", "LinkingTo"),
recursive = FALSE)
{
contrib.url(getOption("repos")["CRAN"], "source") # trigger chooseCRANmirror() if required
description <- sprintf("%s/web/packages/packages.rds",
getOption("repos")["CRAN"])
con <- if(substring(description, 1L, 7L) == "file://")
file(description, "rb")
else
url(description, "rb")
on.exit(close(con))
db <- readRDS(gzcon(con))
rownames(db) <- NULL
rdepends <- package_dependencies(packages, db, which,
recursive = recursive,
reverse = TRUE)
rdepends <- sort(unique(unlist(rdepends)))
pos <- match(rdepends, db[, "Package"], nomatch = 0L)
db[pos, c("Package", "Version", "Maintainer")]
}
Sys.setenv(http_proxy = "")
a <- reverse_dependencies_with_maintainers("ape", which = c("Depends", "Imports", "Suggests", "LinkingTo"))
a <- a[order(a[,1]),]
ff <- file("depends.txt", open = "w")
cat( paste(sep=",",a[,1],sub("\n","",a[,2]),sub("\n"," ",a[,3]), collapse = "\n"), "\n\n", file=ff)
close(ff)
#!/bin/bash
DEFAULT_REPOSITORY="http://cran.irsn.fr/"
XVFBRUN_PATH=xvfb-run
if [ -z ${JAVA_HOME+x} ] || ! [ -d $JAVA_HOME ]; then
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre"
fi
export PATH=$PATH:$JAVA_HOME/bin
# function that takes a destination directory as argument and produces
# an HTML report as index.html into it
function generate_html_report(){
local dir=$1
local dest_html=$1/index.html
echo "<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='content-type'>
</head>
<body>
<table width='100%'>
" > $dest_html
# show install log of package to test
if [ -f $dir"/install_pkg.Rout" ]; then
if [ -f $dir"/install_pkg_ok" ]; then
local version=`cat $dir"/pkg.version"`
local status="ok, version $version"
local color="#4EE877"
else
if [ -f $dir"/install_pkg_problem" ]; then
local status="problem"
local color="red"
else
local status="running"
local color="yellow"
fi
fi
echo "<tr style='background-color:$color' class='title'><td>$PACKAGE_TO_TEST INSTALL PROCESS</td>" >> $dest_html
echo "<td>$status</td></tr>" >> $dest_html
echo "<tr class='retractable' id='update'><td colspan=3><textarea cols='240' rows='30'>`cat $dir/install_pkg.Rout`</textarea></td></tr>" >> $dest_html
fi
# show update log
if [ -f $dir/update.Rout ]; then
if [ -f $dir/update_ok ]; then
local status="ok"
local color="#4EE877"
else
if [ -f $dir/update_problem ]; then
local status="problem"
local color="red"
else
local status="running"
local color="yellow"
fi
fi
local nlines=`cat $dir/update.Rout | wc -l`
echo "<tr style='background-color:$color' class='title'><td>UPDATE PROCESS</td>" >> $dest_html
echo "<td>$status ($nlines lines)</td></tr>" >> $dest_html
echo "<tr class='retractable' id='update'><td colspan=3><textarea cols='200' rows='30'>`cat $dir/update.Rout`</textarea></td></tr>" >> $dest_html
fi
# INSTALL, for all the install R scripts output files
if [[ "`ls $dir | grep "_install.Rout" | wc -l`" != "0" ]]; then
for elem in `ls $dir/*_install.Rout`; do
local package=`basename $elem`
local package_name=${package/_install.Rout/}
# if the installation went well
if [ -f $dir"/"$package_name"_install_ok" ]; then
local status="ok"
local color="#4EE877"
# if the installation failed
else
if [ -f $dir"/"$package_name"_install_problem" ]; then
local status="problem"
local color="red"
else
local status="running"
local color="yellow"
fi
fi
local log=`cat $dir"/"$package_name"_install.Rout"`
local nlines=`cat $dir"/"$package_name"_install.Rout" | wc -l`
echo "<tr style='background-color:$color' class='title'><td>INSTALL $package_name</td>" >> $dest_html
echo "<td>$status ($nlines lines)</td></tr>" >> $dest_html
echo "<tr class='retractable' id='$package_name'><td colspan=3><textarea cols='200' rows='30'>$log</textarea></td></tr>" >> $dest_html
done
fi
# CHECK, for all the downloaded archives
if [[ "`ls $dir | grep ".tar.gz" | wc -l`" != "0" ]]; then
for elem in `ls $dir/*.tar.gz`; do
local baselem=`basename $elem`
local baselem=${baselem/.tar.gz/}
# split string into array
local package=(`echo "$baselem" | tr "_" "\n"`)
#IFS='_' read -ra package <<< "$baselem"
local package_name=${package[0]}
local package_version=${package[1]}
# si CHECKOK
if [ -f $dir"/"$package_name".CHECKOK" ]; then
local status="ok"
local color="#4EE877"
# si CHECKPROBLEM
else
if [ -f $dir"/"$package_name".CHECKPROBLEM" ]; then
local status="problem"
local color="red"
else
local status="running"
local color="yellow"
fi
fi
local log=`cat $dir"/"$package_name".Rcheck/00check.log"`
local nlines=`cat $dir"/"$package_name".Rcheck/00check.log" | wc -l`
echo "<tr style='background-color:$color' class='title'><td>CHECK $package_name V $package_version</td>" >> $dest_html
echo "<td>$status ($nlines lines)</td></tr>" >> $dest_html
echo "<tr class='retractable' id='$package_name'><td colspan=3><textarea cols='200' rows='30'>$log</textarea></td></tr>" >> $dest_html
done
fi
echo "</table>" >> $dest_html
echo '
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script>
$( document ).ready(function() {
$(".retractable").each(function(){
$(this).hide();
});
$(".title").each(function(){
$(this).click(function(){
if (! $(this).next().is(":visible")){
$(this).next().show();
}
else{
$(this).next().hide();
}
});
});
$("tr").hover(function() {
$(this).css("cursor","pointer");
});
});
</script>
</body>
</html>
' >> $dest_html
}
############### PRINTING FUNCTIONS ###################
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtpur=$(tput setaf 5) # Purple
txtrst=$(tput sgr0) # Text reset.
# all of those functions avoid printing colors and right aligned text if the
# output ou rtest was redirected to a file or a pipe
# print left in purple and does NOT put the end-of-line char
function printLeftPurple(){
if [[ -t 1 ]]; then
columns=$(tput cols)
col1="100"
printf "${txtpur}%-*s" "$col1" "$1"
else
printf "%-*s" "$col1" "$1"
fi
export LAST_LENGTH=${#1}
}
# print right in green and DOES put the end-of-line char
function printRightGreen(){
if [[ -t 1 ]]; then
columns=$(tput cols)
col1="100"
let "col2 = $columns - $col1"
printf "${txtgrn}%*s${txtrst}\n" "$col2" "$1"
else
let "place = 120 - $LAST_LENGTH"
printf "%*s\n" "$place" "$1"
fi
}
# print right in red and DOES put the end-of-line char
function printRightRed(){
if [[ -t 1 ]]; then
columns=$(tput cols)
col1="100"
let "col2 = $columns - $col1"
printf "${txtred}%*s${txtrst}\n" "$col2" "$1"
else
let "place = 120 - $LAST_LENGTH"
printf "%*s\n" "$place" "$1"
fi
}
function printUsage(){
echo "`basename $0` is a tool to test that a R package (PACKAGE_TO_TEST) does not break packages that depend on it by running 'R CMD check' for each of them.
usage :
$0 PACKAGE_TO_TEST [-l|--libuser R_USER_LIB_VALUE] [-d|--dest DESTINATION_DIRECTORY] [-m|--mail MAIL_TO] [-u|--urlresult URL] [-r|--repo PACKAGE_TO_TEST_REPO] [-x | --xvfb XVFB-RUN PATH] [-n | --nbcores NBCORES] [-s | --skipinstall] [-h | --html]
PACKAGE_TO_TEST : package to test
-r | --repo PACKAGE_TO_TEST_REPO : repository of package you want to test (DEFAULT : R-CRAN)
-l | --libuser R_LIBS_USER : directory where packages depending on PACKAGE_TO_TEST are going to be installed (DEFAULT : R will choose it)
This directory can be used several times for several tests. Using same directory several times will save time.
This directory can exist or not. If not, it will be created
-d | --dest DESTINATION_DIRECTORY : result directory where HTML result and test files are produced (DEFAULT : ./check_PKGNAME_DATE)
-m | --mail MAIL_TO : email address for real time user information (DEFAULT : NO MAIL WILL BE SENT)
-u | --urlresult URL : if -m option was set, this http link to test results will be sent instead of a file path (DEFAULT : destination directory absolute path)
-x | --xvfb PATH : Specific path to xvfb-run script (DEFAULT : 'xvfb-run')
-n | --nbcores NBCORES : Number of cores for parallel executions of installations (Ncpu parameter) and number of simultaneous checks (DEFAULT : 1)
-s | --skipinstall : flag to skip the packages update/installation
-h | --html : generate html report in DESTINATION_DIRECTORY/index.html . Will download jquery in destination directory
Don't forget to set JAVA_HOME if some dependencies need java, which is quite probable.
"
}
ARGS=$(getopt -o r:d:m:l:x:n:shu: -l "repo:mail:libuser:dest:xvfb:nbcores:skipinstall,html,urlresult:" -n "$0" -- "$@");
#Bad arguments
if [ $? -ne 0 ] || [ $# -eq 0 ];
then
printUsage
exit
fi
REPOSITORYFLAG=0
MAILTOFLAG=0
DESTINATIONFLAG=0
PACKAGE_TO_TEST=""
NBCORES=1
SKIPINSTALLFLAG=0
HTMLFLAG=0
RESULTURLFLAG=0
eval set -- "$ARGS";
while true; do
case "$1" in
-d|--dest)
shift;
if [ -n "$1" ]; then
if [ -d "$1" ] || [ -f "$1" ]; then
echo "File or directory $1 already exists
"
printUsage
exit
else
DESTINATIONFLAG=1
DESTINATION=$(readlink -f "$1")
fi
else
echo "You have to set a destination directory
"
printUsage
exit
fi
shift;
;;
-l|--libuser)
shift;
if [ -n "$1" ]; then
if ! [ -d "$1" ]; then
mkdir "$1"
echo "CREATING '$1' personnal R library"
fi
export R_LIBS_USER=$(readlink -f "$1")
else
echo "You have to set a non-empty R LIB USER directory
"
printUsage
exit
fi
shift;
;;
-r|--repo)
shift;
if [ -n "$1" ]; then
REPOSITORYFLAG=1
REPOSITORY=$1
else
echo "You have to set a non-empty repository
"
printUsage
exit
fi
shift;
;;
-m|--mail)
shift;
if [ -n "$1" ]; then
MAILTOFLAG=1
MAILTO=$1
else
echo "You have to set a non-empty destination EMAIL ADDRESS
"
printUsage
exit
fi
shift;
;;
-u|--urlresult)
shift;
if [ -n "$1" ]; then
RESULTURLFLAG=1
RESULT_URL=$1
else
echo "You have to set a non-empty result url
"
printUsage
exit
fi
shift;
;;
-x|--xvfb)
shift;
if [ -n "$1" ]; then
XVFBRUN_PATH="$1"
if ! [ -f $XVFBRUN_PATH ]; then
echo "xvfb-run not found...
"
exit
fi
else
echo "You have to set a non-empty XVFB-RUN path
"
printUsage
exit
fi
shift;
;;
-n|--nbcores)
shift;
if [ -n "$1" ]; then
NBCORES="$1"
re='^[0-9]+$'
if ! [[ $NBCORES =~ $re ]] ; then
echo "-n --nbcores parameter must be a number" >&2; exit 1
fi
else
echo "You have to set a non-empty nbcores parameter
"
printUsage
exit
fi
shift;
;;
-s|--skipinstall)
SKIPINSTALLFLAG=1
shift;
;;
-h|--html)
HTMLFLAG=1
shift;
;;
--)
break;
;;
esac
done
# getting non-option arguments : THE MAIN ONE : PACKAGE_TO_TEST !
# only last non-option argument will be taken
shift;
while [ -n "$1" ]; do
PACKAGE_TO_TEST=$1
shift
done
if ! [ -n "$PACKAGE_TO_TEST" ]; then
echo "There must be a package to test
"
printUsage
exit
fi
#### DEFAULT VALUES management
# Default destination directory is ./check_PKGNAME_DATE
if [ $DESTINATIONFLAG == 0 ]; then
DESTINATION=$(readlink -f "./check_${PACKAGE_TO_TEST}_`date '+%Y%m%d.%H%M%S'`")
fi
if [ $RESULTURLFLAG == 0 ]; then
RESULT_URL=$DESTINATION
fi
# RECAP OF ALL PARAMS
echo "PACKAGE TO TEST : $PACKAGE_TO_TEST"
if [ -n "$R_LIBS_USER" ]; then
echo "R_LIBS_USER : $R_LIBS_USER"
else
echo "R_LIBS_USER : EMPTY => DEFAULT"
fi
echo "DESTINATION DIRECTORY : $DESTINATION"
if [[ $MAILTOFLAG == 1 ]]; then
echo "MAIL will be sent to $MAILTO"
else
echo "NO MAILS"
fi
if [[ $RESULTURLFLAG == 1 ]]; then
echo "Result URL is $RESULT_URL"
fi
if [[ $REPOSITORYFLAG == 1 ]]; then
echo "Package REPOSITORY : $REPOSITORY"
else
echo "NO SPECIFIC PACKAGE REPOSITORY"
fi
if [[ $SKIPINSTALLFLAG == 1 ]]; then
echo "Installation of packages will be skipped"
fi
if [[ $HTMLFLAG == 1 ]]; then
echo "HTML report will be generated in $DESTINATION/index.html"
else
echo "NO HTML report will be generated"
fi
echo "rtest will be using $NBCORES simultaneous processes"
# send start mail
if [[ $MAILTOFLAG == 1 ]]; then
echo "Check progress and results are here :
$RESULT_URL
Your test directory is named `basename $DESTINATION`
" | mail -s "Package \"$PACKAGE_TO_TEST\" R check started (`basename $DESTINATION`)" $MAILTO
fi
######## FILE management
# Destination directory creation
mkdir $DESTINATION
cd $DESTINATION
if [[ $HTMLFLAG == 1 ]]; then
echo "Downloading jquery inside result folder..."
wget http://code.jquery.com/jquery-1.7.2.min.js -o $DESTINATION/jquery-1.7.2.min.js
echo
fi
echo
printLeftPurple "Generation of depends.R ... started at `date '+%H:%M:%S'` ... "
# generate depends.R
echo 'if (!"tools" %in% installed.packages(lib.loc=Sys.getenv("R_LIBS_USER"))) {
install.packages("tools",repos=c("'$DEFAULT_REPOSITORY'"), lib=Sys.getenv("R_LIBS_USER"), dependencies=c("Depends", "Imports", "LinkingTo", "Suggests"), Ncpus=7)
}
old <- getOption("defaultPackages"); r <- getOption("repos")
r["CRAN"] <- "'$DEFAULT_REPOSITORY'"
options(defaultPackages = c(old, "MASS"), repos = r)
require("tools")
reverse_dependencies_with_maintainers <-
function(packages, which = c("Depends", "Imports", "LinkingTo"),
recursive = FALSE)
{
contrib.url(getOption("repos")["CRAN"], "source") # trigger chooseCRANmirror() if required
description <- sprintf("%s/web/packages/packages.rds",
getOption("repos")["CRAN"])
con <- if(substring(description, 1L, 7L) == "file://")
file(description, "rb")
else
url(description, "rb")
on.exit(close(con))
db <- readRDS(gzcon(con))
rownames(db) <- NULL
rdepends <- package_dependencies(packages, db, which,
recursive = recursive,
reverse = TRUE)
rdepends <- sort(unique(unlist(rdepends)))
pos <- match(rdepends, db[, "Package"], nomatch = 0L)
db[pos, c("Package", "Version", "Maintainer")]
}
Sys.setenv(http_proxy = "")
a <- reverse_dependencies_with_maintainers("'$PACKAGE_TO_TEST'", which = c("Depends", "Imports", "Suggests", "LinkingTo"))
a <- a[order(a[,1]),]
ff <- file("depends.txt", open = "w")
cat( paste(sep=",",a[,1],sub("\n","",a[,2]),sub("\n"," ",a[,3]), collapse = "\n"), "\n", file=ff)
close(ff)
' > $DESTINATION/depends.R
printRightGreen "`date '+%H:%M:%S'` : OK"
################ INSTALL of package to test ####################
printLeftPurple "Installing $PACKAGE_TO_TEST ... started at `date '+%H:%M:%S'` ... "
REPO_R_PARAM=""
if [[ $REPOSITORYFLAG == 1 ]]; then
REPO_R_PARAM=", repos=c(\"$REPOSITORY\")"
else
REPO_R_PARAM=", repos=c(\"$DEFAULT_REPOSITORY\")"
fi
R_LIBS_USER_PARAM=""
if [ -n "$R_LIBS_USER" ]; then
R_LIBS_USER_PARAM=", lib=Sys.getenv(\"R_LIBS_USER\")"
fi
echo '
install.packages("'$PACKAGE_TO_TEST'"'$REPO_R_PARAM''$R_LIBS_USER_PARAM', dependencies=c("Depends", "Imports", "LinkingTo", "Suggests"), Ncpus=7)
ff <- file("pkg.version", open = "w")
cat( paste(sep=",",packageVersion("'$PACKAGE_TO_TEST'")), file=ff)
close(ff)
' > $DESTINATION/install_pkg.R
R CMD BATCH install_pkg.R
if [[ $HTMLFLAG == 1 ]]; then
generate_html_report $DESTINATION
fi
if [[ $? == 0 ]]; then
touch install_pkg_ok
printRightGreen "`date '+%H:%M:%S'` : OK"
else
touch install_pkg_problem
printRightRed "`date '+%H:%M:%S'` : FAILED"
fi
############### GENERATION OF DEPENDENCY LIST ###################
printLeftPurple "Generating dependency list (should take less than a minute)... started at `date '+%H:%M:%S'` ... "
R CMD BATCH --no-timing depends.R
#cat depends.txt | grep -v structSSI | grep -v SigTree | grep -v SeqFeatR | grep -v gWidgetsRGtk2 | grep -v GrammR | grep -v RADami > list_dependencies.txt
cat depends.txt > list_dependencies.txt
printRightGreen "`date '+%H:%M:%S'` : OK"
#################### UPDATE of R packages in R_LIBS_USER #####################
if [[ "$SKIPINSTALLFLAG" == "0" ]]; then
printLeftPurple "Updating R packages in R_LIBS_USER (takes a very variable time)... started at `date '+%H:%M:%S'` ... "
echo '
chooseBioCmirror(ind=3)
setRepositories(ind=c(1,2,3,4,5,6,7,8,9))
update.packages(lib.loc=Sys.getenv("R_LIBS_USER"), repos=c("'$DEFAULT_REPOSITORY'"),ask=FALSE)
if (!"XML" %in% installed.packages(lib.loc=Sys.getenv("R_LIBS_USER"))) {
install.packages("XML",repos=c("'$DEFAULT_REPOSITORY'"), lib=Sys.getenv("R_LIBS_USER"), dependencies=c("Depends", "Imports", "LinkingTo", "Suggests"), Ncpus=7)
}
source("http://bioconductor.org/biocLite.R")
biocLite("Biostrings", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("Heatplus", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("qvalue", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("graph", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("multtest", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("widgetTools", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("phyloseq", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)
biocLite("Rgraphviz", ask=FALSE, lib.loc=Sys.getenv("R_LIBS_USER"), suppressUpdates=TRUE)