<commit_before>module Mobilize
  class Box
    module Action
      module Install
        def install(_script, _message = nil)
          _box                      = self
          Log.write(_message)      if _message
          _box.sh                     _script
          return true
        end

        def apt_install(_name, _version)
          _box                   = self
          Log.write                "Installing apt #{_name} #{_version}..."
          _box.sh                  "sudo apt-get install -y #{_name}=#{_version}"
        end

        def gem_install(_name)
          _box                   = self
          _version               = Gem.loaded_specs[_name].version.to_s
          unless _box.gem_check    _name, _version
            Log.write              "Installing gem #{_name} #{_version}..."
            _box.sh                "gem install #{_name} -v=#{_version}"
          end
        end

        def gem_check(_name, _version)
          _box                   = self
          #check to make sure binary exists as well as correct installed version
          _binary_exists                     = _box.sh("which #{_name}",false).length>0
          if _binary_exists
            _installed_version_line          = _box.sh 'gem list | grep "^' + _name + '\\ "', false
            _installed_versions              = _installed_version_line.between('(',')').split ','
            if _installed_versions.include?    _version
              Log.write                        "Gem #{_name} #{_version} is alredy installed on #{_box.id}"
              return true
            end
          end
        end

        def install_ruby
          _box            = self
          _box.install      '\curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3',
                            "Installing RVM and Ruby 1.9.3 on #{_box.id}"
        end

        def install_mobilize_gem(_path = "c4ssio/mobilize")
          _box                         = self
          _box.sh                        "rm -rf mobilize && " +
                                         "git clone http://u:p@github.com/#{_path}.git --depth=1"
          _repo_revision               = _box.sh "cd mobilize && git log -1 --pretty=format:%H"
          _installed_revision          = begin; _box.sh "mob revision";rescue;nil;end
          if _installed_revision      != _repo_revision
            Log.write                    "Installing Mobilize on #{_box.id}\n" +
                                         "installed revision: #{_installed_revision.to_s}\n" +
                                         "repo revision: #{_repo_revision}"
            _box.sh                      "cd mobilize && bundle install && rake install"
          else
             Log.write                   "mobilize revision #{_installed_revision} already installed on #{_box.id}"
          end
          _box.sh                        "rm -rf mobilize"
        end

        def install_engine
          _box                           = self
          _box.install_mobilize

          _box.write_resque_pool_file
          _box.write_god_file
          Log.write                        "Mobilize engine installed on #{_box.id}"<commit_msg>Update install.rb<commit_after>module Mobilize
  class Box
    module Action
      module Install
        def install(_script, _message = nil)
          _box                      = self
          Log.write(_message)      if _message
          _box.sh                     _script
          return true
        end

        def apt_install(_name, _version)
          _box                   = self
          Log.write                "Installing apt #{_name} #{_version}..."
          _box.sh                  "sudo apt-get install -y #{_name}=#{_version}"
        end

        def gem_install(_name)
          _box                   = self
          _version               = Gem.loaded_specs[_name].version.to_s
          unless _box.gem_check    _name, _version
            Log.write              "Installing gem #{_name} #{_version}..."
            _box.sh                "gem install #{_name} -v=#{_version}"
          end
        end

        def gem_check(_name, _version)
          _box                   = self
          #check to make sure binary exists as well as correct installed version
          _binary_exists                     = _box.sh("which #{_name}",false).length>0
          if _binary_exists
            _installed_version_line          = _box.sh 'gem list | grep "^' + _name + '\\ "', false
            _installed_versions              = _installed_version_line.between('(',')').split ','
            if _installed_versions.include?    _version
              Log.write                        "Gem #{_name} #{_version} is alredy installed on #{_box.id}"
              return true
            end
          end
        end

        def install_ruby
          _box            = self
          _box.install      '\curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3',
                            "Installing RVM and Ruby 1.9.3 on #{_box.id}"
        end

        def install_mobilize_gem(_path = "mobilize/mobilize")
          _box                         = self
          _box.sh                        "rm -rf mobilize && " +
                                         "git clone http://u:p@github.com/#{_path}.git --depth=1"
          _repo_revision               = _box.sh "cd mobilize && git log -1 --pretty=format:%H"
          _installed_revision          = begin; _box.sh "mob revision";rescue;nil;end
          if _installed_revision      != _repo_revision
            Log.write                    "Installing Mobilize on #{_box.id}\n" +
                                         "installed revision: #{_installed_revision.to_s}\n" +
                                         "repo revision: #{_repo_revision}"
            _box.sh                      "cd mobilize && bundle install && rake install"
          else
             Log.write                   "mobilize revision #{_installed_revision} already installed on #{_box.id}"
          end
          _box.sh                        "rm -rf mobilize"
        end

        def install_engine
          _box                           = self
          _box.install_mobilize

          _box.write_resque_pool_file
          _box.write_god_file
          Log.write                        "Mobilize engine installed on #{_box.id}"
{'fraction_non_alphanumeric': 0.08481724461105905, 'fraction_numerical': 0.0029678225554514216, 'mean_word_length': 1.1378964941569283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446781', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1612, 'n_words': 408}