pik 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+
2
+ === 0.2.5 / 2009-10-29
3
+
4
+ * use upx (http://upx.sf.net/) to compress pik_runner.exe
5
+ * fixes uninstall story so it doesn't conflict with other stories
6
+ * bugfix in uninstall command
7
+ * made all prompts default to 'yes'. bugfix:interactive add would prompt for jruby\bin dirs twice because of the existence of jruby.exe and jruby.bat
8
+ * fixed downloading of seven_zip error
9
+ * uninstall command
10
+ * fixes bug in BatchFileEditor#switch_path_to
11
+ * switched to HPricot for package searches, requires rubygems and exerb-mingw - closes gh-30
12
+
1
13
  === 0.2.4 / 2009-10-28
2
14
 
3
15
  * added rake command
@@ -18,6 +18,7 @@ features/run_command.feature
18
18
  features/step_definitions/pik_commands.rb
19
19
  features/switch_command.feature
20
20
  features/tag_command.feature
21
+ features/uninstall_command.feature
21
22
  features/version.feature
22
23
  lib/pik.rb
23
24
  lib/pik/batch_file.rb
@@ -39,6 +40,7 @@ lib/pik/commands/remove_command.rb
39
40
  lib/pik/commands/run_command.rb
40
41
  lib/pik/commands/switch_command.rb
41
42
  lib/pik/commands/tag_command.rb
43
+ lib/pik/commands/uninstall_command.rb
42
44
  lib/pik/config_file.rb
43
45
  lib/pik/contrib/progressbar.rb
44
46
  lib/pik/contrib/unzip.rb
data/Rakefile CHANGED
@@ -1,17 +1,18 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
+ require 'rbconfig'
4
5
  require 'win32/process'
5
6
 
6
7
  ENV['SPEC_OPTS']= '-O spec/spec.opts'
7
8
 
8
9
  file 'tools/pik/pik_runner.exy' do
9
10
  Dir.chdir 'tools/pik' do
10
- sh('ruby -rexerb/mkexy pik_runner')
11
+ sh('ruby -rexerb/mkexy pik_runner -v')
11
12
  end
12
13
  exy = YAML.load(File.read('tools/pik/pik_runner.exy'))
13
14
  zlib1 = {
14
- 'file' => 'c:/ruby/186-p368-mingw32/bin/zlib1.dll',
15
+ 'file' => File.join(RbConfig::CONFIG['bindir'], 'zlib1.dll'),
15
16
  'type' => 'extension-library'
16
17
  }
17
18
  exy['file']['zlib1.dll'] = zlib1
@@ -21,6 +22,7 @@ end
21
22
  file 'tools/pik/pik.exe', :needs => ['tools/pik/pik_runner.exy'] do
22
23
  Dir.chdir 'tools/pik' do
23
24
  sh('ruby -S exerb pik_runner.exy')
25
+ sh('upx -9 pik_runner.exe')
24
26
  end
25
27
  end
26
28
 
@@ -18,8 +18,8 @@ Feature: add command
18
18
  And I should see "Located at: C:\ruby\186-p368-mingw32\bin"
19
19
 
20
20
  Scenario: add a version that has already been added
21
- Given I have already added "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
22
- When I run "pik add C:\ruby\186-p368-mingw32\bin"
21
+ Given I have already added "ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]"
22
+ When I run "pik add "C:\temp\more spaces in path\ruby\Ruby-186-p383\bin""
23
23
  Then I should see "This version has already been added."
24
24
  And nothing should be added to the config file.
25
25
 
@@ -5,7 +5,7 @@ Feature: config command
5
5
  That allows her to configure pik's behavior.
6
6
 
7
7
  Scenario: config gem_home
8
- Given I have already added "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
8
+ Given I have already added "ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]"
9
9
  And I am currently using it.
10
10
  When I run "pik config gem_home default"
11
11
  Then a gem_home option should be added to the config.
@@ -5,8 +5,7 @@ Feature: default command
5
5
  That allows her to switch back to the system defined version.
6
6
 
7
7
  Scenario: switching to the default version
8
- # Given my default system version is "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
9
- And I am currently using "ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]"
8
+ Given I am currently using "ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]"
10
9
  When I run "pik default -v" and check the path
11
- Then I should see "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
12
- And the path should point to "c:\ruby\186-p368-mingw32\bin"
10
+ Then I should see "ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]"
11
+ And the path should point to "c:\ruby\Ruby-186-p383\bin"
@@ -8,9 +8,6 @@ config=<<CONFIG
8
8
  "140: jruby 1.4.0RC2 (ruby 1.8.7 patchlevel 174) (2009-10-21 7e77f32) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]":
9
9
  :path: !ruby/object:Pathname
10
10
  path: C:/temp/more spaces in path/ruby/jruby-140RC2/bin
11
- "186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]":
12
- :path: !ruby/object:Pathname
13
- path: c:/ruby/186-p368-mingw32/bin
14
11
  "186: ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]":
15
12
  :path: !ruby/object:Pathname
16
13
  path: c:/temp/more spaces in path/ruby/ruby-186-p383/bin
@@ -28,8 +25,9 @@ require 'yaml'
28
25
  require 'pathname'
29
26
  require 'fileutils'
30
27
  require 'lib/pik'
28
+ require 'rbconfig'
31
29
 
32
- REAL_PATH = ENV['PATH']
30
+ REAL_PATH = SearchPath.new(ENV['PATH']).replace(RbConfig::CONFIG['bindir'], 'c:/temp/more spaces in path/ruby/ruby-186-p383/bin').join
33
31
 
34
32
  ENV['HOME'] = "C:\\temp\\path with spaces"
35
33
  ENV['JAVA_HOME'] = "C:\\Program Files\\Java\\jre6"
@@ -22,6 +22,6 @@ Feature: list command
22
22
  And I should see "IronRuby:"
23
23
  And I should see "0.9.1:"
24
24
  And I should see "JRuby:"
25
- And I should see "1.4.0RC2:"
25
+ And I should see "1.4.0RC3:"
26
26
  Then I should see "Ruby:"
27
27
  And I should see " 1.8.6-p383"
@@ -5,14 +5,7 @@ Feature: remove command
5
5
  So that she can remove versions.
6
6
 
7
7
  Scenario: remove a version from the config
8
- Given I have already added "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
8
+ Given I have already added "ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]"
9
9
  When I run "pik remove 186 383 -f"
10
10
  Then I should see "removed"
11
- And the version should be removed.
12
-
13
- Scenario: remove a version from the config and the filesystem
14
- # Given I have already added "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
15
- # When I run "pik remove 186 min -f "
16
- # Then I should see "removed"
17
- # And the version should be removed.
18
-
11
+ And the version should be removed.
@@ -6,22 +6,22 @@ Feature: run command
6
6
 
7
7
  Scenario: run code
8
8
  When I run "pik run "path""
9
- Then I should find "PATH=" 5 times
9
+ Then I should find "PATH=" 4 times
10
10
  And I should see each version's path listed
11
11
  And I should see each version listed.
12
12
 
13
13
  Scenario: ruby command
14
14
  When I run "pik ruby -e "puts 'hello world!'" "
15
- Then I should find "hello world!" 5 times
15
+ Then I should find "hello world!" 4 times
16
16
  And I should see each version listed.
17
17
 
18
18
  Scenario: gem command
19
19
  When I run "pik gem -v"
20
- Then I should find "\n\d\.\d\.\d\n" 5 times
20
+ Then I should find "\n\d\.\d\.\d\n" 4 times
21
21
  And I should see each version listed.
22
22
 
23
23
  Scenario: rake command
24
24
  When I run "pik rake -V"
25
- Then I should find "rake, version \d\.\d\.\d\n" 5 times
25
+ Then I should find "rake, version \d\.\d\.\d\n" 4 times
26
26
  And I should see each version listed.
27
27
 
@@ -39,6 +39,10 @@ Given /^I have an empty config\.yml/ do
39
39
  File.open(TEST_PIK_HOME + 'config.yml','w'){|f| }
40
40
  end
41
41
 
42
+ Given /^there is no ruby version in the path$/ do
43
+ ENV['PATH'] = SearchPath.new(REAL_PATH).remove(Which::Ruby.find).join
44
+ end
45
+
42
46
  Given /^I have not installed pik to (.+)$/ do |path|
43
47
  FileUtils.rm_rf path if File.exist? path
44
48
  FileUtils.mkdir_p path
@@ -30,4 +30,17 @@ Feature: switch command
30
30
  | jruby 1.4.0RC2 (ruby 1.8.7 patchlevel 174) | jruby 1.4 |
31
31
  | ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32] | 186 383 |
