toastyapps-gembox 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +11 -0
- data/README.txt +50 -0
- data/Rakefile +12 -0
- data/bin/gembox +9 -0
- data/lib/gembox.rb +115 -0
- data/lib/templates/bashrc +7 -0
- data/lib/templates/dispatch.rb +114 -0
- data/lib/templates/gemrc +6 -0
- data/lib/templates/shell.bash +1 -0
- data/test/test_gembox.rb +27 -0
- metadata +66 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= gembox
|
2
|
+
|
3
|
+
* http://www.halogenandtoast.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Gembox allows you to create a sandbox for installing and using gems using an interactive shell. Simple run "gembox create ." and then "gembox shell"
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* It's perfect ha ha
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
gembox create . && gembox shell
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* rubygems
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem install toastyapps-gembox --source http://gems.github.com
|
24
|
+
|
25
|
+
== USAGE
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
|
29
|
+
(The MIT License)
|
30
|
+
|
31
|
+
Copyright (c) 2009 FIX
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/gembox.rb'
|
6
|
+
|
7
|
+
Hoe.new('gembox', Gembox::VERSION) do |p|
|
8
|
+
# p.rubyforge_name = 'gemboxx' # if different than lowercase project name
|
9
|
+
p.developer('Matthew Mongeau', 'halogenandtoast@gmail.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
# vim: syntax=Ruby
|
data/bin/gembox
ADDED
data/lib/gembox.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
class Gembox
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
attr_accessor :dir, :cfg, :box_name
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@cfg_path = "#{ENV['HOME']}/.gembox/config.yml"
|
11
|
+
load_config
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def help(args)
|
16
|
+
puts File.read("../README.txt")
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(args)
|
20
|
+
args.each do |box_name|
|
21
|
+
@box_name = box_name
|
22
|
+
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
23
|
+
|
24
|
+
if File.exists?(@dir)
|
25
|
+
puts "Box #{box_name} already exists"
|
26
|
+
else
|
27
|
+
FileUtils.mkdir_p @dir # make gembox folder
|
28
|
+
FileUtils.mkdir_p "#{@dir}/usr/bin"
|
29
|
+
FileUtils.mkdir_p "#{@dir}/gems"
|
30
|
+
|
31
|
+
File.open("#{@dir}/.gemrc", 'w') { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/gemrc").read).result(binding) } unless File.exists?("#{@dir}/.gemrc")
|
32
|
+
File.open("#{@dir}/.bashrc", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/bashrc").read).result(binding) } unless File.exists?("#{@dir}/.bashrc")
|
33
|
+
File.open("#{@dir}/shell.bash", "w") {|f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/shell.bash").read).result(binding) } unless File.exists?("#{@dir}/shell.bash")
|
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)
|
103
|
+
end
|
104
|
+
|
105
|
+
def load_yaml path
|
106
|
+
File.exists?(path) ? YAML.load(File.open(path)) : nil
|
107
|
+
end
|
108
|
+
|
109
|
+
alias_method :sh, :shell
|
110
|
+
alias_method :del, :delete
|
111
|
+
alias_method :rm, :delete
|
112
|
+
alias_method :ls, :list
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,114 @@
|
|
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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/usr/bin/env bash --rcfile <%= @dir %>/.bashrc
|
data/test/test_gembox.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: toastyapps-gembox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Mongeau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-18 21:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
description: Gembox allows you to create a sandbox for installing and using gems using an interactive shell. Simple run "gembox create ." and then "gembox shell"
|
16
|
+
email:
|
17
|
+
- halogenandtoast@gmail.com
|
18
|
+
executables:
|
19
|
+
- gembox
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- Manifest.txt
|
25
|
+
- README.txt
|
26
|
+
files:
|
27
|
+
- History.txt
|
28
|
+
- Manifest.txt
|
29
|
+
- README.txt
|
30
|
+
- Rakefile
|
31
|
+
- bin/gembox
|
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
|
+
has_rdoc: true
|
39
|
+
homepage: http://www.halogenandtoast.com
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.txt
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: gembox
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Gembox allows you to create a sandbox for installing and using gems using an interactive shell
|
65
|
+
test_files:
|
66
|
+
- test/test_gembox.rb
|