[Distr-commits] r685 - branches/distr-2.3/pkg/utils
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Oct 20 14:00:36 CEST 2010
Author: ruckdeschel
Date: 2010-10-20 14:00:35 +0200 (Wed, 20 Oct 2010)
New Revision: 685
Added:
branches/distr-2.3/pkg/utils/getRevNr.R
Modified:
branches/distr-2.3/pkg/utils/NEWS
branches/distr-2.3/pkg/utils/README-R-utils
branches/distr-2.3/pkg/utils/showAllFiles.R
Log:
utils: new tools getRevNr, getAllRevNr to obtain SVN Revision Nr of a repository
Modified: branches/distr-2.3/pkg/utils/NEWS
===================================================================
--- branches/distr-2.3/pkg/utils/NEWS 2010-10-19 13:38:24 UTC (rev 684)
+++ branches/distr-2.3/pkg/utils/NEWS 2010-10-20 12:00:35 UTC (rev 685)
@@ -2,6 +2,10 @@
# News: to utilities in folder 'utils'
######################################################################
+### distrXXX family version 2.3
+
++ new utils getRevNr, getAllRevNr to obtain SVN Revision Nr
+
### distrXXX family version 2.2
+ ladealles.R now loads both .r and .R files
Modified: branches/distr-2.3/pkg/utils/README-R-utils
===================================================================
--- branches/distr-2.3/pkg/utils/README-R-utils 2010-10-19 13:38:24 UTC (rev 684)
+++ branches/distr-2.3/pkg/utils/README-R-utils 2010-10-20 12:00:35 UTC (rev 685)
@@ -173,4 +173,40 @@
if(FALSE){
showsvnlog(from=500,to=520)
showsvnlog(from=300,to=Inf,limit=1000)
-}
\ No newline at end of file
+}
+
+### getRevNr.R
+#
+## getRevNr
+# searches for the SVN revision number in a repository
+
+# Syntax
+
+getRevNr(dir="C:/rtest/distr/")
+## args: dir : the path to the repository
+### some examples
+if(FALSE){
+getRevNr()
+getRevNr(dir="C:/rtest/robast/")
+}
+
+## getAllRevNr
+# searches for the SVN revision number in a repository
+# and all its subfolders
+
+# Syntax
+
+getAllRevNr(dir = "C:/rtest/distr/",
+ except = NULL,
+ listOrMax = "list"
+ )
+
+## args: dir: top folder from which to recurse
+ except: some exceptions (regular expressions!)
+ listOrMax: do we return a list or only the max?
+### some examples
+if(FALSE){
+getAllRevNr()
+getAllRevNr(list="max")
+getAllRevNr("C:/rtest/robast/")
+}
Added: branches/distr-2.3/pkg/utils/getRevNr.R
===================================================================
--- branches/distr-2.3/pkg/utils/getRevNr.R (rev 0)
+++ branches/distr-2.3/pkg/utils/getRevNr.R 2010-10-20 12:00:35 UTC (rev 685)
@@ -0,0 +1,60 @@
+getRevNr <- function(dir="C:/rtest/distr/"){
+ ow <- getwd()
+ on.exit(setwd(ow))
+ setwd(dir)
+ if(! file.exists(".svn/entries")) return(NULL)
+ tab <- read.table(".svn/entries")[,1]
+ i<-1
+ while(i<length(tab)){
+ if(tab[i]=="dir") break
+ i <- i+1
+ }
+ vn <- as.numeric(paste(tab[i+1]))
+ while(i<length(tab)){
+ if(length(grep("[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}",tab[i],value=FALSE))>0) break
+ i <- i+1
+ }
+ dat <- as.POSIXct(sub("(.+)T.+","\\1",grep("[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}",tab[i],value=TRUE)))
+ who <- paste(tab[i+2])
+ return(list(vn=vn,dat=dat,who=who))
+}
+
+getAllRevNr <- function(
+ dir = "C:/rtest/distr/", ### top folder from which to recurse
+ except = NULL, ### some exceptions (regular expressions!)
+ listOrMax = "list" ### do we return a list or only the max?
+ ){
+ oldDir <- getwd()
+ on.exit(setwd(oldDir))
+ setwd(dir)
+ DD <- dir(".",rec=T)
+ DD1 <- DD[!DD%in%dir(".")]
+ DIR <- sort(unique(sub("/[^/]+$","",DD1)))
+ if(!is.null(except))
+ DIR <- DIR[-grep(except,DIR)]
+ li <- vector("list",length(DIR))
+ j <- 1
+ for(i in 1: length(DIR)){
+ li0 <- getRevNr(DIR[i])
+ if(!is.null(li0)) {li[[j]] <- li0; j <- j+1}
+ }
+ li<-li[1:j]
+ if(is.null(li[[j]])) li <- li[1:(j-1)]
+ print(length(li))
+ jm <- 1
+ for(j in 1: length(li))
+ {#print(j); print(li[[j]]); print(li[[jm]]$dat)
+ if(li[[j]]$vn>0)
+ if(li[[j]]$dat > li[[jm]]$dat) jm <- j}
+ if(listOrMax=="list")
+ return(li) else return(li[[jm]])
+}
+
+if(FALSE){
+ ### some examples
+getRevNr()
+getAllRevNr()
+
+}
+
+
Modified: branches/distr-2.3/pkg/utils/showAllFiles.R
===================================================================
--- branches/distr-2.3/pkg/utils/showAllFiles.R 2010-10-19 13:38:24 UTC (rev 684)
+++ branches/distr-2.3/pkg/utils/showAllFiles.R 2010-10-20 12:00:35 UTC (rev 685)
@@ -41,4 +41,3 @@
}
-if(FALSE){
More information about the Distr-commits
mailing list