komonzu 0.2.0

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.
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rbenv-version
6
+ vendor
7
+ .vagrant
8
+ Vagrantfile
9
+ solo.rb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,7 @@
1
+ Meta
2
+ ----
3
+
4
+ Derived from the [Heroku gem](https://github.com/heroku/heroku), copyright Heroku, which is released under the MIT license.
5
+
6
+ Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
7
+ <http://github.com/mlinderm/komonzu>
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'komonzu'
3
+ require 'komonzu/cli'
4
+
5
+ begin
6
+
7
+ Komonzu::CLI.start(ARGV)
8
+
9
+ rescue StandardError => e
10
+ shell = Thor::Base.shell.new
11
+ shell.say_status('Error', e.to_s, :red)
12
+ exit 1
13
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "komonzu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "komonzu"
7
+ s.version = Komonzu::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Linderman"]
10
+ s.email = ["michael.linderman@mssm.edu"]
11
+ s.homepage = "http://komonzu.mssm.edu"
12
+ s.summary = %q{Client library and CLI to manage Komonzu.}
13
+ s.description = %q{Client library and command line tool to manage projects and applications on Komonzu.}
14
+
15
+ s.add_runtime_dependency "thor"
16
+
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "contest", "~> 0.1.3"
19
+ s.add_development_dependency "mocha", "~> 0.9.8"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'komonzu/config'
2
+ require 'komonzu/client'
@@ -0,0 +1,33 @@
1
+ require 'thor'
2
+
3
+ module Komonzu
4
+ module Command
5
+ autoload :Base, 'komonzu/commands/base'
6
+ autoload :GroupBase, 'komonzu/commands/group'
7
+ end
8
+ end
9
+
10
+
11
+ module Komonzu
12
+ class CLI < Thor
13
+ include Thor::Actions
14
+
15
+ def self.register(klass, name, usage, description, opts=nil)
16
+ opts ||= {}
17
+ if klass <= Command::GroupBase
18
+ # A subclass of GroupBase is a subcommand, since it contains
19
+ # many smaller commands within it.
20
+ desc usage, description, opts
21
+ subcommand name, klass
22
+ elsif klass <= Command::Base
23
+ # A subclass of Base is a single command, since it
24
+ # is invoked as a whole (as Thor::Group)
25
+ desc usage, description, opts
26
+ define_method(name) { |*args| invoke klass, args }
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |c| require c }
@@ -0,0 +1,15 @@
1
+ require 'komonzu/version'
2
+
3
+ # A Ruby class to call the Komonzu REST API.
4
+
5
+ class Komonzu::Client
6
+
7
+ def self.version
8
+ Komonzu::VERSION
9
+ end
10
+
11
+ def self.gem_version_string
12
+ "komonzu-gem/#{version}"
13
+ end
14
+
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'thor/group'
2
+
3
+ module Komonzu
4
+ module Command
5
+
6
+ class Base < Thor::Group
7
+ include Thor::Actions
8
+
9
+ def self.register(usage, description, opts=nil)
10
+ desc description
11
+ CLI.register(self, extract_name_from_usage(usage), usage, desc, opts)
12
+ end
13
+
14
+ protected
15
+
16
+ # Extracts the name of the command from a usage string. Example:
17
+ # `init [box_name] [box_url]` becomes just `init`.
18
+ def self.extract_name_from_usage(usage)
19
+ /^([-_a-zA-Z0-9]+)(\s+(.+?))?$/.match(usage).to_a[1]
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ module Komonzu
2
+ module Command
3
+
4
+ class GroupBase < Thor
5
+ include Thor::Actions
6
+
7
+ def self.register(name, description, opts=nil)
8
+ @_name = name
9
+ CLI.register(self, @_name, name, description, opts)
10
+ end
11
+
12
+ protected
13
+
14
+ # Override the basename to include the subcommand name.
15
+ def self.basename
16
+ "#{super} #{@_name}"
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'tempfile'
3
+
4
+ module Komonzu
5
+ module Command
6
+ class UseasCommand < GroupBase
7
+ register "useas", "Commands to configure a running sandbox"
8
+
9
+ class_option :config,
10
+ :aliases => '-c',
11
+ :type => :string,
12
+ :default => Komonzu::Config.platform_specific_path('/etc/chef/solo.rb'),
13
+ :banner => "The chef configuration file to use"
14
+
15
+ desc "R", "Install R (and R packages)"
16
+ method_option :packages, :aliases => '-p', :type => :array, :banner => "R packages to install"
17
+ def R
18
+ provision({
19
+ 'R' => { 'packages' => options[:packages] || [] },
20
+ 'run_list' => ['recipe[r]']
21
+ })
22
+ end
23
+
24
+
25
+ private
26
+
27
+ def provision(attributes)
28
+ file = Tempfile.new(['node','.json'])
29
+ begin
30
+ file.write(attributes.to_json)
31
+ file.close
32
+
33
+ if !run("chef-solo -l info -j #{file.path} -c #{options[:config]}")
34
+ say(<<EOM)
35
+ Do you have permission to configure this machine? Try using sudo:
36
+ sudo komonzu #{ARGV.join(' ')}
37
+ EOM
38
+ raise RuntimeError, "'use as' configuration failed"
39
+ end
40
+ ensure
41
+ file.close(true)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ module Komonzu
2
+ module Command
3
+ class VersionCommand < Base
4
+ register "version", "Print Komonzu version"
5
+
6
+ def version
7
+ say Komonzu::VERSION
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Komonzu
2
+ class Config
3
+
4
+ def self.platform_specific_path(path)
5
+ if RUBY_PLATFORM =~ /mswin|mingw|windows/
6
+ # Turns /etc/chef/client.rb into C:/chef/client.rb (and then changes / to \)
7
+ path = File.join(ENV['SYSTEMDRIVE'], path.split('/')[2..-1])
8
+ path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
9
+ end
10
+ path
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Komonzu
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: komonzu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Linderman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70135952075000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70135952075000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70135952072240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70135952072240
36
+ - !ruby/object:Gem::Dependency
37
+ name: contest
38
+ requirement: &70135952068860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.3
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70135952068860
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &70135952066480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.8
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70135952066480
58
+ description: Client library and command line tool to manage projects and applications
59
+ on Komonzu.
60
+ email:
61
+ - michael.linderman@mssm.edu
62
+ executables:
63
+ - komonzu
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - README.md
70
+ - Rakefile
71
+ - bin/komonzu
72
+ - komonzu.gemspec
73
+ - lib/komonzu.rb
74
+ - lib/komonzu/cli.rb
75
+ - lib/komonzu/client.rb
76
+ - lib/komonzu/commands/base.rb
77
+ - lib/komonzu/commands/group.rb
78
+ - lib/komonzu/commands/useas.rb
79
+ - lib/komonzu/commands/version.rb
80
+ - lib/komonzu/config.rb
81
+ - lib/komonzu/version.rb
82
+ homepage: http://komonzu.mssm.edu
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -3659503582020593831
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -3659503582020593831
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.10
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Client library and CLI to manage Komonzu.
112
+ test_files: []