Class: XcodeInstaller::Install
- Inherits:
-
Object
- Object
- XcodeInstaller::Install
- Defined in:
- lib/xcode-installer/install.rb
Instance Attribute Summary collapse
-
#copied_file_count ⇒ Object
Returns the value of attribute copied_file_count.
-
#copied_kb ⇒ Object
Returns the value of attribute copied_kb.
-
#progress_bar ⇒ Object
Returns the value of attribute progress_bar.
-
#release ⇒ Object
Returns the value of attribute release.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#version_suffix ⇒ Object
Returns the value of attribute version_suffix.
Instance Method Summary collapse
- #accumulate_kbytes(path) ⇒ Object
- #action(args, options) ⇒ Object
- #copy(source_path, destination_path) ⇒ Object
- #copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) ⇒ Object
-
#cp_r(src, dest, options = {}) ⇒ Object
# The following code was copied out of fileutils.rb from ruby 1.9.3-p392 # #.
-
#dir_size(path) ⇒ Object
Exmaple output of the du command: 2359828 /Volumes/Xcode/Xcode.app/.
- #dmg_file_name ⇒ Object
- #fu_each_src_dest(src, dest) ⇒ Object
- #fu_each_src_dest0(src, dest) ⇒ Object
-
#initialize ⇒ Install
constructor
A new instance of Install.
Constructor Details
#initialize ⇒ Install
Returns a new instance of Install.
19 20 21 |
# File 'lib/xcode-installer/install.rb', line 19 def initialize @copied_kb = 0 end |
Instance Attribute Details
#copied_file_count ⇒ Object
Returns the value of attribute copied_file_count.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def copied_file_count @copied_file_count end |
#copied_kb ⇒ Object
Returns the value of attribute copied_kb.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def copied_kb @copied_kb end |
#progress_bar ⇒ Object
Returns the value of attribute progress_bar.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def @progress_bar end |
#release ⇒ Object
Returns the value of attribute release.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def release @release end |
#verbose ⇒ Object
Returns the value of attribute verbose.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def verbose @verbose end |
#version_suffix ⇒ Object
Returns the value of attribute version_suffix.
17 18 19 |
# File 'lib/xcode-installer/install.rb', line 17 def version_suffix @version_suffix end |
Instance Method Details
#accumulate_kbytes(path) ⇒ Object
79 80 81 82 |
# File 'lib/xcode-installer/install.rb', line 79 def accumulate_kbytes(path) @copied_file_count = copied_file_count + 1 @progress_bar.progress = @copied_file_count.to_i end |
#action(args, options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/xcode-installer/install.rb', line 23 def action(args, ) @verbose = .verbose mgr = XcodeInstaller::ReleaseManager.new @release = mgr.get_release(.release, .pre_release) @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}" # 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}/Xcode.app", destination) system "hdiutil detach -quiet #{mountpoint}" end |
#copy(source_path, destination_path) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xcode-installer/install.rb', line 59 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) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/xcode-installer/install.rb', line 101 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. destent.path if preserve end end |
#cp_r(src, dest, options = {}) ⇒ Object
# The following code was copied out of fileutils.rb from ruby 1.9.3-p392 #
#
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/xcode-installer/install.rb', line 90 def cp_r(src, dest, = {}) # 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 [:noop] = .dup [:dereference_root] = true unless .key?(:dereference_root) fu_each_src_dest(src, dest) do |s, d| copy_entry s, d, [:preserve], [:dereference_root], [:remove_destination] end end |
#dir_size(path) ⇒ Object
Exmaple output of the du command: 2359828 /Volumes/Xcode/Xcode.app/
74 75 76 77 |
# File 'lib/xcode-installer/install.rb', line 74 def dir_size(path) output = `du -sk '#{path}' 2> /dev/null` return output.split(" ").first.to_i * 1024 end |
#dmg_file_name ⇒ Object
55 56 57 |
# File 'lib/xcode-installer/install.rb', line 55 def dmg_file_name return File.basename(@release['download_url']) end |
#fu_each_src_dest(src, dest) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/xcode-installer/install.rb', line 114 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) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/xcode-installer/install.rb', line 121 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 |