32
32
  | ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] | 191 p2 |
33
-
33
+
34
+ Scenario Outline: Switching versions with no ruby in the path
35
+ Given I have added "<version>" to pik
36
+ And there is no ruby version in the path
37
+ When I run "pik <patterns>" and check the path
38
+ Then the path should point to it.
39
+ And the GEM_HOME might get set.
40
+
41
+ Examples:
42
+ | version | patterns |
43
+ | IronRuby 0.9.1.0 on .NET 2.0.0.0 | Ir 91 |
44
+ | jruby 1.4.0RC2 (ruby 1.8.7 patchlevel 174) | jruby 1.4 |
45
+ | ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32] | 186 383 |
46
+ | ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] | 191 p2 |
@@ -0,0 +1,13 @@
1
+ Feature: uninstall command
2
+ In order to keep the filesystem clean
3
+ A developer
4
+ Wants a command line tool
5
+ So that he can download and uninstall older ruby versions
6
+
7
+ Scenario: uninstall IronRuby
8
+ When I run "pik rm Ir 91 -f -q"
9
+ And I run "pik add "C:\temp\path with spaces\IronRuby-091\bin""
10
+ And I run "pik unin Ir 91 -f"
11
+ Then I should see "** Deleting C:\temp\path with spaces\IronRuby-091"
12
+ And I should see "091: IronRuby 0.9.1.0 on .NET 2.0.0.0 has been uninstalled."
13
+
data/lib/pik.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  module Pik
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ ENV['GEM_HOME'] = nil
8
+ ENV['GEM_PATH'] = nil
9
+
6
10
  require 'yaml'
