ewoga/bin/ewoga-test

81 lines
1.5 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
require 'colorize'
ROOTDIR=Pathname.new(__FILE__).dirname.parent.realpath.to_s
DATADIR=(Pathname.new(ROOTDIR) + 'NEXTFORMATION-ROR').to_s
# puts "ROOTDIR = #{ROOTDIR}"
# puts "DATA = #{DATADIR}"
$INDENT = 2
def indent
" " * $INDENT
end
class Project
def initialize path
@path = path
@name = File.basename path
@score = 0
@score_max = 0
@errors = 0
end
class ExtractionError < Exception ; end
def extract
Dir.chdir(@path)
tarfile = Dir.glob('projet-*.tar').sort.last
# tarfile = @path + '/projet.tar'
print indent + "Extracting project data from #{tarfile}... "
system "tar xavf #{tarfile} > extractlog"
raise ExtractionError unless $?.success?
puts "success".green
dir = %x{head -n1 extractlog}.strip
if dir != 'datingapp/' then
FileUtils.rm_rf 'datingapp'
FileUtils.mv dir, 'datingapp'
end
FileUtils.rm 'extractlog'
puts ""
FileUtils.rm_f ENV['HOME'] + '/.taskman.yml'
FileUtils.rm_f ENV['HOME'] + '/.taskman'
end
private
def bundle_prefix
prefix = ''
prefix = 'bundle exec ' if File.exist? 'Gemfile'
prefix
end
end
projects = []
if ARGV.empty? then
projects = Dir.glob(DATADIR + '/*')
else
projects = ARGV
end
out = File.open('result.csv','w+')
projects.each do |name|
projectpath = Pathname.new(name).realpath.to_s
puts "[#{File.basename(projectpath).yellow.on_blue}] #{projectpath}"
project = Project.new(projectpath)
project.extract
puts ""
end
out.close
exit 0