<commit_before>require 'thor'
require 'yaml'
require 'json'
require 'travis/worker'

module Travis
  module Worker
    module Cli
      class Vagrant < Thor
        class << self
          def config
            Travis::Worker.config.vms
          end
        end

        namespace "travis:worker:vagrant"

        include Cli

        desc 'rebuild', 'Rebuild all worker vms'
        method_option :from, :default => config.base
        def rebuild
          vbox.reset

          download
          add_box from, :to => 'base'
          exit unless up 'base'
          package 'base'

          1.upto(config.count) do |num|
            add_box 'base', :to => "worker-#{num}"
          end
          up
        end

        protected

          def vbox
            @vbox ||= Vbox.new
          end

          def config
            self.class.config
          end

          def from
            options['from']
          end

          def download
            run "wget http://files.vagrantup.com/#{from}.box" unless File.exists?("#{from}.box")
          end

          def add_box(name, options = {})
            run "vagrant box add #{options[:to] || name} #{name}.box"
          end

          def up(name = nil)
            run "vagrant up #{name}"
          end

          def package(name)
            run "rm -rf #{name}.box"
            run "vagrant package --base #{uuid}"
            run "mv package.box #{name}.box"
          end

          def uuid
            vms = JSON.parse(File.read('.vagrant'))
            vms['active']['base'] || raise("could not find base uuid in #{vms.inspect}")
          end
      end
    end
  end
end<commit_msg>refactor thor cli for vagrant and add a few finer grained tasks<commit_after>require 'thor'
require 'yaml'
require 'json'
require 'travis/worker'

module Travis
  module Worker
    module Cli
      class Vagrant < Thor
        class << self
          def config
            Travis::Worker.config.vms
          end
        end

        namespace "travis:worker:vagrant"

        include Cli

        desc 'rebuild', 'Rebuild all worker vms'
        method_option :from, :default => config.base
        def rebuild
          vbox.reset

          download
          add_box from, :to => 'base'
          exit unless up 'base'
          package_box 'base'

          1.upto(config.count) do |num|
            add_box 'base', :to => "worker-#{num}"
          end
          up
        end

        desc 'package', 'Package the base.box'
        method_option :from, :default => config.base
        def package
          exit unless up 'base'
          package_box 'base'
        end

        desc 'import', 'Import the base.box to worker boxes'
        method_option :from, :default => config.base
        def import
          1.upto(config.count) do |num|
            add_box 'base', :to => "worker-#{num}"
          end
        end

        protected

          def vbox
            @vbox ||= Vbox.new
          end

          def config
            self.class.config
          end

          def from
            options['from']
          end

          def download
            run "wget http://files.vagrantup.com/#{from}.box" unless File.exists?("#{from}.box")
          end

          def add_box(name, options = {})
            run "vagrant box add #{options[:to] || name} #{name}.box"
          end

          def up(name = nil, options = { :provision => false })
            run "vagrant up #{name} --provision=#{options[:provision].inspect}"
          end

          def package_box(name)
            run "rm -rf #{name}.box"
            run "vagrant package --base #{uuid}"
            run "mv package.box #{name}.box"
          end

          def uuid
            vms = JSON.parse(File.read('.vagrant'))
            vms['active']['base'] || raise("could not find base uuid in #{vms.inspect}")
          end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10581603894440174, 'fraction_numerical': 0.0007686395080707148, 'mean_word_length': 1.44, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5503612', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1102, 'n_words': 327}