Class: Pik::Install
Instance Attribute Summary
Attributes inherited from Command
#config, #debug, #options, #output, #version
Instance Method Summary
collapse
Methods inherited from Command
#actual_gem_home, #add_sigint_handler, aka, choose_from, clean_gem_batch, #close, cmd_name, #cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_batches, description, #editors, #find_config_from_path, #get_gem_home, #get_version, hl, inherited, it, names, #parse_options, #pik_version, #sh, summary
Constructor Details
#initialize(args = ARGV, config_ = nil) ⇒ Install
Returns a new instance of Install.
12
13
14
15
16
17
|
# File 'lib/pik/commands/install_command.rb', line 12
def initialize(args=ARGV, config_=nil)
super
@download_dir = config.global[:download_dir] || PIK_HOME + 'downloads'
@install_root = config.global[:install_dir] || PIK_BATCH.dirname + 'pik'
FileUtils.mkdir_p @download_dir.to_s
end
|
Instance Method Details
#add(path) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/pik/commands/install_command.rb', line 66
def add(path)
puts
p = Pik::Add.new([path], config)
p.execute
p.close
end
|
#command_options ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pik/commands/install_command.rb', line 28
def command_options
super
sep =<<SEP
Choices are: ruby, jruby, or ironruby
If no version is specified, the latest version will be installed.
Download and install locations can be configured with 'pik config'.
Examples:
# install the latest version of JRuby (currently 1.4.0RC1)
>pik install jruby
# install the latest 1.8 version of MinGW Ruby
>pik install ruby 1.8
SEP
options.separator sep
end
|
#download(package, download_dir = @download_dir) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/pik/commands/install_command.rb', line 48
def download(package, download_dir=@download_dir)
target = download_dir + package. split('/').last
puts "** Downloading: #{package} \n to: #{target.windows}\n\n"
URI.download(package, target.to_s, {:progress => true})
puts
return target
end
|
#download_seven_zip ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/pik/commands/install_command.rb', line 81
def download_seven_zip
question = "You need the 7zip utility to extract this file.\n"
question << "Would you like me to download it? (yes/no)"
if @hl.agree(question){|answer| answer.default = 'yes' }
uri = 'http://downloads.sourceforge.net/sevenzip/7za465.zip'
file = download(uri)
Zip.fake_unzip(file.to_s, /\.exe|\.dll$/, PIK_BATCH.dirname.to_s)
else
raise QuitError
end
end
|
19
20
21
22
23
24
25
26
|
# File 'lib/pik/commands/install_command.rb', line 19
def execute
implementation = Implementations[@args.shift]
target, package = implementation.find(*@args)
target = @install_root + "#{implementation.name}-#{target.gsub('.','')}"
file = download(package)
(target, file)
add( Pathname(target) + 'bin' )
end
|
56
57
58
59
60
61
62
63
64
|
# File 'lib/pik/commands/install_command.rb', line 56
def (target, file)
if Which::SevenZip.exe
FileUtils.mkdir_p target
(file, target)
else
download_seven_zip
(target, file)
end
end
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/pik/commands/install_command.rb', line 93
def (file, target, options = {})
fail unless File.directory?(target)
tmpdir = File.expand_path(File.join(Dir.tmpdir, "extract_sandbox_#{$$}"))
FileUtils.mkpath(tmpdir) unless File.exist?(tmpdir)
case file
when /(^.+\.tar)\.z$/, /(^.+\.tar)\.gz$/, /(^.+\.tar)\.bz2$/
seven_zip tmpdir, file
seven_zip target, File.join(tmpdir, File.basename($1))
when /(^.+)\.tgz$/
seven_zip tmpdir, file
seven_zip target, File.join(tmpdir, "#{File.basename($1)}.tar")
when /(^.+\.zip$)/, /(^.+\.7z$)/
seven_zip(target, $1)
else
raise "Unknown file extension! (for file #{file})"
end
folders_in_target = []
Dir.chdir(target) { folders_in_target = Dir.glob('*') }
folders_in_target.each do |folder|
next unless File.directory?(File.join(target, folder)) && folder =~ /\-/
contents = []
Dir.chdir(File.join(target, folder)) { contents = Dir.glob('*') }
contents.each do |c|
FileUtils.mv File.join(target, folder, c), target, :force => true
end
FileUtils.rm_rf File.join(target, folder)
end
FileUtils.rm_rf tmpdir
end
|
#seven_zip(target, file) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/pik/commands/install_command.rb', line 73
def seven_zip(target, file)
file = Pathname(file)
seven_zip = Which::SevenZip.exe.basename
puts "** Extracting: #{file.windows}\n to: #{target}" system("#{seven_zip} x -y -o\"#{target}\" \"#{file.windows}\" > NUL")
puts 'done'
end
|