spatula 0.0.3 → 0.0.4
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/bin/spatula +1 -1
- data/lib/spatula/cook.rb +0 -2
- data/lib/spatula/prepare.rb +0 -2
- data/lib/spatula/search.rb +0 -2
- data/lib/spatula.rb +31 -87
- metadata +12 -5
data/bin/spatula
CHANGED
data/lib/spatula/cook.rb
CHANGED
data/lib/spatula/prepare.rb
CHANGED
data/lib/spatula/search.rb
CHANGED
data/lib/spatula.rb
CHANGED
@@ -2,112 +2,52 @@ require 'rubygems'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'uri'
|
4
4
|
require 'json'
|
5
|
+
require 'thor'
|
5
6
|
|
6
7
|
module Spatula
|
7
8
|
BASE_URL = "http://cookbooks.opscode.com/api/v1"
|
8
9
|
|
9
|
-
class Spatula
|
10
|
-
|
11
|
-
|
12
|
-
def self.register(command, klass)
|
13
|
-
@commands[command] = klass
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.run
|
17
|
-
command = ARGV.shift
|
18
|
-
if klass = @commands[command]
|
19
|
-
klass.run(*ARGV)
|
20
|
-
else
|
21
|
-
Spatula.new.send(command, *ARGV)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Show the cookbook named :name:
|
10
|
+
class Spatula < Thor
|
11
|
+
desc "show COOKBOOK", "Show information about a cookbook"
|
26
12
|
def show(name)
|
27
13
|
print_response(get_cookbook_info(name))
|
28
14
|
end
|
29
15
|
|
30
|
-
|
16
|
+
desc "show_latest_version COOKBOOK", "Show the latest version for a cookbook"
|
31
17
|
def show_latest_version(name)
|
32
18
|
print_response(get_version_info(name))
|
33
19
|
end
|
34
20
|
|
35
|
-
|
36
|
-
# Will create a cookbook_tarballs dir for storing downloaded tarballs
|
21
|
+
desc "install COOKBOOK", "Install the latest version of COOKBOOK into ./cookbooks"
|
37
22
|
def install(name)
|
38
23
|
file = JSON.parse(get_version_info(name))["file"]
|
39
24
|
filename = File.basename(file)
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
# Use ENV['HOME'] as the base here
|
26
|
+
tarball_dir = "#{ENV['HOME']}/.spatula/cookbook_tarballs"
|
27
|
+
FileUtils.mkdir_p(tarball_dir)
|
28
|
+
system "curl #{file} -o #{tarball_dir}"
|
29
|
+
system "tar xzvf #{tarball_dir}/#{filename} -C cookbooks"
|
43
30
|
end
|
44
31
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
trace = cmd.join(' ')
|
51
|
-
warn trace if $TRACE
|
52
|
-
|
53
|
-
pid, inn, out, err = popen4(*cmd)
|
54
|
-
|
55
|
-
inn.sync = true
|
56
|
-
streams = [out, err]
|
57
|
-
out_stream = {
|
58
|
-
out => $stdout,
|
59
|
-
err => $stderr,
|
60
|
-
}
|
61
|
-
|
62
|
-
out_stream_buffers = {
|
63
|
-
out => "",
|
64
|
-
err => ""
|
65
|
-
}
|
66
|
-
|
67
|
-
# Handle process termination ourselves
|
68
|
-
status = nil
|
69
|
-
Thread.start do
|
70
|
-
status = Process.waitpid2(pid).last
|
71
|
-
end
|
72
|
-
|
73
|
-
until streams.empty? do
|
74
|
-
# don't busy loop
|
75
|
-
selected, = select streams, nil, nil, 0.1
|
76
|
-
|
77
|
-
next if selected.nil? or selected.empty?
|
78
|
-
|
79
|
-
selected.each do |stream|
|
80
|
-
if stream.eof? then
|
81
|
-
streams.delete stream if status # we've quit, so no more writing
|
82
|
-
next
|
83
|
-
end
|
84
|
-
|
85
|
-
data = stream.readpartial(1024)
|
86
|
-
out_stream[stream].write data
|
87
|
-
out_stream_buffers[stream] << data
|
88
|
-
|
89
|
-
if stream == err and out_stream_buffers[stream] =~ /password(?:for)?.*:/i then
|
90
|
-
out_stream_buffers[stream] = ""
|
91
|
-
inn.puts @password
|
92
|
-
data << "\n"
|
93
|
-
$stderr.write "\n"
|
94
|
-
end
|
95
|
-
|
96
|
-
result << data
|
97
|
-
end
|
98
|
-
end
|
32
|
+
desc "search QUERY", "Search cookbooks.opscode.com for cookbooks matching QUERY"
|
33
|
+
method_options :start => 0, :count => 10
|
34
|
+
def search(query)
|
35
|
+
Search.run(query, options[:start], options[:count])
|
36
|
+
end
|
99
37
|
|
100
|
-
|
101
|
-
|
102
|
-
|
38
|
+
desc "cook SERVER NODE", "Cook SERVER with the specification in config/NODE.js"
|
39
|
+
method_options :port => 22
|
40
|
+
def cook(server, node)
|
41
|
+
Cook.run(server, node, options[:port])
|
42
|
+
end
|
103
43
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
44
|
+
desc "prepare SERVER", "Install software/libs required by chef on SERVER"
|
45
|
+
method_options :port => 22
|
46
|
+
def prepare(server)
|
47
|
+
Prepare.run(server, port)
|
48
|
+
end
|
110
49
|
|
50
|
+
private
|
111
51
|
def get_cookbook_info(name)
|
112
52
|
url = URI.parse("%s/cookbooks/%s" % [BASE_URL, name])
|
113
53
|
Net::HTTP.get(url)
|
@@ -127,10 +67,14 @@ module Spatula
|
|
127
67
|
end
|
128
68
|
end
|
129
69
|
|
70
|
+
if __FILE__ == $0
|
71
|
+
$: << File.dirname(__FILE__)
|
72
|
+
end
|
73
|
+
|
130
74
|
require 'spatula/search'
|
131
75
|
require 'spatula/prepare'
|
132
76
|
require 'spatula/cook'
|
133
77
|
|
134
78
|
if __FILE__ == $0
|
135
|
-
Spatula::Spatula.
|
79
|
+
Spatula::Spatula.start
|
136
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spatula
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Trotter Cashion
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-07 00:00:00 -05:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -41,18 +46,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
46
|
requirements:
|
42
47
|
- - ">="
|
43
48
|
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
44
51
|
version: "0"
|
45
|
-
version:
|
46
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
53
|
requirements:
|
48
54
|
- - ">="
|
49
55
|
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
50
58
|
version: "0"
|
51
|
-
version:
|
52
59
|
requirements: []
|
53
60
|
|
54
61
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.3.
|
62
|
+
rubygems_version: 1.3.6
|
56
63
|
signing_key:
|
57
64
|
specification_version: 3
|
58
65
|
summary: Command line helper app for use with Chef
|