vertiginous-pik 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +16 -0
- data/README.txt +81 -0
- data/Rakefile +13 -0
- data/bin/pik +22 -0
- data/lib/pik/batch_file.rb +67 -0
- data/lib/pik/checkup.rb +74 -0
- data/lib/pik/config.rb +20 -0
- data/lib/pik/runner.rb +221 -0
- data/lib/pik/search_path.rb +37 -0
- data/lib/pik/windows_env.rb +64 -0
- data/lib/pik/windows_file.rb +9 -0
- data/lib/pik.rb +22 -0
- data/messages/messages.yml +109 -0
- data/spec/batch_file_spec.rb +24 -0
- data/spec/search_path_spec.rb +159 -0
- metadata +91 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bin/pik
|
6
|
+
lib/pik.rb
|
7
|
+
lib/pik/batch_file.rb
|
8
|
+
lib/pik/checkup.rb
|
9
|
+
lib/pik/config.rb
|
10
|
+
lib/pik/runner.rb
|
11
|
+
lib/pik/search_path.rb
|
12
|
+
lib/pik/windows_env.rb
|
13
|
+
lib/pik/windows_file.rb
|
14
|
+
messages/messages.yml
|
15
|
+
spec/batch_file_spec.rb
|
16
|
+
spec/search_path_spec.rb
|
data/README.txt
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= pik
|
2
|
+
|
3
|
+
http://github.com/vertiginous/pik/tree/master
|
4
|
+
Gordon Thiesfeld
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
PIK, the ruby manager for windows
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
Currently, changes are to the open cmd session only. I haven't wired up the --global switch yet.
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
pik commands are:
|
17
|
+
|
18
|
+
add Add another ruby location to pik.
|
19
|
+
checkup Checks your environment for current Ruby best practices.
|
20
|
+
run Runs command with all version of ruby that pik is aware of.
|
21
|
+
rm Remove a ruby location from pik.
|
22
|
+
help Diskplays help topics.
|
23
|
+
|
24
|
+
|
25
|
+
For help on a particular command, use 'pik help COMMAND'.
|
26
|
+
|
27
|
+
>pik run "rake -V"
|
28
|
+
Running with 185: ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]
|
29
|
+
rake, version 0.8.7
|
30
|
+
|
31
|
+
Running with 186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
|
32
|
+
rake, version 0.8.7
|
33
|
+
|
34
|
+
Running with 186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]
|
35
|
+
rake, version 0.8.7
|
36
|
+
|
37
|
+
Running with 191: ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mingw32]
|
38
|
+
rake, version 0.8.3
|
39
|
+
|
40
|
+
Running with 191: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]
|
41
|
+
rake, version 0.8.7
|
42
|
+
|
43
|
+
== REQUIREMENTS:
|
44
|
+
|
45
|
+
Windows, Ruby, Rubygems
|
46
|
+
|
47
|
+
== INSTALL:
|
48
|
+
|
49
|
+
1. gem install pik
|
50
|
+
|
51
|
+
2. pik add path_to_ruby_bin
|
52
|
+
|
53
|
+
3. repeat step 2 as many times as necessary,
|
54
|
+
or use 'pik add -i'
|
55
|
+
|
56
|
+
4. pik run "gem install pik"
|
57
|
+
|
58
|
+
== LICENSE:
|
59
|
+
|
60
|
+
(The MIT License)
|
61
|
+
|
62
|
+
Copyright (c) 2009 FIX
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
65
|
+
a copy of this software and associated documentation files (the
|
66
|
+
'Software'), to deal in the Software without restriction, including
|
67
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
68
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
69
|
+
permit persons to whom the Software is furnished to do so, subject to
|
70
|
+
the following conditions:
|
71
|
+
|
72
|
+
The above copyright notice and this permission notice shall be
|
73
|
+
included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
76
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
77
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
78
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
79
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
80
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
81
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/pik.rb'
|
6
|
+
|
7
|
+
Hoe.new('pik', Pik::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'pik' # if different than lowercase project name
|
9
|
+
p.developer('Gordon Thiesfeld', 'gthiesfeld@gmail.com')
|
10
|
+
p.extra_deps = ['highline']
|
11
|
+
end
|
12
|
+
|
13
|
+
# vim: syntax=Ruby
|
data/bin/pik
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# pik 186
|
4
|
+
# pik 186 mingw
|
5
|
+
# pik 191 --system
|
6
|
+
# pik default
|
7
|
+
|
8
|
+
# pik config default=186 mingw
|
9
|
+
# pik config home
|
10
|
+
# pik config rubyopt=(on|off)
|
11
|
+
|
12
|
+
# pik checkup
|
13
|
+
|
14
|
+
# pik search
|
15
|
+
# pik add (path_to_ruby)
|
16
|
+
# pik help (command)
|
17
|
+
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'pik')
|
20
|
+
|
21
|
+
Pik::Runner.execute
|
22
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
class BatchFile
|
3
|
+
|
4
|
+
def self.open(file_name)
|
5
|
+
bf = new(file_name, :open)
|
6
|
+
yield bf if block_given?
|
7
|
+
bf
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :file_data, :file_name, :ruby_dir
|
11
|
+
|
12
|
+
def initialize(file_name, mode=:new)
|
13
|
+
@rubyw_exe = 'rubyw.exe'
|
14
|
+
@ruby_exe = 'ruby.exe'
|
15
|
+
@file_name = file_name
|
16
|
+
case mode
|
17
|
+
when :open
|
18
|
+
@file_data = File.read(@file_name).split("\n")
|
19
|
+
@fmode = 'r+'
|
20
|
+
when :new
|
21
|
+
@file_data = [header]
|
22
|
+
@fmode = 'w+'
|
23
|
+
end
|
24
|
+
yield self if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def bin_dir
|
28
|
+
WindowsFile.join(File.dirname(@ruby_exe))
|
29
|
+
end
|
30
|
+
|
31
|
+
def header
|
32
|
+
string = "@ECHO OFF\n\n"
|
33
|
+
string << ":: This batch file generated by Pik, the\n"
|
34
|
+
string << ":: Ruby Manager for Windows\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def ftype(files={ 'rbfile' => @ruby_exe, 'rbwfile' => @rubyw_exe })
|
38
|
+
files.sort.each do |filetype, open_with|
|
39
|
+
@file_data << "FTYPE #{filetype}=#{open_with} \"%1\" %*\n"
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def call(bat)
|
45
|
+
@file_data << "CALL #{bat}\n"
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def set(items)
|
50
|
+
items.each{|k,v| @file_data << "SET #{k}=#{v}" }
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def echo(string)
|
55
|
+
string = ' ' + string unless string == '.'
|
56
|
+
@file_data << "ECHO#{string}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
@file_data.join("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
def write
|
64
|
+
File.open(@file_name, @fmode){|f| f.puts self.to_s }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/lib/pik/checkup.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
class Pik
|
2
|
+
|
3
|
+
class Checkup
|
4
|
+
|
5
|
+
def initialize(text)
|
6
|
+
@text = text
|
7
|
+
# pp @text
|
8
|
+
@output = ["Checkup results:"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def check
|
12
|
+
home
|
13
|
+
rubyopt
|
14
|
+
path
|
15
|
+
pathext
|
16
|
+
|
17
|
+
puts
|
18
|
+
puts
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
ERB.new(@output.join("\n\n")).result
|
25
|
+
end
|
26
|
+
|
27
|
+
def rubyopt
|
28
|
+
unless WindowsEnv.user['rubyopt'].empty? && WindowsEnv.system['rubyopt'].empty?
|
29
|
+
fail('rubyopt')
|
30
|
+
else
|
31
|
+
pass('rubyopt')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def home
|
36
|
+
if WindowsEnv.user['home'].empty?
|
37
|
+
fail('home')
|
38
|
+
else
|
39
|
+
pass('home')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def path
|
44
|
+
dirs = (WindowsEnv.user['path'] + WindowsEnv.system['path']).split(';')
|
45
|
+
unless dirs.grep(/ruby/) == 1
|
46
|
+
fail('path')
|
47
|
+
else
|
48
|
+
pass('path')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def pathext
|
53
|
+
p_ext = WindowsEnv.system['pathext'].downcase
|
54
|
+
unless p_ext.include?('.rb') && p_ext.include?('.rbw')
|
55
|
+
fail('pathext')
|
56
|
+
else
|
57
|
+
pass('pathext')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def pass(test)
|
62
|
+
print '.'
|
63
|
+
$stdout.flush
|
64
|
+
@output << @text[test][:pass]
|
65
|
+
end
|
66
|
+
|
67
|
+
def fail(test)
|
68
|
+
print 'F'
|
69
|
+
@output << @text[test][:fail]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/lib/pik/config.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Pik
|
4
|
+
|
5
|
+
class Config < Hash
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@file = File.join(PIK_HOME, 'config.yml')
|
9
|
+
if File.exists? @file
|
10
|
+
self.update( YAML.load( File.read( @file ) ) )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def write
|
15
|
+
File.open(@file, 'w'){|f| f.puts YAML::dump(self) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/pik/runner.rb
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
class Pik
|
2
|
+
|
3
|
+
class Runner #< ::HighLine
|
4
|
+
|
5
|
+
def self.execute
|
6
|
+
new.execute
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@options = {}
|
11
|
+
@config = Config.new
|
12
|
+
@msg_file = File.join(File.dirname(__FILE__), '..', '..', 'messages','messages.yml')
|
13
|
+
@hl = HighLine.new
|
14
|
+
|
15
|
+
options, @commands = ARGV.partition{ |a| a =~ /^-/ }
|
16
|
+
options.each do |option|
|
17
|
+
case option
|
18
|
+
when '-g', '--global'
|
19
|
+
@options[:global] = true
|
20
|
+
when '-i', '--interactive'
|
21
|
+
@options[:interactive] = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
create(PIK_HOME) unless File.exist?(PIK_HOME)
|
28
|
+
|
29
|
+
init_config if @config.empty?
|
30
|
+
|
31
|
+
@pik_batch = BatchFile.new(File.join(PIK_HOME, "#{File.basename($0)}.bat") )
|
32
|
+
update_gem_batch
|
33
|
+
|
34
|
+
# begin
|
35
|
+
@commands = ['help'] if @commands.empty?
|
36
|
+
send(*@commands)
|
37
|
+
@config.write
|
38
|
+
@pik_batch.write
|
39
|
+
# rescue ArgumentError
|
40
|
+
# text(@commands.first)
|
41
|
+
# exit 1
|
42
|
+
# end
|
43
|
+
puts
|
44
|
+
end
|
45
|
+
|
46
|
+
def run(command)
|
47
|
+
current_dir = @config[get_version]
|
48
|
+
@config.sort.each do |version,ruby_dir|
|
49
|
+
@pik_batch.echo "Running with #{version}"
|
50
|
+
switch_path_to(ruby_dir)
|
51
|
+
@pik_batch.call command
|
52
|
+
@pik_batch.echo "."
|
53
|
+
end
|
54
|
+
switch_path_to(current_dir)
|
55
|
+
end
|
56
|
+
|
57
|
+
def add(path=::Config::CONFIG['bindir'])
|
58
|
+
return add_interactive if @options[:interactive]
|
59
|
+
if File.exist?("#{path}/ruby.exe")
|
60
|
+
version = get_version(path)
|
61
|
+
path = File.expand_path(path).gsub('\\','/')
|
62
|
+
puts "Adding: #{version}'\n Located at: #{path}\n"
|
63
|
+
@config[version] = path
|
64
|
+
else
|
65
|
+
help('no_ruby')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
alias :init_config :add
|
69
|
+
|
70
|
+
def rm(*patterns)
|
71
|
+
to_rm = choose_from(patterns)
|
72
|
+
if @hl.agree("Are you sure you'd like to remove '#{to_rm}'? [Yn] ")
|
73
|
+
@config.delete(to_rm)
|
74
|
+
@hl.say("#{to_rm} removed")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def checkup
|
79
|
+
puts Checkup.new(message).check
|
80
|
+
end
|
81
|
+
|
82
|
+
def config(*args)
|
83
|
+
item, value = args.shift.downcase.split('=')
|
84
|
+
case item
|
85
|
+
when 'home'
|
86
|
+
if value
|
87
|
+
set('HOME' => value)
|
88
|
+
else
|
89
|
+
set('HOME' => "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}")
|
90
|
+
end
|
91
|
+
when 'rubyopt'
|
92
|
+
case value
|
93
|
+
when 'on' then set('RUBYOPT' => '-rubygems')
|
94
|
+
when 'off' then set('RUBYOPT' => nil)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def list
|
100
|
+
puts @config.keys.sort
|
101
|
+
end
|
102
|
+
alias :ls :list
|
103
|
+
|
104
|
+
def switch(*patterns)
|
105
|
+
new_ver = choose_from(patterns)
|
106
|
+
if new_ver
|
107
|
+
@hl.say "Switching to #{new_ver}"
|
108
|
+
switch_path_to(@config[new_ver])
|
109
|
+
else
|
110
|
+
abort
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def help(arg='help')
|
115
|
+
@hl.say(message[arg])
|
116
|
+
end
|
117
|
+
|
118
|
+
def message
|
119
|
+
@messages ||= YAML.load(File.read(@msg_file))
|
120
|
+
end
|
121
|
+
|
122
|
+
def method_missing(meth)
|
123
|
+
if @config[meth]
|
124
|
+
switch[meth]
|
125
|
+
else
|
126
|
+
abort "The command #{meth} isn't recognized"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def switch_path_to(ruby_dir)
|
133
|
+
dir = current_dir.gsub('/', '\\')
|
134
|
+
new_path = SearchPath.new(ENV['PATH']).replace_or_add(dir, ruby_dir).join
|
135
|
+
@pik_batch.set('PATH' => WindowsFile.join(new_path) )
|
136
|
+
end
|
137
|
+
|
138
|
+
def add_interactive
|
139
|
+
@options.delete(:interactive)
|
140
|
+
@hl.choose do |menu|
|
141
|
+
menu.prompt = ""
|
142
|
+
menu.choice('e]nter a path'){
|
143
|
+
dir = @hl.ask("Enter a path to a ruby/bin dir (enter to quit)")
|
144
|
+
add(dir) unless dir.empty? || !@hl.agree("Add '#{dir}'? [Yn] ")
|
145
|
+
add_interactive
|
146
|
+
}
|
147
|
+
menu.choice('s]earch'){
|
148
|
+
search_dir = @hl.ask("Enter a search path")
|
149
|
+
files = Dir[File.join(search_dir, '**','ruby.exe').gsub('\\','/')]
|
150
|
+
files.each{|file|
|
151
|
+
dir = File.dirname(file)
|
152
|
+
add(dir) if @hl.agree("Add '#{dir}'? [Yn] ")
|
153
|
+
}
|
154
|
+
add_interactive
|
155
|
+
}
|
156
|
+
menu.choice('q]uit')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def choose_from(patterns)
|
161
|
+
if patterns.empty?
|
162
|
+
possibles = @config.keys
|
163
|
+
else
|
164
|
+
possibles = patterns.map{|p| @config.keys.grep(Regexp.new(p)) }
|
165
|
+
possibles = possibles.inject{|m,v| m & v }.flatten.uniq
|
166
|
+
end
|
167
|
+
|
168
|
+
case possibles.size
|
169
|
+
when 0
|
170
|
+
@hl.say 'Nothing matches:'
|
171
|
+
return nil
|
172
|
+
when 1
|
173
|
+
return possibles.first
|
174
|
+
else
|
175
|
+
@hl.say('Select which Ruby you want:')
|
176
|
+
ver = @hl.choose(*possibles)
|
177
|
+
return ver
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def get_version(path=current_dir)
|
182
|
+
ruby = File.join(path, 'ruby.exe')
|
183
|
+
ruby_ver = `#{path}/ruby.exe -v`
|
184
|
+
ruby_ver =~ /ruby (\d\.\d\.\d)/
|
185
|
+
major = $1.gsub('.','')
|
186
|
+
"#{major}: #{ruby_ver.strip}"
|
187
|
+
end
|
188
|
+
|
189
|
+
def current_dir
|
190
|
+
::RbConfig::CONFIG['bindir']
|
191
|
+
end
|
192
|
+
|
193
|
+
def set(items)
|
194
|
+
items.each do |k, v|
|
195
|
+
@pik_batch.set(k => v)
|
196
|
+
WindowsEnv.user.set(k => v) if @options[:global]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def create(home)
|
201
|
+
puts "creating #{home}"
|
202
|
+
FileUtils.mkpath(home)
|
203
|
+
end
|
204
|
+
|
205
|
+
def update_gem_batch
|
206
|
+
BatchFile.open("#{$0}.bat") do |batch|
|
207
|
+
case batch.file_data.last
|
208
|
+
when Regexp.new( PIK_HOME.gsub(/\\/, '\&\&') )
|
209
|
+
puts batch.file_data.last
|
210
|
+
when /call/i
|
211
|
+
batch.file_data.pop
|
212
|
+
batch.call("\"#{WindowsFile.join(@pik_batch.file_name)}\"").write
|
213
|
+
else
|
214
|
+
batch.call("\"#{WindowsFile.join(@pik_batch.file_name)}\"").write
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
class SearchPath
|
3
|
+
|
4
|
+
def initialize(path)
|
5
|
+
@path = path.split(';')
|
6
|
+
end
|
7
|
+
|
8
|
+
def replace(old, new)
|
9
|
+
@path.map!{|dir|
|
10
|
+
case dir
|
11
|
+
when old
|
12
|
+
new
|
13
|
+
else
|
14
|
+
dir
|
15
|
+
end
|
16
|
+
}.uniq!
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def add(new)
|
21
|
+
@path << new
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def replace_or_add(old, new)
|
26
|
+
old_path = @path.dup
|
27
|
+
replace(old, new)
|
28
|
+
add(new) if @path == old_path
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def join
|
33
|
+
@path.join(';')
|
34
|
+
end
|
35
|
+
alias :to_s :join
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'win32ole'
|
2
|
+
|
3
|
+
class WindowsEnv
|
4
|
+
|
5
|
+
def self.system
|
6
|
+
@system ||= new('SYSTEM', shell)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.user
|
10
|
+
@user ||= new('User', shell)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(account, shell)
|
14
|
+
@env = shell.environment(account)
|
15
|
+
end
|
16
|
+
|
17
|
+
def set(items)
|
18
|
+
items.each{|k,v| self[k] = v }
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](name)
|
22
|
+
@env.item(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def []=(name, other)
|
26
|
+
if other == nil
|
27
|
+
@env.remove(name)
|
28
|
+
else
|
29
|
+
@env.setproperty('item', name, other)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_key?(key)
|
34
|
+
!!self[key]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.shell
|
40
|
+
@shell ||= WIN32OLE.new('WScript.Shell')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# env = WindowsEnv.user
|
46
|
+
|
47
|
+
# home = env['home']
|
48
|
+
# p home
|
49
|
+
|
50
|
+
# env['home'] = nil
|
51
|
+
|
52
|
+
# p env['home']
|
53
|
+
|
54
|
+
# env['rubyopt'] = '-rubygems'
|
55
|
+
|
56
|
+
# env['home'] = home
|
57
|
+
# p env['home']
|
58
|
+
|
59
|
+
# p env['path']
|
60
|
+
|
61
|
+
# p env.has_key?('path')
|
62
|
+
# p env.has_key?('rubyopt')
|
63
|
+
|
64
|
+
|
data/lib/pik.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pik
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
end
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'erb'
|
8
|
+
require 'highline'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
require 'pik/runner'
|
13
|
+
require 'pik/config'
|
14
|
+
require 'pik/checkup'
|
15
|
+
require 'pik/windows_file'
|
16
|
+
require 'pik/windows_env'
|
17
|
+
require 'pik/batch_file'
|
18
|
+
require 'pik/search_path'
|
19
|
+
|
20
|
+
PIK_HOME = File.join( (ENV['HOME'] || ENV['USERPROFILE']) , '.pik')
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
config: |-
|
3
|
+
this is help for the config command
|
4
|
+
<%= File.basename($0) %> config default=186 mingw
|
5
|
+
<%= File.basename($0) %> config home
|
6
|
+
<%= File.basename($0) %> config rubyopt=(on|off)
|
7
|
+
|
8
|
+
add: |-
|
9
|
+
<%= File.basename($0) %> add [-i]|[path_to_ruby]
|
10
|
+
|
11
|
+
<%= File.basename($0) %> add path_to_ruby Adds the path if ruby.exe is found.
|
12
|
+
<%= File.basename($0) %> add -i Opens up interactive mode.
|
13
|
+
|
14
|
+
|
15
|
+
checkup: |-
|
16
|
+
<%= File.basename($0) %> checkup
|
17
|
+
|
18
|
+
list: <%= File.basename($0) %> list
|
19
|
+
ls: |-
|
20
|
+
<%= File.basename($0) %> ls
|
21
|
+
an alias for the list command.
|
22
|
+
see pik help list
|
23
|
+
|
24
|
+
rm: |-
|
25
|
+
<%= File.basename($0) %> rm [patern1 pattern2 ... pattern*]
|
26
|
+
|
27
|
+
Removes the
|
28
|
+
|
29
|
+
run: |-
|
30
|
+
<%= File.basename($0) %> run "command args"
|
31
|
+
|
32
|
+
rm: |-
|
33
|
+
<%= File.basename($0) %> rm
|
34
|
+
|
35
|
+
Searches the current drive for ruby
|
36
|
+
installations, and prompts you if you want to add them
|
37
|
+
|
38
|
+
commands: |-
|
39
|
+
|
40
|
+
<%= File.basename($0) %> commands are:
|
41
|
+
|
42
|
+
add Add another ruby location to <%= File.basename($0) %>.
|
43
|
+
checkup Checks your environment for current Ruby best practices.
|
44
|
+
list|ls Lists ruby versions that <%= File.basename($0) %> is aware of.
|
45
|
+
run Runs command with all version of ruby that <%= File.basename($0) %> is aware of.
|
46
|
+
rm Remove a ruby location from <%= File.basename($0) %>.
|
47
|
+
help Displays help topics.
|
48
|
+
|
49
|
+
|
50
|
+
For help on a particular command, use '<%= File.basename($0) %> help COMMAND'.
|
51
|
+
|
52
|
+
help: |-
|
53
|
+
This is the over all help file
|
54
|
+
|
55
|
+
To get help with a command
|
56
|
+
|
57
|
+
<%= File.basename($0) %> help (command)
|
58
|
+
|
59
|
+
To list all commands:
|
60
|
+
|
61
|
+
<%= File.basename($0) %> help commands
|
62
|
+
|
63
|
+
no_text: No text exists for the command '<%= command %>'
|
64
|
+
|
65
|
+
rubyopt:
|
66
|
+
:fail: |-
|
67
|
+
FAIL
|
68
|
+
The 'rubyopt' environment variable is set. Consider turning this off
|
69
|
+
by running 'pik config rubyopt=off'.
|
70
|
+
|
71
|
+
|
72
|
+
:pass: |-
|
73
|
+
PASS
|
74
|
+
The 'rubyopt' environment variable is not set.
|
75
|
+
|
76
|
+
home:
|
77
|
+
:fail: |-
|
78
|
+
FAIL
|
79
|
+
The 'home' environment variable is not set. Consider adding this
|
80
|
+
by running 'pik config home' to set it to '<%= ENV['homedrive']}#{ENV['homepath'] %>'
|
81
|
+
or 'pik config home=(another_path)' to set it to something else.
|
82
|
+
|
83
|
+
:pass: |-
|
84
|
+
PASS
|
85
|
+
The 'home' environment variable is set.
|
86
|
+
|
87
|
+
|
88
|
+
path:
|
89
|
+
:fail: |-
|
90
|
+
FAIL
|
91
|
+
You have more than one ruby path in your system path.
|
92
|
+
Consider fixing this.
|
93
|
+
|
94
|
+
:pass: |-
|
95
|
+
PASS
|
96
|
+
Your path has only one path to ruby.exe.
|
97
|
+
|
98
|
+
pathext:
|
99
|
+
:fail: |-
|
100
|
+
FAIL
|
101
|
+
The .rb and .rbw file extensions are missing from the pathext environment variable.
|
102
|
+
You can add them by running 'pik config pathext'
|
103
|
+
|
104
|
+
:pass: |-
|
105
|
+
PASS
|
106
|
+
The pathext environment variable contains the .rb and .rbw file extensions.
|
107
|
+
|
108
|
+
no_ruby: This is not a valid path to ruby.exe
|
109
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'lib/pik/windows_file'
|
2
|
+
require 'lib/pik/batch_file'
|
3
|
+
require 'lib/pik/search_path'
|
4
|
+
|
5
|
+
describe BatchFile do
|
6
|
+
|
7
|
+
it "should have a header" do
|
8
|
+
string = "@ECHO OFF\n\n"
|
9
|
+
string << ":: This batch file generated by Pik, the\n"
|
10
|
+
string << ":: Ruby Manager for Windows\n"
|
11
|
+
BatchFile.new('pik.bat').to_s.should == string
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should generate an ftype command for ruby.exe and rubyw.exe" do
|
15
|
+
bf = BatchFile.new('pik.bat')
|
16
|
+
bf.ftype.to_s.should match /FTYPE rbfile\=ruby\.exe \"%1\" \%\*\n\nFTYPE rbwfile\=rubyw\.exe \"\%1\" \%\*/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should generate a path command with the updated ruby path" do
|
20
|
+
bf = BatchFile.new('pik.bat')
|
21
|
+
bf.set('PATH' => "C:\\ruby\\191\\bin").to_s.should match /SET PATH\=C:\\ruby\\191\\bin/
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'lib/pik/search_path'
|
2
|
+
|
3
|
+
describe SearchPath do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
7
|
+
path << 'C:\bin;'
|
8
|
+
path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
9
|
+
path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
10
|
+
path << 'C:\windows\system32;'
|
11
|
+
path << 'C:\windows\system;'
|
12
|
+
path << 'C:\Program Files\Subversion\bin;'
|
13
|
+
path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
14
|
+
path << 'C:\Program Files\Common Files\Lenovo;'
|
15
|
+
path << 'C:\Program Files\QuickTime\QTSystem\;'
|
16
|
+
path << 'C:\Program Files\Git\cmd;'
|
17
|
+
path << 'C:\Program Files\jEdit;'
|
18
|
+
path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
19
|
+
path << 'C:\ruby\186-mswin32\bin;'
|
20
|
+
path << 'C:\Program Files\Putty'
|
21
|
+
@path = SearchPath.new(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#replace' do
|
25
|
+
it "should replace one element with another using a regex" do
|
26
|
+
path = 'C:\ruby\191\bin'
|
27
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
28
|
+
new_path << 'C:\bin;'
|
29
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
30
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
31
|
+
new_path << 'C:\windows\system32;'
|
32
|
+
new_path << 'C:\windows\system;'
|
33
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
34
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
35
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
36
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
37
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
38
|
+
new_path << 'C:\Program Files\jEdit;'
|
39
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
40
|
+
new_path << 'C:\ruby\191\bin;'
|
41
|
+
new_path << 'C:\Program Files\Putty'
|
42
|
+
updated_path = @path.replace(/ruby/i, path).join
|
43
|
+
updated_path.should == new_path
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should replace one element with another using a string" do
|
47
|
+
path = 'C:\ruby\191\bin'
|
48
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
49
|
+
new_path << 'C:\bin;'
|
50
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
51
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
52
|
+
new_path << 'C:\windows\system32;'
|
53
|
+
new_path << 'C:\windows\system;'
|
54
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
55
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
56
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
57
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
58
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
59
|
+
new_path << 'C:\Program Files\jEdit;'
|
60
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
61
|
+
new_path << 'C:\ruby\191\bin;'
|
62
|
+
new_path << 'C:\Program Files\Putty'
|
63
|
+
updated_path = @path.replace('C:\ruby\186-mswin32\bin', path).join
|
64
|
+
updated_path.should == new_path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#add' do
|
69
|
+
it "should add an element to the end" do
|
70
|
+
path = 'C:\ruby\191\bin'
|
71
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
72
|
+
new_path << 'C:\bin;'
|
73
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
74
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
75
|
+
new_path << 'C:\windows\system32;'
|
76
|
+
new_path << 'C:\windows\system;'
|
77
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
78
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
79
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
80
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
81
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
82
|
+
new_path << 'C:\Program Files\jEdit;'
|
83
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
84
|
+
new_path << 'C:\ruby\186-mswin32\bin;'
|
85
|
+
new_path << 'C:\Program Files\Putty;'
|
86
|
+
new_path << 'C:\ruby\191\bin'
|
87
|
+
@path.add(path)
|
88
|
+
@path.join.should == new_path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#replace_or_add' do
|
93
|
+
it "should replace one element with another using a regex" do
|
94
|
+
path = 'C:\ruby\191\bin'
|
95
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
96
|
+
new_path << 'C:\bin;'
|
97
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
98
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
99
|
+
new_path << 'C:\windows\system32;'
|
100
|
+
new_path << 'C:\windows\system;'
|
101
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
102
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
103
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
104
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
105
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
106
|
+
new_path << 'C:\Program Files\jEdit;'
|
107
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
108
|
+
new_path << 'C:\ruby\191\bin;'
|
109
|
+
new_path << 'C:\Program Files\Putty'
|
110
|
+
@path.replace_or_add(/ruby/i, path)
|
111
|
+
@path.join.should == new_path
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should replace one element with another using a string" do
|
115
|
+
path = 'C:\ruby\191\bin'
|
116
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
117
|
+
new_path << 'C:\bin;'
|
118
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
119
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
120
|
+
new_path << 'C:\windows\system32;'
|
121
|
+
new_path << 'C:\windows\system;'
|
122
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
123
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
124
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
125
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
126
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
127
|
+
new_path << 'C:\Program Files\jEdit;'
|
128
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
129
|
+
new_path << 'C:\ruby\191\bin;'
|
130
|
+
new_path << 'C:\Program Files\Putty'
|
131
|
+
@path.replace_or_add('C:\ruby\186-mswin32\bin', path)
|
132
|
+
@path.join.should == new_path
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should add an element to the end if it doesn't already exist" do
|
136
|
+
path = 'C:\xray\yankee\zebra'
|
137
|
+
new_path = 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
138
|
+
new_path << 'C:\bin;'
|
139
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
140
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
141
|
+
new_path << 'C:\windows\system32;'
|
142
|
+
new_path << 'C:\windows\system;'
|
143
|
+
new_path << 'C:\Program Files\Subversion\bin;'
|
144
|
+
new_path << 'C:\Program Files\MySQL\MySQL Server 5.0\bin;'
|
145
|
+
new_path << 'C:\Program Files\Common Files\Lenovo;'
|
146
|
+
new_path << 'C:\Program Files\QuickTime\QTSystem\;'
|
147
|
+
new_path << 'C:\Program Files\Git\cmd;'
|
148
|
+
new_path << 'C:\Program Files\jEdit;'
|
149
|
+
new_path << 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\;'
|
150
|
+
new_path << 'C:\ruby\186-mswin32\bin;'
|
151
|
+
new_path << 'C:\Program Files\Putty;'
|
152
|
+
new_path << 'C:\xray\yankee\zebra'
|
153
|
+
@path.replace_or_add(/xray/i, path)
|
154
|
+
@path.join.should == new_path
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vertiginous-pik
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gordon Thiesfeld
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-02 00:00:00 -07:00
|
13
|
+
default_executable: pik
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: highline
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.12.2
|
34
|
+
version:
|
35
|
+
description: PIK, the ruby manager for windows
|
36
|
+
email:
|
37
|
+
- gthiesfeld@gmail.com
|
38
|
+
executables:
|
39
|
+
- pik
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.txt
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.txt
|
50
|
+
- Rakefile
|
51
|
+
- bin/pik
|
52
|
+
- lib/pik.rb
|
53
|
+
- lib/pik/batch_file.rb
|
54
|
+
- lib/pik/checkup.rb
|
55
|
+
- lib/pik/config.rb
|
56
|
+
- lib/pik/runner.rb
|
57
|
+
- lib/pik/search_path.rb
|
58
|
+
- lib/pik/windows_env.rb
|
59
|
+
- lib/pik/windows_file.rb
|
60
|
+
- messages/messages.yml
|
61
|
+
- spec/batch_file_spec.rb
|
62
|
+
- spec/search_path_spec.rb
|
63
|
+
has_rdoc: false
|
64
|
+
homepage: http://github.com/vertiginous/pik/tree/master
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --main
|
68
|
+
- README.txt
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: pik
|
86
|
+
rubygems_version: 1.2.0
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: PIK, the ruby manager for windows
|
90
|
+
test_files: []
|
91
|
+
|