toastyapps-gembox 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -5
- data/README.txt +0 -2
- data/lib/gembox.rb +32 -111
- metadata +4 -10
- data/lib/templates/bashrc +0 -7
- data/lib/templates/dispatch.rb +0 -114
- data/lib/templates/gemrc +0 -6
- data/lib/templates/shell.bash +0 -1
- data/test/test_gembox.rb +0 -27
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/lib/gembox.rb
CHANGED
@@ -1,115 +1,36 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'yaml'
|
3
|
-
require 'erb'
|
4
|
-
|
5
1
|
class Gembox
|
6
|
-
VERSION = '0.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
puts
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
File.open("#{@dir}/dispatch.rb", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/dispatch.rb").read).result(binding) } unless File.exists?("#{@dir}/dispatch.rb")
|
35
|
-
puts "Box #{box_name} has been created"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def list(args)
|
41
|
-
puts "Current Boxes:\n"
|
42
|
-
Dir.foreach("#{ENV['HOME']}/.gembox") do |file|
|
43
|
-
puts " #{file}" if file !~ /^\./ && File.directory?("#{ENV['HOME']}/.gembox/#{file}")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def delete(args)
|
48
|
-
args.each do |box_name|
|
49
|
-
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
50
|
-
if File.exists?(@dir)
|
51
|
-
FileUtils.rm_r(@dir)
|
52
|
-
puts "Box #{box_name} has been deleted"
|
53
|
-
else
|
54
|
-
puts "Box #{box_name} does not exists"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def shell(args)
|
60
|
-
box_name = args.shift
|
61
|
-
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
62
|
-
if File.exists?(@dir)
|
63
|
-
generate_gems_yaml("#{@dir}/gems.yaml")
|
64
|
-
system("sh #{@dir}/shell.bash")
|
65
|
-
else
|
66
|
-
puts "Box #{box_name} does not exist"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def generate_gems_yaml(file)
|
73
|
-
data = `gem query -d`.split("\n")
|
74
|
-
gemdata = {}
|
75
|
-
index = 'NULL'
|
76
|
-
in_installed_at = false
|
77
|
-
data.each do |line|
|
78
|
-
if line =~ /^[a-z]/i
|
79
|
-
index = line.split(' ')[0]
|
80
|
-
versions = line.match(/\((.*?)\)/).captures[0].split(', ')
|
81
|
-
gemdata[index] = {}
|
82
|
-
versions.each do |version|
|
83
|
-
gemdata[index][version] = ''
|
84
|
-
end
|
85
|
-
elsif line =~ /Installed at/ || in_installed_at
|
86
|
-
if line.match(/\((.*?)\):\s(.*)/)
|
87
|
-
in_installed_at = true
|
88
|
-
version, dir = line.match(/\((.*?)\):\s(.*)/).captures
|
89
|
-
gemdata[index][version] = dir
|
90
|
-
elsif line =~ /Installed at/
|
91
|
-
dir = line.match(/:\s(.*)/).captures[0]
|
92
|
-
gemdata[index][gemdata[index].keys[0]] = dir
|
93
|
-
else
|
94
|
-
in_installed_at = false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
File.open(file, "w") { |f| f.puts gemdata.to_yaml }
|
99
|
-
end
|
100
|
-
|
101
|
-
def load_config
|
102
|
-
@cfg = load_yaml(@cfg_path)
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
|
4
|
+
def self.create(args)
|
5
|
+
dir = Dir.new(Dir.pwd+"/"+args.shift).path
|
6
|
+
Dir.chdir(dir)
|
7
|
+
dir = Dir.pwd
|
8
|
+
FileUtils.mkdir_p "#{dir}/usr/bin"
|
9
|
+
FileUtils.mkdir_p "#{dir}/gems"
|
10
|
+
File.open("#{dir}/.gemrc", 'w') do |f|
|
11
|
+
f.puts "gempath:"
|
12
|
+
f.puts " - #{dir}/gems"
|
13
|
+
f.puts "gemhome: #{dir}/usr/bin"
|
14
|
+
end
|
15
|
+
File.open("#{dir}/.bashrc", "w") do |f|
|
16
|
+
f.puts "PS1=\"gembox:\\w> \""
|
17
|
+
f.puts "export PATH=#{dir}/usr/bin:\$PATH"
|
18
|
+
f.puts "alias gem='ruby #{dir}/dispatch.rb'"
|
19
|
+
f.puts "export GEM_PATH=#{dir}/gems"
|
20
|
+
f.puts "export GEM_HOME=#{dir}/gems"
|
21
|
+
end
|
22
|
+
File.open("#{dir}/shell.bash", "w") do |f|
|
23
|
+
f.puts "/usr/bin/env bash --rcfile #{dir}/.bashrc"
|
24
|
+
end
|
25
|
+
File.open("#{dir}/dispatch.rb", "w") do |f|
|
26
|
+
f.puts "#!/usr/bin/ruby"
|
27
|
+
f.puts "args=ARGV"
|
28
|
+
f.puts "command=args.shift"
|
29
|
+
f.puts "system(\"gem --config-file #{dir}/.gemrc #\{command\} #\{ARGV.join(' ')\}\")"
|
103
30
|
end
|
31
|
+
end
|
104
32
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
alias_method :sh, :shell
|
110
|
-
alias_method :del, :delete
|
111
|
-
alias_method :rm, :delete
|
112
|
-
alias_method :ls, :list
|
113
|
-
|
33
|
+
def self.shell(args)
|
34
|
+
system("sh shell.bash")
|
114
35
|
end
|
115
|
-
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toastyapps-gembox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Mongeau
|
@@ -12,7 +12,7 @@ cert_chain: []
|
|
12
12
|
date: 2009-03-18 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
description:
|
15
|
+
description: Create an interactive shell to use as a sandbox for managing gems
|
16
16
|
email:
|
17
17
|
- halogenandtoast@gmail.com
|
18
18
|
executables:
|
@@ -30,13 +30,8 @@ files:
|
|
30
30
|
- Rakefile
|
31
31
|
- bin/gembox
|
32
32
|
- lib/gembox.rb
|
33
|
-
- lib/templates/dispatch.rb
|
34
|
-
- lib/templates/bashrc
|
35
|
-
- lib/templates/gemrc
|
36
|
-
- lib/templates/shell.bash
|
37
|
-
- test/test_gembox.rb
|
38
33
|
has_rdoc: true
|
39
|
-
homepage: http://
|
34
|
+
homepage: http://halogenandtast.com
|
40
35
|
post_install_message:
|
41
36
|
rdoc_options:
|
42
37
|
- --main
|
@@ -61,6 +56,5 @@ rubyforge_project: gembox
|
|
61
56
|
rubygems_version: 1.2.0
|
62
57
|
signing_key:
|
63
58
|
specification_version: 2
|
64
|
-
summary:
|
59
|
+
summary: Create an interactive shell to use as a sandbox for managing gems
|
65
60
|
test_files:
|
66
|
-
- test/test_gembox.rb
|
data/lib/templates/bashrc
DELETED
data/lib/templates/dispatch.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
require 'rubygems'
|
3
|
-
require 'yaml'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
class Dispatch
|
7
|
-
|
8
|
-
DIR = "<%= @dir %>"
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def install(args)
|
12
|
-
system("gem --config-file #{DIR}/.gemrc install --bindir #{DIR}/usr/bin #{ARGV.join(' ')}")
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_config(args)
|
16
|
-
cfg_path = "#{ENV['HOME']}/.gembox/config.yml"
|
17
|
-
if File.exists?(cfg_path)
|
18
|
-
data = YAML.load(File.open(cfg_path).read)
|
19
|
-
if data['symlink']
|
20
|
-
data['symlink'].each do |symlink|
|
21
|
-
if `gem query -i -n #{symlink}`.chomp == 'false'
|
22
|
-
system("ruby #{DIR}/dispatch.rb symlink #{symlink}")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def unsymlink(args)
|
30
|
-
gem_name = args.shift
|
31
|
-
data = `gem query -d -n #{gem_name}`.strip.split("\n")
|
32
|
-
versions = []
|
33
|
-
data.each do |line|
|
34
|
-
if line =~ /^[a-z]/i
|
35
|
-
versions << line.match(/\((.*?)\)/).captures[0]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
if versions.length == 1
|
39
|
-
version = versions[0]
|
40
|
-
if `ls -la #{DIR}/gems/gems/ | grep #{gem_name}-#{version}` =~ /^l/
|
41
|
-
`rm #{DIR}/gems/gems/#{gem_name}-#{version} && rm #{DIR}/gems/specifications/#{gem_name}-#{version}.gemspec`
|
42
|
-
puts "Gem #{gem_name} is been unsymlinked"
|
43
|
-
else
|
44
|
-
puts "Gem #{gem_name} is installed, but not symlinked"
|
45
|
-
end
|
46
|
-
elsif versions.length > 1
|
47
|
-
puts "more"
|
48
|
-
else
|
49
|
-
puts "Gem #{gem_name} is not installed"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def symlink(args)
|
54
|
-
data = YAML.load(File.open("#{DIR}/gems.yaml").read)
|
55
|
-
args.each do |gem_name|
|
56
|
-
if data[gem_name] && data[gem_name].keys.length > 0
|
57
|
-
FileUtils.mkdir_p("#{DIR}/gems/gems/")
|
58
|
-
FileUtils.mkdir_p("#{DIR}/gems/specifications/")
|
59
|
-
versions = []
|
60
|
-
if data[gem_name].keys.length == 1
|
61
|
-
versions << data[gem_name].keys[0]
|
62
|
-
elsif data[gem_name].keys.length > 1
|
63
|
-
puts 'Select gem to symlink:'
|
64
|
-
index = 1
|
65
|
-
data[gem_name].keys.each do |key|
|
66
|
-
puts " #{index}. #{gem_name}-#{key}"
|
67
|
-
index += 1
|
68
|
-
end
|
69
|
-
puts " #{index}. All versions"
|
70
|
-
print "> "
|
71
|
-
choice = gets
|
72
|
-
if choice == index
|
73
|
-
versions = data[gem_name].keys
|
74
|
-
else
|
75
|
-
versions << data[gem_name].keys[choice.to_i - 1]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
versions.each do |version|
|
80
|
-
gemdir = data[gem_name][version]
|
81
|
-
gemname = gem_name+'-'+version
|
82
|
-
gem_file = gemdir + '/gems/' + gemname
|
83
|
-
spec_file = gemdir + '/specifications/' + gemname + '.gemspec'
|
84
|
-
unless File.exists?("#{DIR}/gems/gems/#{gemname}")
|
85
|
-
`ln -s #{gem_file} #{DIR}/gems/gems/#{gemname} && ln -s #{spec_file} #{DIR}/gems/specifications/#{gemname}.gemspec`
|
86
|
-
puts "Successfully symlinked #{gemname}"
|
87
|
-
else
|
88
|
-
puts "#{gemname} already exists"
|
89
|
-
end
|
90
|
-
|
91
|
-
# check dependencies
|
92
|
-
data = `gem dependency #{gem_name} -v #{version}`.chomp.split("\n")
|
93
|
-
data.shift
|
94
|
-
data.each do |dependency|
|
95
|
-
name = dependency.match(/\s+(.*?)\s\(/).captures[0]
|
96
|
-
symlink([name])
|
97
|
-
end
|
98
|
-
end
|
99
|
-
else
|
100
|
-
puts "Could not find gem #{gem_name}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def method_missing(method, *args)
|
106
|
-
# must be a gem commands
|
107
|
-
system("gem --config-file #{DIR}/.gemrc #{method} #{args.join(' ')}")
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
args=ARGV
|
113
|
-
command=args.shift
|
114
|
-
Dispatch.send(command, args)
|
data/lib/templates/gemrc
DELETED
data/lib/templates/shell.bash
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
/usr/bin/env bash --rcfile <%= @dir %>/.bashrc
|
data/test/test_gembox.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'spec'
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/gembox")
|
4
|
-
|
5
|
-
describe Gembox do
|
6
|
-
before(:each) do
|
7
|
-
@gb = Gembox.new
|
8
|
-
@cfg_file_path = File.expand_path(File.dirname(__FILE__)) + '/sample.gemboxrc.yml'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should load the current users config file" do
|
12
|
-
cfg = @gb.load_yaml @cfg_file_path
|
13
|
-
cfg.should_not be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should skip config file if not found" do
|
17
|
-
cfg = @gb.load_yaml "~/some/random/path"
|
18
|
-
cfg.should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should find .gemboxrc" do
|
22
|
-
home = `cd ~/ && pwd`.chomp
|
23
|
-
cfg = @gb.load_yaml "#{home}/.gemboxrc"
|
24
|
-
cfg.should_not be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|