<commit_before>require 'boxcar/command/base'
require 'httparty'

# Manage updates for Boxcar
#
class Boxcar::Command::Update < Boxcar::Command::Base
  include HTTParty

  def index
    version = args.first || latest_stable
    abort "You're on the latest stable" unless version.present?

    host    = 'https://github.com/nicinabox/boxcar/archive/'
    dest    = 'usr/apps/boxcar'

    `boxcar server:stop`

    puts "Fetching..."
    FileUtils.cd('/tmp') do
      # Fetch
      FileUtils.mkdir_p("build/#{dest}/log")
      `wget -q --no-check-certificate #{host}#{version}.zip`
      `unzip -q #{version}`
      `mv boxcar-#{version}/* build/#{dest}`
      `mv build/#{dest}/boot build/`
      `rm -rf build/#{dest}/test`
    end

    puts "Precompiling assets..."
    FileUtils.cd("/tmp/build/#{dest}") do
      # Precompile
      `bundle && rake assetpack:build`
    end

    FileUtils.cd('/tmp/build') do
      puts "Packing..."
      `makepkg -c y /boot/extra/boxcar-#{version}.txz`

      puts "Installing..."
      `installpkg /boot/extra/boxcar-#{version}.txz >/dev/null`
    end

    FileUtils.cd('/tmp') do
      puts "Clean up..."
      FileUtils.rm_rf(%W(build boxcar-#{version} #{version}))
    end

    # Migrate
    puts "Finishing..."
    FileUtils.cd("/#{dest}") do
      `rake db:migrate RACK_ENV=production >/dev/null`

      puts "Updated to #{version}!"
    end

    track_event("CLI", "update")

    `boxcar server:start`
  end

private

  def latest_stable
    response = self.class.get('https://api.github.com/repos/nicinabox/boxcar/tags')
    tags = JSON.parse(response.body)
    tags.first[0].name
  end
end
<commit_msg>Remove old boxcar txz on update<commit_after>require 'boxcar/command/base'
require 'httparty'

# Manage updates for Boxcar
#
class Boxcar::Command::Update < Boxcar::Command::Base
  include HTTParty

  def index
    version = args.first || latest_stable
    abort "You're on the latest stable" unless version.present?

    host    = 'https://github.com/nicinabox/boxcar/archive/'
    dest    = 'usr/apps/boxcar'

    `boxcar server:stop`

    puts "Fetching..."
    FileUtils.cd('/tmp') do
      # Fetch
      FileUtils.mkdir_p("build/#{dest}/log")
      `wget -q --no-check-certificate #{host}#{version}.zip`
      `unzip -q #{version}`
      `mv boxcar-#{version}/* build/#{dest}`
      `mv build/#{dest}/boot build/`
      `rm -rf build/#{dest}/test`
    end

    puts "Precompiling assets..."
    FileUtils.cd("/tmp/build/#{dest}") do
      # Precompile
      `bundle && rake assetpack:build`
    end

    FileUtils.cd('/tmp/build') do
      puts "Packing..."
      `rm /boot/extra/boxcar-*`
      `makepkg -c y /boot/extra/boxcar-#{version}.txz`

      puts "Installing..."
      `installpkg /boot/extra/boxcar-#{version}.txz >/dev/null`
    end

    FileUtils.cd('/tmp') do
      puts "Clean up..."
      FileUtils.rm_rf(%W(build boxcar-#{version} #{version}))
    end

    # Migrate
    puts "Finishing..."
    FileUtils.cd("/#{dest}") do
      `rake db:migrate RACK_ENV=production >/dev/null`

      puts "Updated to #{version}!"
    end

    track_event("CLI", "update")

    `boxcar server:start`
  end

private

  def latest_stable
    response = self.class.get('https://api.github.com/repos/nicinabox/boxcar/tags')
    tags = JSON.parse(response.body)
    tags.first[0].name
  end
end

{'fraction_non_alphanumeric': 0.16247755834829444, 'fraction_numerical': 0.0005984440454817474, 'mean_word_length': 2.617965367965368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2985310', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1162, 'n_words': 241}