librarian 0.0.24 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -1
- data/CHANGELOG.md +19 -1
- data/README.md +2 -9
- data/Rakefile +0 -11
- data/lib/librarian.rb +0 -8
- data/lib/librarian/action/base.rb +6 -4
- data/lib/librarian/chef/cli.rb +1 -1
- data/lib/librarian/chef/integration/knife.rb +4 -0
- data/lib/librarian/chef/manifest_reader.rb +14 -2
- data/lib/librarian/chef/source/local.rb +2 -0
- data/lib/librarian/chef/source/site.rb +49 -41
- data/lib/librarian/cli.rb +32 -17
- data/lib/librarian/dependency.rb +1 -9
- data/lib/librarian/dsl.rb +6 -3
- data/lib/librarian/dsl/receiver.rb +10 -12
- data/lib/librarian/dsl/target.rb +5 -10
- data/lib/librarian/environment.rb +41 -2
- data/lib/librarian/lockfile.rb +0 -4
- data/lib/librarian/lockfile/compiler.rb +0 -4
- data/lib/librarian/lockfile/parser.rb +0 -4
- data/lib/librarian/logger.rb +46 -0
- data/lib/librarian/manifest.rb +1 -9
- data/lib/librarian/resolution.rb +5 -3
- data/lib/librarian/resolver.rb +6 -1
- data/lib/librarian/resolver/implementation.rb +18 -8
- data/lib/librarian/source/git.rb +2 -0
- data/lib/librarian/source/git/repository.rb +9 -5
- data/lib/librarian/source/local.rb +12 -2
- data/lib/librarian/spec.rb +4 -4
- data/lib/librarian/spec_change_set.rb +7 -4
- data/lib/librarian/specfile.rb +3 -8
- data/lib/librarian/version.rb +1 -1
- data/librarian.gemspec +3 -9
- data/spec/functional/chef/cli_spec.rb +194 -0
- data/spec/functional/chef/source/site_spec.rb +11 -10
- data/spec/functional/source/git/repository_spec.rb +1 -1
- data/spec/support/cli_macro.rb +122 -0
- data/spec/support/with_env_macro.rb +20 -0
- data/spec/unit/config/database_spec.rb +2 -2
- data/spec/unit/dependency_spec.rb +6 -0
- data/spec/unit/dsl_spec.rb +16 -37
- data/spec/unit/environment_spec.rb +95 -0
- data/spec/unit/manifest_spec.rb +6 -0
- data/spec/unit/resolver_spec.rb +41 -0
- metadata +7 -42
- data/config/cucumber.yaml +0 -1
- data/features/chef/cli/init.feature +0 -11
- data/features/chef/cli/install.feature +0 -64
- data/features/chef/cli/show.feature +0 -77
- data/features/chef/cli/version.feature +0 -11
- data/features/support/env.rb +0 -9
- data/lib/librarian/helpers/debug.rb +0 -35
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.25
|
4
|
+
|
5
|
+
* \#71. Fix an error, given certain locale settings, with reading cookbook
|
6
|
+
metadata files.
|
7
|
+
|
8
|
+
* \#89. Fix an error when encountering manifests and dependencies with names of
|
9
|
+
a single letter, such as `"R"`.
|
10
|
+
|
11
|
+
* \#92, \#99. HTTP proxy support via the `HTTP_PROXY` environment variable. Also
|
12
|
+
supports `HTTP_PROXY_USER` and `HTTP_PROXY_PASS` environment variables. Thanks
|
13
|
+
@tknerr.
|
14
|
+
|
15
|
+
* \#97. Enforce that the `:ref` option in the `:git` source may only be given a
|
16
|
+
string.
|
17
|
+
|
18
|
+
* \#98. Fix unpacking chef site-sourced packages where the directory in the
|
19
|
+
tarball does not match the cookbook name.
|
20
|
+
|
3
21
|
## 0.0.24
|
4
22
|
|
5
23
|
* \#15. A remembered configuration system.
|
@@ -12,7 +30,7 @@
|
|
12
30
|
* \#76. Support git annotated tags.
|
13
31
|
|
14
32
|
* \#80. Ignore directories in the `PATH` named `git` when looking for the `git`
|
15
|
-
bin.
|
33
|
+
bin. Thanks @avit.
|
16
34
|
|
17
35
|
* \#85. Provide a helpful message when running the `show` command without a
|
18
36
|
lockfile present.
|
data/README.md
CHANGED
@@ -146,8 +146,8 @@ Prepare your infrastructure repository:
|
|
146
146
|
|
147
147
|
$ cd ~/path/to/chef-repo
|
148
148
|
$ git rm -r cookbooks
|
149
|
-
$ echo cookbooks >> .gitignore
|
150
|
-
$ echo tmp >> .gitignore
|
149
|
+
$ echo /cookbooks >> .gitignore
|
150
|
+
$ echo /tmp >> .gitignore
|
151
151
|
|
152
152
|
Librarian-Chef takes over your `cookbooks/` directory, and will always reinstall
|
153
153
|
the cookbooks listed the `Cheffile.lock` into your `cookbooks/` directory. Hence
|
@@ -359,12 +359,7 @@ How to Contribute
|
|
359
359
|
|
360
360
|
### Running the tests
|
361
361
|
|
362
|
-
# Either
|
363
362
|
$ rspec spec
|
364
|
-
$ cucumber
|
365
|
-
|
366
|
-
# Or
|
367
|
-
$ rake
|
368
363
|
|
369
364
|
You will probably need some way to isolate gems. Librarian provides a `Gemfile`,
|
370
365
|
so if you want to use bundler, you can prepare the directory with the usual
|
@@ -372,8 +367,6 @@ so if you want to use bundler, you can prepare the directory with the usual
|
|
372
367
|
|
373
368
|
$ bundle install
|
374
369
|
$ bundle exec rspec spec
|
375
|
-
$ bundle exec cucumber
|
376
|
-
$ bundle exec rake
|
377
370
|
|
378
371
|
### Installing locally
|
379
372
|
|
data/Rakefile
CHANGED
@@ -21,14 +21,3 @@ module Bundler
|
|
21
21
|
end
|
22
22
|
|
23
23
|
Bundler::GemHelper.install_tasks
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'rspec/core/rake_task'
|
27
|
-
RSpec::Core::RakeTask.new(:spec)
|
28
|
-
|
29
|
-
require 'cucumber/rake/task'
|
30
|
-
Cucumber::Rake::Task.new(:features)
|
31
|
-
|
32
|
-
task :default => [:spec, :features]
|
33
|
-
rescue LoadError
|
34
|
-
end
|
data/lib/librarian.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require "librarian/helpers/debug"
|
2
|
-
|
3
1
|
module Librarian
|
4
2
|
module Action
|
5
3
|
class Base
|
6
4
|
|
7
|
-
include Helpers::Debug
|
8
|
-
|
9
5
|
attr_accessor :environment
|
10
6
|
private :environment=
|
11
7
|
|
@@ -17,6 +13,12 @@ module Librarian
|
|
17
13
|
self.options = options
|
18
14
|
end
|
19
15
|
|
16
|
+
private
|
17
|
+
|
18
|
+
def debug(*args, &block)
|
19
|
+
environment.logger.debug(*args, &block)
|
20
|
+
end
|
21
|
+
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/librarian/chef/cli.rb
CHANGED
@@ -13,7 +13,6 @@ module Librarian
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
include Particularity
|
17
16
|
extend Particularity
|
18
17
|
|
19
18
|
source_root Pathname.new(__FILE__).dirname.join("templates")
|
@@ -23,6 +22,7 @@ module Librarian
|
|
23
22
|
end
|
24
23
|
|
25
24
|
desc "install", "Resolves and installs all of the dependencies you specify."
|
25
|
+
option "quiet", :type => :boolean, :default => false
|
26
26
|
option "verbose", :type => :boolean, :default => false
|
27
27
|
option "line-numbers", :type => :boolean, :default => false
|
28
28
|
option "clean", :type => :boolean, :default => false
|
@@ -16,8 +16,8 @@ module Librarian
|
|
16
16
|
|
17
17
|
def read_manifest(name, manifest_path)
|
18
18
|
case manifest_path.extname
|
19
|
-
when ".json" then JSON.parse(manifest_path
|
20
|
-
when ".yml", ".yaml" then YAML.load(manifest_path
|
19
|
+
when ".json" then JSON.parse(binread(manifest_path))
|
20
|
+
when ".yml", ".yaml" then YAML.load(binread(manifest_path))
|
21
21
|
when ".rb" then compile_manifest(name, manifest_path.dirname)
|
22
22
|
end
|
23
23
|
end
|
@@ -42,6 +42,18 @@ module Librarian
|
|
42
42
|
manifest["name"] == name
|
43
43
|
end
|
44
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
if IO.respond_to?(:binread)
|
48
|
+
def binread(path)
|
49
|
+
path.binread
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def binread(path)
|
53
|
+
path.read
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
@@ -8,8 +8,6 @@ require 'zlib'
|
|
8
8
|
require 'securerandom'
|
9
9
|
require 'archive/tar/minitar'
|
10
10
|
|
11
|
-
require 'librarian/helpers/debug'
|
12
|
-
|
13
11
|
require 'librarian/chef/manifest_reader'
|
14
12
|
|
15
13
|
module Librarian
|
@@ -17,12 +15,8 @@ module Librarian
|
|
17
15
|
module Source
|
18
16
|
class Site
|
19
17
|
|
20
|
-
include Helpers::Debug
|
21
|
-
|
22
18
|
class Line
|
23
19
|
|
24
|
-
include Helpers::Debug
|
25
|
-
|
26
20
|
attr_accessor :source, :name
|
27
21
|
private :source=, :name=
|
28
22
|
|
@@ -238,39 +232,27 @@ module Librarian
|
|
238
232
|
end
|
239
233
|
|
240
234
|
def cache_remote_json!(path, uri)
|
241
|
-
path
|
242
|
-
uri = to_uri(uri)
|
243
|
-
|
244
|
-
path.dirname.mkpath unless path.dirname.directory?
|
245
|
-
|
246
|
-
debug { "Caching #{uri} to #{path}" }
|
247
|
-
|
248
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
249
|
-
request = Net::HTTP::Get.new(uri.path)
|
250
|
-
response = http.start{|http| http.request(request)}
|
251
|
-
unless Net::HTTPSuccess === response
|
252
|
-
raise Error, "Could not get #{uri} because #{response.code} #{response.message}!"
|
253
|
-
end
|
254
|
-
json = response.body
|
255
|
-
JSON.parse(json) # verify that it's really JSON.
|
256
|
-
write! path, json
|
235
|
+
cache_remote_object!(path, uri, :type => :json)
|
257
236
|
end
|
258
237
|
|
259
|
-
def cache_remote_object!(path, uri)
|
238
|
+
def cache_remote_object!(path, uri, options = { })
|
260
239
|
path = Pathname(path)
|
261
240
|
uri = to_uri(uri)
|
262
|
-
|
263
|
-
path.dirname.mkpath unless path.dirname.directory?
|
241
|
+
type = options[:type]
|
264
242
|
|
265
243
|
debug { "Caching #{uri} to #{path}" }
|
266
244
|
|
267
|
-
|
268
|
-
request = Net::HTTP::Get.new(uri.path)
|
269
|
-
response = http.start{|http| http.request(request)}
|
245
|
+
response = http_get(uri)
|
270
246
|
unless Net::HTTPSuccess === response
|
271
247
|
raise Error, "Could not get #{uri} because #{response.code} #{response.message}!"
|
272
248
|
end
|
273
|
-
|
249
|
+
|
250
|
+
object = response.body
|
251
|
+
case type
|
252
|
+
when :json
|
253
|
+
JSON.parse(object) # verify that it's really JSON.
|
254
|
+
end
|
255
|
+
write! path, object
|
274
256
|
end
|
275
257
|
|
276
258
|
def write!(path, bytes)
|
@@ -291,9 +273,11 @@ module Librarian
|
|
291
273
|
end
|
292
274
|
|
293
275
|
# Cookbook files, as pulled from Opscode Community Site API, are
|
294
|
-
# embedded in a subdirectory of the tarball
|
295
|
-
|
296
|
-
|
276
|
+
# embedded in a subdirectory of the tarball.
|
277
|
+
subtemps = temp.children
|
278
|
+
subtemps.empty? and raise "The package archive was empty!"
|
279
|
+
subtemps.size > 1 and raise "The package archive has too many children!"
|
280
|
+
subtemp = subtemps.first
|
297
281
|
debug { "Moving #{relative_path_to(subtemp)} to #{relative_path_to(path)}" }
|
298
282
|
FileUtils.mv(subtemp, path)
|
299
283
|
ensure
|
@@ -313,6 +297,26 @@ module Librarian
|
|
313
297
|
uri
|
314
298
|
end
|
315
299
|
|
300
|
+
def debug(*args, &block)
|
301
|
+
environment.logger.debug(*args, &block)
|
302
|
+
end
|
303
|
+
|
304
|
+
def relative_path_to(path)
|
305
|
+
environment.logger.relative_path_to(path)
|
306
|
+
end
|
307
|
+
|
308
|
+
def http(uri)
|
309
|
+
environment.net_http_class.new(uri.host, uri.port)
|
310
|
+
end
|
311
|
+
|
312
|
+
def http_get(uri)
|
313
|
+
http = http(uri)
|
314
|
+
request = Net::HTTP::Get.new(uri.path)
|
315
|
+
response = http.start{|http| http.request(request)}
|
316
|
+
|
317
|
+
response
|
318
|
+
end
|
319
|
+
|
316
320
|
end
|
317
321
|
|
318
322
|
class << self
|
@@ -337,18 +341,12 @@ module Librarian
|
|
337
341
|
|
338
342
|
end
|
339
343
|
|
340
|
-
attr_accessor :environment
|
341
|
-
private :environment=
|
342
|
-
attr_reader :uri
|
343
|
-
|
344
|
-
attr_accessor :_metadata_cache
|
345
|
-
private :_metadata_cache, :_metadata_cache=
|
344
|
+
attr_accessor :environment, :uri
|
345
|
+
private :environment=, :uri=
|
346
346
|
|
347
347
|
def initialize(environment, uri, options = {})
|
348
348
|
self.environment = environment
|
349
|
-
|
350
|
-
@cache_path = nil
|
351
|
-
self._metadata_cache = { }
|
349
|
+
self.uri = uri
|
352
350
|
end
|
353
351
|
|
354
352
|
def to_s
|
@@ -384,6 +382,8 @@ module Librarian
|
|
384
382
|
install_path = install_path(name)
|
385
383
|
line = line(name)
|
386
384
|
|
385
|
+
info { "Installing #{manifest.name} (#{manifest.version})" }
|
386
|
+
|
387
387
|
debug { "Installing #{manifest}" }
|
388
388
|
|
389
389
|
line.install_version! version, install_path
|
@@ -428,6 +428,14 @@ module Librarian
|
|
428
428
|
@line[name] ||= Line.new(self, name)
|
429
429
|
end
|
430
430
|
|
431
|
+
def info(*args, &block)
|
432
|
+
environment.logger.info(*args, &block)
|
433
|
+
end
|
434
|
+
|
435
|
+
def debug(*args, &block)
|
436
|
+
environment.logger.debug(*args, &block)
|
437
|
+
end
|
438
|
+
|
431
439
|
end
|
432
440
|
end
|
433
441
|
end
|
data/lib/librarian/cli.rb
CHANGED
@@ -6,8 +6,6 @@ require 'librarian/error'
|
|
6
6
|
require 'librarian/action'
|
7
7
|
require "librarian/ui"
|
8
8
|
|
9
|
-
require "librarian/helpers/debug"
|
10
|
-
|
11
9
|
module Librarian
|
12
10
|
class Cli < Thor
|
13
11
|
|
@@ -21,31 +19,40 @@ module Librarian
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
include Particularity
|
25
22
|
extend Particularity
|
26
23
|
|
27
|
-
include Helpers::Debug
|
28
|
-
|
29
24
|
class << self
|
30
25
|
def bin!
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
with_environment do |environment|
|
27
|
+
begin
|
28
|
+
start
|
29
|
+
rescue Librarian::Error => e
|
30
|
+
environment.ui.error e.message
|
31
|
+
environment.ui.debug e.backtrace.join("\n")
|
32
|
+
exit (e.respond_to?(:status_code) ? e.status_code : 1)
|
33
|
+
rescue Interrupt => e
|
34
|
+
environment.ui.error "\nQuitting..."
|
35
|
+
exit 1
|
36
|
+
end
|
41
37
|
end
|
42
38
|
end
|
39
|
+
|
40
|
+
attr_accessor :environment
|
41
|
+
|
42
|
+
def with_environment
|
43
|
+
environment = root_module.environment_class.new
|
44
|
+
self.environment, orig_environment = environment, self.environment
|
45
|
+
yield(environment)
|
46
|
+
ensure
|
47
|
+
self.environment = orig_environment
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
def initialize(*)
|
46
52
|
super
|
47
53
|
the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
|
48
54
|
environment.ui = UI::Shell.new(the_shell)
|
55
|
+
environment.ui.be_quiet! if options["quiet"]
|
49
56
|
environment.ui.debug! if options["verbose"]
|
50
57
|
environment.ui.debug_line_numbers! if options["verbose"] && options["line-numbers"]
|
51
58
|
|
@@ -54,7 +61,7 @@ module Librarian
|
|
54
61
|
|
55
62
|
desc "version", "Displays the version."
|
56
63
|
def version
|
57
|
-
say "librarian-#{
|
64
|
+
say "librarian-#{environment.version}"
|
58
65
|
end
|
59
66
|
|
60
67
|
desc "config", "Show or edit the config."
|
@@ -145,7 +152,7 @@ module Librarian
|
|
145
152
|
private
|
146
153
|
|
147
154
|
def environment
|
148
|
-
|
155
|
+
self.class.environment
|
149
156
|
end
|
150
157
|
|
151
158
|
def ensure!(options = { })
|
@@ -196,5 +203,13 @@ module Librarian
|
|
196
203
|
end
|
197
204
|
end
|
198
205
|
|
206
|
+
def debug(*args, &block)
|
207
|
+
environment.logger.debug(*args, &block)
|
208
|
+
end
|
209
|
+
|
210
|
+
def relative_path_to(path)
|
211
|
+
environment.logger.relative_path_to(path)
|
212
|
+
end
|
213
|
+
|
199
214
|
end
|
200
215
|
end
|