7
11
  require 'pathname'
8
12
  require 'fileutils'
13
+ require 'open-uri'
9
14
  require 'rbconfig'
15
+ require 'rubygems'
16
+ require 'hpricot'
17
+ require 'highline'
10
18
 
11
19
  require 'pik/pik'
12
20
  require 'pik/batch_file'
@@ -28,14 +36,13 @@ require 'pik/commands/gemsync_command'
28
36
  require 'pik/commands/default_command'
29
37
  require 'pik/commands/implode_command'
30
38
  require 'pik/commands/tag_command'
39
+ require 'pik/commands/uninstall_command'
31
40
  require 'pik/config_file'
32
41
  require 'pik/implementations'
42
+ require 'pik/search_path'
33
43
  require 'pik/windows_env'
34
44
  require 'pik/which'
35
45
 
36
- require 'pik/search_path'
37
-
38
- require 'highline'
39
46
 
40
47
  PIK_HOME = Pathname.new( ENV['HOME'] || ENV['USERPROFILE'] ) + '.pik'
41
48
 
@@ -43,20 +43,20 @@ module Pik
43
43
  def add_interactive
44
44
  @hl.choose do |menu|
45
45
  menu.prompt = ""
46
- menu.choice('e]nter a path'){
46
+ menu.choice('e]nter a path') do
47
47
  dir = @hl.ask("Enter a path to a ruby/bin dir (enter to quit)")
48
- execute(dir) unless dir.empty? || !@hl.agree("Add '#{dir}'? [Yn] ")
48
+ execute(dir) unless dir.empty? || !@hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
49
49
  add_interactive
50
- }
51
- menu.choice('s]earch'){
50
+ end
51
+ menu.choice('s]earch') do
52
52
  search_dir = @hl.ask("Enter a search path")
53
53
  files = Which::Ruby.glob(search_dir + '**')
54
- files.each{|file|
54
+ files.uniq.each do |file|
55
55
  dir = File.dirname(file)
56
- add(dir) if @hl.agree("Add '#{dir}'? [Yn] ")
57
- }
56
+ add(dir) if @hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
57
+ end
58
58
  add_interactive
59
- }
59
+ end
60
60
  menu.choice('q]uit'){raise QuitError}
61
61
  end
62
62
 
@@ -23,35 +23,25 @@ module Pik
23
23
  end
