Class: Pik::Install
Instance Attribute Summary collapse
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, #close, #cmd_name, cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_script, description, #editors, #find_config_from_path, #gem_path, #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.
14
15
16
17
18
19
|
# File 'lib/pik/commands/install_command.rb', line 14
def initialize(args=ARGV, config_=nil)
super
@download_dir = config.global[:download_dir] || PIK_HOME + 'downloads'
@install_root = config.global[:install_dir] || PIK_HOME + 'rubies'
FileUtils.mkdir_p @download_dir.to_s
end
|
Instance Attribute Details
Returns the value of attribute target.
12
13
14
|
# File 'lib/pik/commands/install_command.rb', line 12
def target
@target
end
|
Instance Method Details
#command_options ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/pik/commands/install_command.rb', line 30
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
50
51
52
53
54
55
56
|
# File 'lib/pik/commands/install_command.rb', line 50
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
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/pik/commands/install_command.rb', line 76
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_SCRIPT.dirname.to_s)
else
raise QuitError
end
end
|
21
22
23
24
25
26
27
28
|
# File 'lib/pik/commands/install_command.rb', line 21
def execute
implementation = Implementations[@args.shift]
@target, package = implementation.find(*@args)
@target = @install_root + "#{implementation.name}-#{@target.gsub('.','')}"
file = download(package)
(@target, file)
implementation.after_install(self)
end
|
58
59
60
61
62
63
64
65
66
|
# File 'lib/pik/commands/install_command.rb', line 58
def (target, file)
if Which::SevenZip.exe
FileUtils.mkdir_p target
(file, target)
else
download_seven_zip
(target, file)
end
end
|
88
89
90
91
92
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
|
# File 'lib/pik/commands/install_command.rb', line 88
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
68
69
70
71
72
73
74
|
# File 'lib/pik/commands/install_command.rb', line 68
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
|