DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Cvs PrintModified, RemoveUnmodified, Chroot
This script perfoms three utilities on CVS working directories.
-m, --printModified print modified cvs files
This prints out the modified files by comparing the timestamps to those in the CVS/Entries file in all subdirectories.
--removeUnmodified delete unmodified cvs files
This deletes all unmodified files. This saves disk space. Later you can run "cvs update" and the unmodified files will be restored.
3. This changes the cvs root in all subdirectories
-d, --chroot [ROOT] change CVS root
-h, --help Show this message
#! /usr/bin/ruby -W0
require 'Time'
require 'Find'
require 'optparse'
def splitEntryLine(line)
re = /\/(.*)\/(.*)\/(.*)\/(.*)\/(.*)/
m=re.match(line)
if m
return m[1..-1]
else
return nil
end
end
def parseCvsEntries(dirname, modified)
#print "CVS: ", dirname
array = []
File.open(File.join(dirname,"CVS", "Entries"), "r") { | entriesFile |
entriesFile.each_line { | line |
name, ver, date, k, t=splitEntryLine(line)
if name
file=File.join(dirname, name)
if File.exists?(file) and not File.directory?(file)
orig=Time.parse(date)
orig = orig+orig.gmt_offset
mtime = File.new(file).mtime
if mtime != orig
if modified
array.push(file)
end
else
if not modified
array.push(file)
end
end
end
end
}
}
return array
end
def checkFile(dirname, filename, modified)
array = []
path = File.join(dirname, filename)
if File.directory?(path)
if filename == "CVS"
array += parseCvsEntries(dirname, modified);
elsif not filename == "." and not filename == ".."
array += checkDir(path, modified)
end
end
return array
end
def checkDir(dirname, modified)
array = Array.new
Dir.entries(dirname).each do |filename|
array += checkFile(dirname, filename, modified);
end
return array
end
def removeUnmodified()
list = checkDir(".", false)
list.each { |file|
cmd = "rm -vf "+ file
system(cmd)
}
end
def printModified()
list = checkDir(".", true)
list.each { |file|
print file, "\n"
}
end
def change_root(new_root)
print new_root, "\n"
Find.find(".") do |path|
if File.basename(path) == "Root" and File.basename(File.dirname(path)) == "CVS"
print path, "\n"
File.open(path, "w") do |fout|
fout << new_root << "\n"
end
end
end
print new_root, "\n"
end
def hello()
print "Hi\n"
end
def usage()
puts "cvs.rb"
puts " options:"
puts " --removeUnmodified"
puts " --chroot(-d)"
puts " --printModified(-m)"
puts " --help(-h)"
exit 1
end
def main()
opts = OptionParser.new {|opts|
opts.on("-e", "--eval [TEXT]" ,"evaluate ruby code") do |text|
eval(text)
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on("--removeUnmodified","delete unmodified cvs files") do
removeUnmodified
end
opts.on("--printModified","-m", "print modified cvs files") do
printModified
end
opts.on("-d", "--chroot [ROOT]" ,"change CVS root") do |root|
change_root(root)
end
}.parse!
end
main





