Narnach-gems 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Wes Oldenbeuving
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ == Gems
2
+ Gems is a simple tool to manage sets of RubyGems. It can be used to install and uninstall large numbers of gems.
3
+ Gems was originally created to replicate a server's gems on my development machine in order to see if my
4
+ Rails code would not get into dependency issues.
5
+
6
+ == Recent changes
7
+
8
+ === Version 0.1.1
9
+ The install and uninstall actions now show a summary of the gems installed/uninstalled/failed.
10
+
11
+ === Version 0.1.0
12
+ First version as a gem.
13
+ Features available are:
14
+ * Install gems in a project
15
+ * Uninstall gems in a project
16
+ * Import 'gems list' dump as project
17
+ * Export project to 'gems list'-ish file
18
+ * List gems in project
19
+ * List projects
20
+
21
+ == Installation
22
+ === From gem
23
+ Use gem to install gems. The gem is located on github.
24
+ sudo gem install Narnach-gems -s http://gems.github.com
25
+ === From git
26
+ From the project root, use rake to install:
27
+ git clone git://github.com/Narnach/gems.git
28
+ cd gems
29
+ rake install
30
+ This will build the gem and install it for you.
31
+
32
+ == Usage
33
+ Output if 'gems help':
34
+ Syntax:
35
+ gems <action> <arguments>
36
+
37
+ Actions and arguments:
38
+ install <name>
39
+ Install all gems in project <name>.
40
+ uninstall <name>
41
+ Uninstall all gems in project <name>.
42
+ list <name>
43
+ List all gems in project <name>.
44
+ import <name> <file>
45
+ Import all gems in <file> into project <name>.
46
+ This will overwrite the gems currently in this project.
47
+ export <name> <file>
48
+ Export all gems in project <name> to <file>.
49
+ The file will be overwritten and can be parsed by the import action.
50
+ projects
51
+ List all stored project names.
52
+
53
+ == Examples
54
+ To store your current gems as project 'dev', do the following:
55
+ gem list > gems.dev
56
+ gems import dev gems.dev
57
+ To switch from project 'dev' to 'server', do the following:
58
+ gems uninstall dev
59
+ gems install server
60
+ To export project 'dev' to the file 'gems.dev', do the following:
61
+ gems export dev gems.dev
62
+
63
+ == About
64
+ Author:: Wes 'Narnach' Oldenbeuving (narnach@gmail.com)
65
+ Website:: http://www.github.com/Narnach/gems
66
+ Copyright:: Copyright (c) 2008 Wes Oldenbeuving
67
+ License:: MIT license. See MIT-LICENSE (in the gem directory) for license details.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "rake"
2
+ require "rake/clean"
3
+ require "rake/gempackagetask"
4
+ require 'rubygems'
5
+
6
+ ################################################################################
7
+ ### Gem
8
+ ################################################################################
9
+
10
+ begin
11
+ # Parse gemspec using the github safety level.
12
+ data = File.read('gems.gemspec')
13
+ spec = nil
14
+ Thread.new { spec = eval("$SAFE = 3\n%s" % data)}.join
15
+
16
+ # Create the gem tasks
17
+ Rake::GemPackageTask.new(spec) do |package|
18
+ package.gem_spec = spec
19
+ end
20
+ rescue Exception => e
21
+ printf "WARNING: Error caught (%s): %s\n", e.class.name, e.message
22
+ end
23
+
24
+ desc 'Package and install the gem for the current version'
25
+ task :install => :gem do
26
+ system "sudo gem install -l pkg/gems-%s.gem" % spec.version
27
+ end
data/bin/gems ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gems'
3
+
4
+ action = ARGV.shift.to_s.strip
5
+ project = ARGV.shift.to_s.strip
6
+
7
+ case action
8
+ when 'install'
9
+ gems = Gems.new project
10
+ gems.install
11
+ when 'uninstall'
12
+ gems = Gems.new project
13
+ gems.uninstall
14
+ when 'list'
15
+ gems = Gems.new project
16
+ gems.list
17
+ when 'import'
18
+ gems_config = GemsConfig.new(project)
19
+ gems_file = ARGV.shift.to_s.strip
20
+ gems_config.import_gems(gems_file)
21
+ when 'export'
22
+ gems_config = GemsConfig.new(project)
23
+ gems_file = ARGV.shift.to_s.strip
24
+ gems_config.export_gems(gems_file)
25
+ when 'projects'
26
+ gems_config = GemsConfig.new(nil)
27
+ gems_config.project_names.each do |project|
28
+ puts project
29
+ end
30
+ else 'help'
31
+ puts <<-EOS
32
+ Syntax:
33
+ gems <action> <arguments>
34
+
35
+ Actions and arguments:
36
+ install <name>
37
+ Install all gems in project <name>.
38
+ uninstall <name>
39
+ Uninstall all gems in project <name>.
40
+ list <name>
41
+ List all gems in project <name>.
42
+ import <name> <file>
43
+ Import all gems in <file> into project <name>.
44
+ This will overwrite the gems currently in this project.
45
+ export <name> <file>
46
+ Export all gems in project <name> to <file>.
47
+ The file will be overwritten and can be parsed by the import action.
48
+ projects
49
+ List all stored project names.
50
+ EOS
51
+ end
data/gems.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ # Project
3
+ s.name = 'gems'
4
+ s.summary = "Gems is a simple tool to manage sets of RubyGems."
5
+ s.description = "Gems is a simple tool to manage sets of RubyGems. It can be used to install and uninstall large numbers of gems."
6
+ s.version = '0.1.1'
7
+ s.date = '2008-08-19'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Wes Oldenbeuving"]
10
+ s.email = "narnach@gmail.com"
11
+ s.homepage = "http://www.github.com/Narnach/gems"
12
+
13
+ # Files
14
+ s.bindir = "bin"
15
+ s.executables = %w[gems]
16
+ s.require_path = "lib"
17
+ s.files = ['MIT-LICENSE', 'README.rdoc', 'Rakefile', 'bin/gems', 'lib/gems.rb', 'lib/gems_config.rb', 'lib/gems_parser.rb', 'gems.gemspec']
18
+ s.test_files = []
19
+
20
+ # rdoc
21
+ s.has_rdoc = true
22
+ s.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE]
23
+ s.rdoc_options << '--inline-source' << '--line-numbers' << '--main' << 'README.rdoc'
24
+
25
+ # Requirements
26
+ s.required_ruby_version = ">= 1.8.0"
27
+ end
data/lib/gems.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'gems_config'
2
+
3
+ class Gems
4
+ attr_reader :project, :gems, :gems_config
5
+
6
+ def initialize(project)
7
+ @project = project
8
+ @gems_config = GemsConfig.new(@project)
9
+ @gems = @gems_config.gems
10
+ end
11
+
12
+ def list
13
+ puts 'Gems in "%s":' % project
14
+ gems.each do |gemname, versions|
15
+ puts "%#{longest_gem_name_length}s %s" % [gemname, versions.join(", ")]
16
+ end
17
+ end
18
+
19
+ def install
20
+ puts "Installing all gems and versions in '%s'" % project
21
+ results = {}
22
+ each_gem_with_version do |gemname, version|
23
+ cmd = "sudo gem install --ignore-dependencies --no-rdoc --no-ri -v %s %s" % [version, gemname]
24
+ puts cmd
25
+ result = system(cmd)
26
+ results['%s-%s' % [gemname, version]] = result
27
+ end
28
+ successful = results.select {|gemname, success| success}
29
+ unsuccessful = results.select {|gemname, success| !success}
30
+ puts
31
+ puts "Successfully installed: %s" % successful.map{|ary| ary[0]}.sort.join(", ")
32
+ puts
33
+ puts "Failed to install: %s" % unsuccessful.map{|ary| ary[0]}.sort.join(", ")
34
+ end
35
+
36
+ def uninstall
37
+ puts "Uninstalling all gems and versions in '%s'" % project
38
+ results = {}
39
+ each_gem_with_version do |gemname, version|
40
+ cmd = "sudo gem uninstall --ignore-dependencies --executables -v %s %s" % [version, gemname]
41
+ puts cmd
42
+ result = system(cmd)
43
+ results['%s-%s' % [gemname, version]] = result
44
+ end
45
+ successful = results.select {|gemname, success| success}
46
+ unsuccessful = results.select {|gemname, success| !success}
47
+ puts
48
+ puts "Successfully uninstalled: %s" % successful.map{|ary| ary[0]}.sort.join(", ")
49
+ puts
50
+ puts "Failed to uninstall: %s" % unsuccessful.map{|ary| ary[0]}.sort.join(", ")
51
+ end
52
+
53
+ private
54
+
55
+ def each_gem_with_version(&block)
56
+ raise ArgumentError, 'No block provided' unless block
57
+ gems.each do |gemname, versions|
58
+ versions.each do |version|
59
+ block.call(gemname, version)
60
+ end
61
+ end
62
+ end
63
+
64
+ def longest_gem_name_length
65
+ gems.map{|ary| ary[0].size}.max
66
+ end
67
+ end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+ require 'gems_parser'
3
+
4
+ class GemsConfig
5
+ attr_reader :name
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+
11
+ def export_gems(file)
12
+ File.open(file,'wb') do |f|
13
+ gems.sort_by{|gemname, versions| gemname}.each do |gemname, versions|
14
+ f.puts "%s (%s)" % [gemname, versions.join(", ")]
15
+ end
16
+ end
17
+ end
18
+
19
+ def import_gems(file)
20
+ gems = GemsParser.new(file).gems
21
+ np = projects[name] ||= {}
22
+ np['gems'] = gems
23
+ save_config
24
+ end
25
+
26
+ def gems
27
+ project['gems']
28
+ end
29
+
30
+ def project_names
31
+ projects.keys.sort
32
+ end
33
+
34
+ protected
35
+
36
+ def config
37
+ @config ||= load_config
38
+ end
39
+
40
+ def project
41
+ projects[name]
42
+ end
43
+
44
+ def projects
45
+ config['projects'] ||= {}
46
+ end
47
+
48
+ private
49
+
50
+ def config_file
51
+ File.expand_path('~/.gems.yml')
52
+ end
53
+
54
+ def load_config
55
+ YAML.load_file(config_file)
56
+ rescue SystemCallError, ArgumentError
57
+ {}
58
+ end
59
+
60
+ def save_config
61
+ File.open(config_file, 'wb') {|f| f.puts(config.to_yaml)}
62
+ end
63
+ end
@@ -0,0 +1,40 @@
1
+ class GemsParser
2
+ attr_reader :file
3
+
4
+ def initialize(file)
5
+ @file = file
6
+ end
7
+
8
+ def gems
9
+ @gems ||= parse_gems
10
+ end
11
+
12
+ protected
13
+
14
+ def str
15
+ @str ||= read_file
16
+ end
17
+
18
+ private
19
+
20
+ def parse_gems
21
+ parsed_gems = []
22
+ str.each do |line|
23
+ gemname, *versions = line.split(" ")
24
+ next if gemname.to_s.size == 0
25
+ versions.each {|v| v.gsub!(/[^\d.]/,'')}
26
+ versions = versions.select {|v| v =~ /(\d+\.)+\d+/}
27
+ versions.flatten!
28
+ versions.compact!
29
+ versions.uniq!
30
+ next if versions.size == 0
31
+ parsed_gems << [gemname, versions]
32
+ end
33
+ return parsed_gems
34
+ end
35
+
36
+ def read_file
37
+ raise 'File does not exist: "%s"' % file unless File.exist?(file)
38
+ File.read(file)
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Narnach-gems
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Wes Oldenbeuving
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-19 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Gems is a simple tool to manage sets of RubyGems. It can be used to install and uninstall large numbers of gems.
17
+ email: narnach@gmail.com
18
+ executables:
19
+ - gems
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - MIT-LICENSE
25
+ files:
26
+ - MIT-LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - bin/gems
30
+ - lib/gems.rb
31
+ - lib/gems_config.rb
32
+ - lib/gems_parser.rb
33
+ - gems.gemspec
34
+ has_rdoc: true
35
+ homepage: http://www.github.com/Narnach/gems
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --inline-source
39
+ - --line-numbers
40
+ - --main
41
+ - README.rdoc
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.8.0
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Gems is a simple tool to manage sets of RubyGems.
63
+ test_files: []
64
+