module Dev module Cmd class Build def self.build(branch) db=Dev::Database.new puts " " puts "building branch " + branch.foreground(:green) h=Dev::Cmd::Build.get_branch_hash(branch) Hash.print_hash("",h) # does a result already exist? results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}", :user=>"#{h[:user]}", :machine=>"#{h[:machine]}"}) result=results[0] if !results.empty? if(results.empty?) result=h # export to local directory FileUtils.mkdir("#{Dev::Environment.dev_root}/exp") if !File.exists?("#{Dev::Environment.dev_root}/exp") FileUtils.rm_r(h[:dir]) if File.exists? h[:dir] puts "svn exporting #{h[:uri]}@#{h[:revision]} to #{h[:dir]}" Dev::Scm::export("#{h[:uri]}@#{h[:revision]}","#{h[:dir]}",'svn') # Dev::Commands.execute_cmd("svn export #{h[:uri]}@#{h[:revision]} #{h[:dir]}") # rake in local directory call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true}) call.puts_summary ch=call.get_hash [:cmd,:status,:start_time,:end_time,:elapsed,:timeout,:timed_out,:output,:error].each{ |k| h[k]=ch[k]; } # store results to database db.add_result(result) db=nil end puts "results hash:" puts " " Hash.print_hash("",result) Dev::SystemCall.puts_hash_summary(result) return 0 end def self.status(branch) db=Dev::Database.new h=Dev::Cmd::Build.get_branch_hash(branch) puts "status of branch " + branch.foreground(:green) + "@#{h[:revision]}" # do any results exist for latest revision? results=db.get_results({:uri=>"#{h[:uri]}", :revision=>"#{h[:revision]}"}) #resultss=db.get_results({:branch=>h[:branch]}) #results=db.get_results({:uri=>"#{h[:uri]}"}) db=nil puts " no results" if results.empty? fail=" [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan) pass=" [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan) results.each{ |r| status=pass status=fail if r[:status] != 0 && r[:status] != "0" elapsed="[" + "%.0f" %(r[:elapsed]) + "s]".foreground(:cyan) context="#{r[:user]}@#{r[:machine]}".foreground(:green) puts "#{status} #{context} #{elapsed} #{r[:end_time]}" } end def self.work(branch) #db=Dev::Database.new puts " " puts "working on branch " + branch.foreground(:green) h=Dev::Cmd::Build.get_branch_hash(branch) h[:dir]="#{Dev::Environment.dev_root}/wrk/#{branch}" #Hash.print_hash("",h) # export to local directory FileUtils.mkdir("#{Dev::Enviroment.dev_root}/wrk") if !File.exists?("#{Dev::Environment.dev_root}/wrk") Dev::Commands.execute_cmd("svn co #{h[:uri]} #{h[:dir]}") if !File.exists? h[:dir] # rake in local directory call=Dev::SystemCall.new({:cmd=>'rake default',:dir=>h[:dir],:capture_output=>true,:capture_error=>true}) puts "------------------------------------------------------------".foreground(:green) call.puts_summary puts "------------------------------------------------------------".foreground(:green) end def self.get_branch_hash(branch) db=Dev::Database.new h=Hash.new h[:uri]=db.get_branch_uri(branch) db=nil h[:revision]=Dev::Svn.last_changed_revision(h[:uri]) h[:dir]="#{Dev::Environment.dev_root}/exp/#{branch}@#{h[:revision]}" h[:user]="#{Dev::Environment.user}" h[:machine]="#{Dev::Environment.machine}" h[:ruby_version]=RUBY_VERSION h[:ruby_platform]=RUBY_PLATFORM return h end end # class Setup end # module Cmd end # module Dev