class XcodeInstaller::Install

Attributes

copied_file_count[RW]
copied_kb[RW]
progress_bar[RW]
release[RW]
verbose[RW]
version_suffix[RW]

Public Class Methods

new() click to toggle source
# File lib/xcode-installer/install.rb, line 19
def initialize
  @copied_kb = 0
end

Public Instance Methods

accumulate_kbytes(path) click to toggle source
# File lib/xcode-installer/install.rb, line 92
def accumulate_kbytes(path)
  @copied_file_count = copied_file_count + 1
  @progress_bar.progress = @copied_file_count.to_i
end
action(args, options) click to toggle source
# File lib/xcode-installer/install.rb, line 23
def action(args, options)
  install_type = (args.include? 'cli') ? 'cli' : 'gui'

  @verbose = options.verbose
  mgr = XcodeInstaller::ReleaseManager.new
  @release = mgr.get_release(options.release, options.pre_release, install_type)
  @version_suffix = "-#{@release['version']}"

  files = Dir.glob(dmg_file_name)
  if files.length == 0
    puts "#{dmg_file_name} file not found in current directory. Run the download command first."
    return
  elsif files.length > 1
    puts "Multiple #{dmg_file_name} files found in the current directory. Is this partition formatted with a case-insensitive disk format?"
    return
  end
  dmg_file = files[0]
  puts dmg_file if @verbose

  # Mount disk image
  mountpoint = '/Volumes/Xcode'
  # system "hdid '#{dmg_file}' -mountpoint #{mountpoint}"
  system "hdiutil attach -quiet #{dmg_file}"

  #
  # Install
  #
  if (install_type == 'gui')
    app_bundle_name = @release['app_bundle_name'] ||= "Xcode.app"

    # Trash existing install (so command is rerunnable)
    destination = "/Applications/Xcode#{version_suffix}.app"
    Trash.new.throw_out(destination)

    # TODO: Dynamically determine .app file name (DP releases have the version embedded)
    copy("#{mountpoint}/#{app_bundle_name}", destination)
  else
    # CLI install
    mountpoint = '/Volumes/Command\ Line\ Developer\ Tools'
    system "sudo installer -package #{mountpoint}/*.pkg -target /"
  end

  system "hdiutil detach -quiet #{mountpoint}"
end
copy(source_path, destination_path) click to toggle source
# File lib/xcode-installer/install.rb, line 72
def copy(source_path, destination_path)
  # Copy into /Applications
  # puts 'Copying Xcode.app into Applications directory (this can take a little while)'
  puts "#{source_path} -> #{destination_path}"

  total_files = `find #{source_path} -print | wc -l`
  puts "total_files: #{total_files}" if @verbose
  @progress_bar = ProgressBar.create(:title => "Copying", :starting_at => 0, :total => total_files.to_i)
  @copied_file_count = 0
  cp_r(source_path, destination_path, {})
  @progress_bar.finish
end
copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) click to toggle source
# File lib/xcode-installer/install.rb, line 114
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
  Entry_.new(src, nil, dereference_root).traverse do |ent|
    destent = Entry_.new(dest, ent.rel, false)

    # puts "#{dir_size(ent.path)} #{ent.path}"
    accumulate_kbytes(ent.path)

    File.unlink destent.path if remove_destination && File.file?(destent.path)
    ent.copy destent.path
    ent.copy_metadata destent.path if preserve
  end
end
cp_r(src, dest, options = {}) click to toggle source
#

The following code was copied out of fileutils.rb from ruby 1.9.3-p392 #

#
# File lib/xcode-installer/install.rb, line 103
def cp_r(src, dest, options = {})
  # fu_check_options options, OPT_TABLE['cp_r']
  # fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  return if options[:noop]
  options = options.dup
  options[:dereference_root] = true unless options.key?(:dereference_root)
  fu_each_src_dest(src, dest) do |s, d|
    copy_entry s, d, options[:preserve], options[:dereference_root], options[:remove_destination]
  end
end
dir_size(path) click to toggle source

Exmaple output of the du command: 2359828 /Volumes/Xcode/Xcode.app/

# File lib/xcode-installer/install.rb, line 87
def dir_size(path)
  output = `du -sk '#{path}' 2> /dev/null`
  return output.split(" ").first.to_i * 1024
end
dmg_file_name() click to toggle source
# File lib/xcode-installer/install.rb, line 68
def dmg_file_name
  return File.basename(@release['download_url'])
end
fu_each_src_dest(src, dest) { |s, d, stat| ... } click to toggle source
# File lib/xcode-installer/install.rb, line 127
def fu_each_src_dest(src, dest)
  fu_each_src_dest0(src, dest) do |s, d|
    raise ArgumentError, "same file: #{s} and #{d}" if File.identical?(s, d)
    yield s, d, File.stat(s)
  end
end
fu_each_src_dest0(src, dest) { |s, join(dest, basename)| ... } click to toggle source
# File lib/xcode-installer/install.rb, line 134
def fu_each_src_dest0(src, dest)
  if tmp = Array.try_convert(src)
    tmp.each do |s|
      s = File.path(s)
      yield s, File.join(dest, File.basename(s))
    end
  else
    src = File.path(src)
    if File.directory?(dest)
      yield src, File.join(dest, File.basename(src))
    else
      yield src, File.path(dest)
    end
  end
end