24
24
  end
25
25
 
26
- def switch_path_to(new_ver)
27
- dir = Which::Ruby.find
28
- current_config = config[ find_config_from_path(dir) ]
26
+ def switch_path_to(other)
27
+ current = Which::Ruby.find
28
+
29
+ new_path = SearchPath.new(ENV['PATH'])
30
+ new_path.replace_or_add(current, other[:path])
31
+
32
+ # if there is currently a GEM_HOME, remove it's bin dir from the path
33
+ new_path.remove(Pathname.new(ENV['GEM_HOME']) + 'bin') if ENV['GEM_HOME']
34
+
35
+ # if the new version has a GEM_HOME, add it's bin dir to the path
36
+ new_path.add(Pathname.new(other[:gem_home]) + 'bin') if other[:gem_home]
29
37
 
30
- new_path = SearchPath.new(ENV['PATH']).replace_or_add(dir, new_ver[:path])
31
- if new_gem_home = new_ver[:gem_home]
32
-
33
- new_gem_bin = Pathname.new(new_gem_home) + 'bin'
34
-
35
- if current_gem_home = current_config[:gem_home]
36
- current_gem_bin = Pathname.new(current_gem_home) + 'bin'
37
- new_path.replace(current_gem_bin, new_gem_bin)
38
- else
39
- new_path.add(new_gem_bin)
40
- end
41
- else
42
- if current_gem_home = current_config[:gem_home]
43
- current_gem_bin = Pathname.new(current_gem_home) + 'bin'
44
- new_path.remove(current_gem_bin)
45
- end
46
- end
47
38
  @batch.set('PATH' => new_path.join )
48
39
  end
49
-
50
- def switch_gem_home_to(gem_home_dir)
51
- gem_home_dir ||= ''
52
- gem_path = Pathname.new(gem_home_dir).to_windows
53
- @batch.set('GEM_PATH' => gem_path )
54
- @batch.set('GEM_HOME' => gem_path )
40
+
41
+ def switch_gem_home_to(gem_home)
42
+ gem_home = Pathname(gem_home).to_windows rescue nil
43
+ @batch.set('GEM_PATH' => gem_home )
44
+ @batch.set('GEM_HOME' => gem_home )
55
45
  end
56
46
 
57
47
  def echo_ruby_version(path, verb='')
@@ -9,8 +9,8 @@ module Pik
9
9
 
10
10
  def execute
11
11
  msg = "Are you sure you want pik to implode? "
12
- msg << "This will remove '#{PIK_HOME.to_ruby}'. [Yn] "
13
- if @force || @hl.agree(msg)
12
+ msg << "This will remove '#{PIK_HOME.to_ruby}'."
13
+ if @force || @hl.agree(msg){|answer| answer.default = 'yes' }
14
14
  PIK_HOME.rmtree
15
15
  end
16
16
  end
@@ -58,7 +58,7 @@ SEP
58
58
  FileUtils.mkdir_p target
59
59
  extract_(file, target)
60
60
  else
61
- file = download_seven_zip
61
+ download_seven_zip
62
62
  extract(target, file)
63
63
  end
64
64
  end
@@ -80,9 +80,9 @@ SEP
80
80
 
81
81
  def download_seven_zip
82
82
  question = "You need the 7zip utility to extract this file.\n"
83
- question << "Would you like me to download it? [Yn]"
84
- if @hl.agree question
85
- uri = 'http://downloads.sourceforge.net/sevenzip/7za465.zip'
83
+ question << "Would you like me to download it? (yes/no)"
84
+ if @hl.agree(question){|answer| answer.default = 'yes' }
85
+ uri = 'http://downloads.sourceforge.net/sevenzip/7za465.zip'
86
86
  file = download(uri)
87
87
  Zip.fake_unzip(file.to_s, /\.exe|\.dll$/, PIK_BATCH.dirname.to_s)
88
88
  else
@@ -6,14 +6,14 @@ module Pik
6
6
  it "Removes a ruby location from pik."
7
7
  include ConfigFileEditor
8
8
 
9
- attr_reader :force
9
+ attr_reader :force, :quiet
10
10
 
11
11
  def execute
12
12
  to_remove = self.class.choose_from(@args, @config)
