Permalink
Browse files

update tasks

  • Loading branch information...
1 parent 3b2ce2d commit 17ddcfc348f3d234f0b03b238188b1269eb6ad00 Greg Weber committed Nov 27, 2008
Showing with 60 additions and 12 deletions.
  1. +1 −12 rakefile
  2. +59 −0 tasks/helpers.rb
View
@@ -1,15 +1,4 @@
-def exit_msg(msg, code=1)
- puts msg
- exit(code)
-end
-def run command
- res = `#{command}`
- exit_msg res, $?.exitstatus if $?.exitstatus != 0
- res
-end
-def out command
- (puts (run command))
-end
+require 'tasks/helpers'
desc "mirror to jquery svn repository"
task :mirror do
View
@@ -0,0 +1,59 @@
+def exit_msg msg, code=1
+ puts msg; exit code
+end
+
+# exit on non-zero error code
+def run! *command
+ res = run(*command)
+ if (s = $?.exitstatus) != 0
+ exit_msg(res, s)
+ else
+ res
+ end
+end
+
+# this is like backticks, but the command will be shell escaped
+def run *command
+ res = run_shell_escaped *command
+ return <<-EOS if $?.exitstatus != 0
+
+exit code: #{$?.exitstatus}
+command result:
+#{res}
+
+failure on command:
+#{command.join(' ')}
+EOS
+
+ res
+end
+
+def run_shell_escaped *command
+ command = command.flatten.map do |str|
+ str =~/^'.*'$/ ? str : str.split(/\s+/)
+ end.flatten
+ res = IO.popen('-') {|io| io ? io.read : exec(command.shift, *command)}
+end
+
+def out *command
+ (puts (run! *command))
+end
+
+def cd_tmp
+ Dir.mkdir 'tmp' unless File.directory? 'tmp'
+ Dir.chdir('tmp') do |dir|
+ yield dir
+ end
+ rm_rf 'tmp'
+end
+
+class IO
+ def self.write( file, str )
+ self.open( file, 'w' ) { |fh| fh.print str }
+ end
+ def self.read_write( file, write_file=file )
+ self.write(write_file, (yield( self.read( file ))))
+ end
+end
+
+Dir.glob('tasks/*.rake').sort.each {|fn| import fn}

0 comments on commit 17ddcfc

Please sign in to comment.