Panasonic Youth rob sanheim writes about software, business, ruby, music, stuff and things



Posted
16 October 2007 @ 9am

Tagged
Open Source, Ruby

Discuss

Yall gonna go update some code, up in here, up ‘n here!”

A stupid script to update all projects within a directory. This could be massively improved.

RUBY:
  1. #!/usr/bin/env ruby
  2.  
  3. # Simple script to svn up all directories within the current directory, or the
  4. # specified directory.  Does not recurse, assumes we only need to go to the
  5. # immediate directories.
  6. # ex:> cd my_projects; upper    # svn up all projects w/i my_projects
  7. # ex:> upper ~/src/work/        # svn up all projects inside ~/src/work
  8. class Upper
  9.  
  10.   def self.svn_up(top_level_dir)
  11.     puts "Svn upping all projects within '#{top_level_dir}'"
  12.     full_path = File.expand_path(top_level_dir)
  13.     directories = []
  14.     Dir.open(full_path).each do |dir|
  15.       if (dir == "." || dir == ".." || dir == ".DS_store") then next end
  16.       full_dir = File.join(full_path, dir)
  17.       directories <<dir if File.directory?(full_dir)
  18.     end
  19.     puts "No directories found." if directories.empty?
  20.     directories.each do |dir|
  21.       command = "svn up #{dir}"
  22.       puts command
  23.       puts `#{command}`
  24.     end
  25.   end
  26.  
  27. end
  28.  
  29. dir = ARGV[0] || Dir.pwd
  30.  
  31. unless File.directory?(dir.to_s)
  32.   puts "Error - No directory exists with name: '#{dir}'" and exit
  33. end
  34.  
  35. Upper.svn_up(dir)


2 Comments

Posted by
Dan Manges
7 November 2007 @ 11am

You can also do this from the shell: ls | xargs svn up


Posted by
Rob
8 November 2007 @ 9am

Dan: very true…though then I don’t get the pretty puts messages, or the ability to build on top of it in ruby to do more advanced stuff =).


Leave a Comment

I’m feeling open sourcey… multi_rails has been released