Never been to DZone Snippets before?

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 (See related posts)

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

   1  
   2  #! /usr/bin/ruby -W0
   3  
   4  require 'Time'
   5  require 'Find'
   6  require 'optparse'
   7  
   8  def splitEntryLine(line)
   9  	re = /\/(.*)\/(.*)\/(.*)\/(.*)\/(.*)/
  10  	m=re.match(line)
  11  	if m
  12  		return m[1..-1]	
  13  	else
  14  		return nil
  15  	end
  16  end
  17  		
  18  
  19  def parseCvsEntries(dirname, modified)
  20  #print "CVS: ", dirname
  21  		array = []
  22      File.open(File.join(dirname,"CVS", "Entries"), "r") { | entriesFile |
  23          entriesFile.each_line { | line |
  24  					name, ver, date, k, t=splitEntryLine(line)
  25  					if name
  26  							file=File.join(dirname, name)
  27  							if File.exists?(file) and not File.directory?(file)
  28  								orig=Time.parse(date)
  29  								orig = orig+orig.gmt_offset
  30  								mtime = File.new(file).mtime
  31  								if mtime != orig
  32  									if modified
  33  										array.push(file)
  34  									end
  35  								else
  36  									if not modified
  37  										array.push(file)
  38  									end
  39  								end
  40  							end
  41  					end
  42          }
  43       }
  44  	return array
  45  end
  46  
  47  def checkFile(dirname, filename, modified)
  48  	array = []
  49  	path = File.join(dirname, filename)
  50    if File.directory?(path)
  51  		if filename == "CVS"
  52  			array += parseCvsEntries(dirname, modified);
  53  		elsif not filename == "." and not filename == ".."
  54  			array += checkDir(path, modified)
  55  		end	
  56  	end
  57  	return array
  58  end
  59  
  60  def checkDir(dirname, modified)
  61  	array = Array.new
  62  	Dir.entries(dirname).each do |filename|
  63  		array += checkFile(dirname, filename, modified);
  64  	end 
  65  	return array
  66  end
  67  
  68  def removeUnmodified() 
  69  	list = checkDir(".", false)
  70  	list.each { |file|
  71  		cmd = "rm -vf "+ file
  72  		system(cmd)
  73  	}
  74  end
  75  def printModified() 
  76  	list = checkDir(".", true)
  77  	list.each { |file|
  78  		print file, "\n"
  79  	}
  80  end
  81  def change_root(new_root)
  82  	print new_root, "\n"
  83  	Find.find(".") do |path|
  84  		if File.basename(path) == "Root" and File.basename(File.dirname(path)) == "CVS"
  85  			print path, "\n"
  86  			File.open(path, "w") do |fout|
  87  				fout << new_root << "\n"
  88  			end
  89  		end
  90  	end
  91  	print new_root, "\n"
  92  end
  93  def hello()
  94  	print "Hi\n"
  95  end
  96  def usage() 
  97  	puts "cvs.rb"
  98  	puts "  options:"
  99  	puts "    --removeUnmodified"
 100  	puts "    --chroot(-d)"
 101  	puts "    --printModified(-m)"
 102  	puts "    --help(-h)"
 103  	exit 1
 104  end
 105  def main() 
 106  	opts = OptionParser.new {|opts|
 107  		opts.on("-e", "--eval [TEXT]" ,"evaluate ruby code") do |text| 
 108  			eval(text)
 109  		end
 110  		opts.on_tail("-h", "--help", "Show this message") do
 111            puts opts
 112            exit
 113          end
 114  		opts.on("--removeUnmodified","delete unmodified cvs files") do 
 115  			removeUnmodified	
 116  		end
 117  		opts.on("--printModified","-m", "print modified cvs files") do 
 118  			printModified
 119  		end
 120  		opts.on("-d", "--chroot [ROOT]" ,"change CVS root") do |root| 
 121  			change_root(root)
 122  		end
 123  	}.parse!
 124  end
 125  main

You need to create an account or log in to post comments to this site.


Click here to browse all 5551 code snippets

Related Posts