13
13
  raise QuitError unless to_remove
14
- if force || @hl.agree("Are you sure you'd like to remove '#{to_remove}'? [Yn] ")
14
+ if force || @hl.agree("Are you sure you'd like to remove '#{to_remove}'?"){|answer| answer.default = 'yes' }
15
15
  @config.delete(to_remove)
16
- @hl.say("#{to_remove} removed")
16
+ @hl.say("#{to_remove} removed.") unless quiet
17
17
  end
18
18
  end
19
19
 
@@ -22,6 +22,9 @@ module Pik
22
22
  options.on("--force", "-f", "Remove without prompting") do |value|
23
23
  @force = value
24
24
  end
25
+ options.on("--quiet", "-q", "Remove without a response") do |value|
26
+ @quiet = value
27
+ end
25
28
  end
26
29
 
27
30
  end
@@ -0,0 +1,39 @@
1
+
2
+ module Pik
3
+
4
+ class UnInstall < Command
5
+
6
+ aka :unin
7
+ it "Deletes a ruby version from the filesystem and removes it from Pik."
8
+
9
+ attr_reader :force
10
+
11
+ def execute
12
+ to_remove = self.class.choose_from(@args, @config)
13
+ raise QuitError unless to_remove
14
+ if force || @hl.agree("Are you sure you'd like to uninstall '#{to_remove}'?"){|answer| answer.default = 'yes' }
15
+ puts "** Deleting #{config[to_remove][:path].dirname}"
16
+ path = config[to_remove][:path].dirname
17
+ FileUtils.rm_rf(path) if path.exist?
18
+ remove
19
+ puts
20
+ @hl.say("#{to_remove} has been uninstalled.")
21
+ end
22
+ end
23
+
24
+ def remove
25
+ rm = Pik::Remove.new(@args + ['--force', '--quiet'], config)
26
+ rm.execute
27
+ rm.close
28
+ end
29
+
30
+ def command_options
31
+ super
32
+ options.on("--force", "-f", "Remove without prompting") do |value|
33
+ @force = value
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,4 +1,3 @@
1
- require 'open-uri'
2
1
 
3
2
  module Pik
4
3
 
@@ -54,14 +53,19 @@ module Pik
54
53
  end
55
54
 
56
55
  def versions
57
- vers = read.scan(@re).map{|v| v.reverse}
58
- vers.map!{ |name, path| [name, @url + path] }.flatten!
59
- Hash[*vers]
56
+ h = {}
57
+ Hpricot(read).search("a") do |a|
58
+ if a_href = a.attributes['href']
59
+ href, link, version = *a_href.match(@re)
60
+ h[version] = @url + link if version
61
+ end
62
+ end
63
+ h
60
64
  end
61
65
 
62
66
  def read
63
67
  uri = URI.parse(@url+@path)
64
- uri.read
68
+ uri.read rescue ''
65
69
  end
66
70
 
67
71
  def subclass
@@ -75,7 +79,7 @@ module Pik
75
79
  def initialize
76
80
  super
77
81
  @path = "/frs/?group_id=167"
78
- @re = /\"(.+ruby\-(.+)\-i386\-mingw32\.7z)\"/
82
+ @re = /(.+ruby\-(.+)\-i386\-mingw32\.7z)/
79
83
  end
80
84
 
81
85
  end
@@ -85,17 +89,18 @@ module Pik
85
89
  def initialize
86
90
  super
87
91
  @path = "/frs/?group_id=4359"
88
- @re = /\"(.+ironruby\-(\d\.\d\.\d)\.zip)\"/
92
+ @re = /(.+ironruby\-(\d\.\d\.\d)\.zip)/
89
93
  end
90
94
 
91
95
  end
92
96
 
93
97
  class JRuby < Base
94
98
 
99
+ # <a href='http://jruby.kenai.com/downloads/1.4.0RC3/jruby-bin-1.4.0RC3.zip'>
95
100
  def initialize
96
101
  @url = ''
97
102
  @path = "http://www.jruby.org/download"
98
- @re = /\<p.*\>\<a .*href\=\"(.+ruby-bin\-(.+)\.zip)\"/
103
+ @re = /(.+\-bin\-(.+)\.zip)/
99
104
  end
100
105
  end
101
106