natives 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjQ4ZmU0MzcyMTQyNjVjMzZmOGIxNzk3ZTU5YjcyOGU1ZTdhNGFlMg==
4
+ YjhlODM3ZWJiNzkwMTY3ZDEwN2Y4YzY2NjJhN2Q0NmQ0NTFmOTk2Zg==
5
5
  data.tar.gz: !binary |-
6
- NWQ2NzcyOWM3ZjQ3ODExMzU2MzQzM2M2YzA0YWQ4MTE0Y2Q0NTYyNg==
6
+ MWNjYTc2Njg3MmJmYzg4OTUxNDQwMjhkNDZlYjk3OWZlNDRhNGZiOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTIzNzllZWNlYzI5OGJjZTIxOTRjNjBjNmQ1YTliMjJlNjRhZjlmZDk1ZjE1
10
- NjU5OTJmMzBlMWQ0YTJmMmM5YmExOGRkOTVjODRhNWVmNzAxYWY0OWU4MWEz
11
- OTRhM2ExYWI4ZmNhZjJlMGRiOTA1YzgzOTVkYzI5NmI0MjAyZWE=
9
+ OTFlNjI1MjU0YzY2NjU1YTNhZTIyYzJmODhlZGJkY2M3YTMxMzdlOGQ5Mjky
10
+ YThhNTJlZjBjYzVhNzEwZDBlYjZiOTEzNGZmMWY2OWZiMzE1YmRmNTM2YjU0
11
+ YjA5YTQ3Zjc1OTQwODg2MzRiZDlkMTMwMmI5NTA1N2VmMmQzNjQ=
12
12
  data.tar.gz: !binary |-
13
- ZjNkYTFkNDU5OWU1MGQ3ZGEwZWQ0ZmNkZGM5ODJkMzQ4ODdkZjlkZDdiMzZm
14
- YWRlOWI2MGFlMjA3MzRiNzZhOWIxNzc4MTFhYmVkYjUyOGY1OTAwZWIwZTMy
15
- YTBkNzRmNGIxYjZiMzUzYmIwNDY5ZDkwNGE3YWE3YzUyYzYwNjk=
13
+ NDk5ZjNmNjdlMmI0OWE0ZDc5Y2Q5MjcxYjEyYjU2ZWMwMzBjMDNhOGY0YzE2
14
+ ZDRmODk2MWRhYTkyMDJmMTU3OTlmMTQ4ZjJiZDliZDdiNmU5ZWU3NmY0M2Ni
15
+ OTIxMGM0MmQ2ODQwNTc3YWMxOGRiMWE5YjcyMjZhZjRlMTQ2OWQ=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -9,18 +9,20 @@
9
9
 
10
10
  require 'natives/catalog'
11
11
 
12
- include_recipe 'homebrew' if use_homebrew?
13
- include_recipe 'apt' if use_apt?
12
+ if node['natives']['configs']['update_provider']
13
+ include_recipe('homebrew') if use_homebrew?
14
+ include_recipe('apt') if use_apt?
15
+ end
14
16
 
15
17
  natives_install_list.each do |catalog_name, entries|
16
18
  catalog = Natives::Catalog.new(
17
19
  catalog_name,
18
20
  node[:platform], node[:platform_version],
19
21
  current_package_provider,
20
- working_dir: node['natives']['config']['working_dir']
22
+ working_dir: node['natives']['configs']['working_dir']
21
23
  )
22
-
23
24
  packages = catalog.native_packages_for(entries)
25
+
24
26
  packages.each do |package_name|
25
27
  package package_name do
26
28
  action :install
data/chef/solo.rb CHANGED
@@ -1,4 +1,4 @@
1
- log_level :warn
1
+ log_level :error
2
2
 
3
3
  base_path = File.absolute_path(File.join(File.dirname(__FILE__)))
4
4
 
data/lib/natives/app.rb CHANGED
@@ -4,9 +4,13 @@ require 'chef/application/solo'
4
4
 
5
5
  module Natives
6
6
  class App
7
- def install(catalog_name, packages)
8
- create_solo_json_tempfile(catalog_name.to_s,
9
- Array(packages)) do |attrs_file|
7
+ def install(catalog_name, packages, configs={})
8
+ create_solo_json_tempfile(
9
+ catalog_name.to_s,
10
+ Array(packages),
11
+ default_configs.merge(configs || {})
12
+
13
+ ) do |attrs_file|
10
14
  run_chef_solo(attrs_file)
11
15
  end
12
16
  end
@@ -23,9 +27,9 @@ module Natives
23
27
  Chef::Application::Solo.new.run
24
28
  end
25
29
 
26
- def create_solo_json_tempfile(catalog_name, packages, &block)
30
+ def create_solo_json_tempfile(catalog_name, packages, configs, &block)
27
31
  file = Tempfile.new('natives.temp_attrs_file')
28
- file.write(json_attrs(catalog_name, packages))
32
+ file.write(json_attrs(catalog_name, packages, configs))
29
33
  file.flush
30
34
  file.rewind
31
35
  begin
@@ -35,6 +39,11 @@ module Natives
35
39
  end
36
40
  end
37
41
 
42
+ def default_configs
43
+ {
44
+ working_dir: current_working_dir
45
+ }
46
+ end
38
47
  protected
39
48
 
40
49
  def current_working_dir
@@ -45,15 +54,13 @@ module Natives
45
54
  File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
46
55
  end
47
56
 
48
- def json_attrs(catalog_name, packages)
57
+ def json_attrs(catalog_name, packages, configs)
49
58
  {
50
59
  "natives" => {
51
60
  "install_list" => {
52
61
  catalog_name => packages
53
62
  },
54
- "config" => {
55
- "working_dir" => current_working_dir
56
- }
63
+ "configs" => configs
57
64
  }
58
65
  }.to_json
59
66
  end
data/lib/natives/cli.rb CHANGED
@@ -4,21 +4,39 @@ require 'natives/gemfile_viewer'
4
4
 
5
5
  module Natives
6
6
  class Cli < Thor
7
- desc 'install PACKAGE1 PACKAGE2 ..', 'install a list of ruby packages'
7
+ default_task :install
8
+
9
+ desc 'install [ENTRY1 ENTRY2 ..]',
10
+ 'install native packages required by the catalog entries'
11
+
8
12
  method_option :catalog, default: 'rubygems',
9
- desc: 'set the catalog to be used',
10
- aliases: '-c'
11
- method_option :gemfile, default: 'Gemfile'
13
+ aliases: '-c',
14
+ desc: 'use this catalog'
15
+ method_option :gemfile, default: 'Gemfile',
16
+ desc: 'use gems in the gemfile as the catalog entries'
17
+ method_option :"update-provider", type: 'boolean',
18
+ default: false,
19
+ aliases: '-u',
20
+ desc: "update package provider's repo (eg. apt-get update)"
21
+
12
22
  def install(*packages)
13
23
  catalog = options[:catalog]
14
-
24
+ configs = {
25
+ update_provider: options['update-provider']
26
+ }
15
27
  if catalog == 'rubygems' && packages.empty?
16
28
  packages = packages_in_gemfile(options[:gemfile])
17
29
  end
18
30
 
19
- puts "Catalog: #{catalog.inspect}\nPackages:\n#{packages.inspect}\n\n"
31
+ puts "catalog: #{catalog.inspect}"
32
+ puts "entries: #{packages.inspect}"
33
+ puts "configs: #{configs}"
34
+ puts ""
35
+
36
+ Natives::App.new.install(catalog, packages, configs)
20
37
 
21
- Natives::App.new.install catalog, packages
38
+ rescue => ex
39
+ $stderr.puts ex.message
22
40
  end
23
41
 
24
42
  protected
data/natives.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: natives 0.3.0 ruby lib
5
+ # stub: natives 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "natives"
9
- s.version = "0.3.0"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Huiming Teo"]
@@ -7,7 +7,8 @@ describe Natives::App do
7
7
 
8
8
  it "forces packages argument to be an Array" do
9
9
  app.should_receive(:run_chef_solo)
10
- app.should_receive(:create_solo_json_tempfile).with("foo", []).
10
+ app.should_receive(:create_solo_json_tempfile).
11
+ with("foo", [], app.default_configs).
11
12
  and_call_original
12
13
 
13
14
  app.install("foo", nil)
@@ -15,11 +16,29 @@ describe Natives::App do
15
16
 
16
17
  it "forces catalog_name to be a String" do
17
18
  app.should_receive(:run_chef_solo)
18
- app.should_receive(:create_solo_json_tempfile).with("", []).
19
+ app.should_receive(:create_solo_json_tempfile).
20
+ with("", ['foo', 'bar'], app.default_configs).
19
21
  and_call_original
20
22
 
21
- app.install(nil, nil)
23
+ app.install(nil, ['foo', 'bar'])
24
+ end
25
+
26
+ it "merges configs with default configs" do
27
+ app.should_receive(:run_chef_solo)
28
+ app.should_receive(:create_solo_json_tempfile).
29
+ with("foobar", ['foo', 'bar'], app.default_configs.merge({foo: false})).
30
+ and_call_original
31
+
32
+ app.install('foobar', ['foo', 'bar'], {foo: false})
33
+ end
34
+
35
+ it "treats nil configs as empty hash" do
36
+ app.should_receive(:run_chef_solo)
37
+ app.should_receive(:create_solo_json_tempfile).
38
+ with("foobar", ['foo', 'bar'], app.default_configs).
39
+ and_call_original
22
40
 
41
+ app.install('foobar', ['foo', 'bar'], nil)
23
42
  end
24
43
  end
25
44
 
@@ -28,7 +47,10 @@ describe Natives::App do
28
47
 
29
48
  it "generates a valid solo.json file" do
30
49
  json = nil
31
- app.create_solo_json_tempfile('rubygems', ['foo', 'bar']) do |file|
50
+ app.create_solo_json_tempfile(
51
+ 'rubygems',
52
+ ['foo', 'bar'],
53
+ {working_dir: '/path/to/working_dir'}) do |file|
32
54
  json = JSON.parse(file.read)
33
55
  end
34
56
  expect(json).to eq({
@@ -36,8 +58,8 @@ describe Natives::App do
36
58
  "install_list" => {
37
59
  "rubygems" => ["foo", "bar"]
38
60
  },
39
- "config" => {
40
- "working_dir" => Dir.pwd
61
+ "configs" => {
62
+ "working_dir" => '/path/to/working_dir'
41
63
  }
42
64
  }
43
65
  })
@@ -45,7 +67,9 @@ describe Natives::App do
45
67
 
46
68
  it "generates solo.json file based on the given catalog name" do
47
69
  json = nil
48
- app.create_solo_json_tempfile('npm', ['foo', 'bar']) do |file|
70
+ app.create_solo_json_tempfile(
71
+ 'npm', ['foo', 'bar'],
72
+ {working_dir: '/path/to/foo'}) do |file|
49
73
  json = JSON.parse(file.read)
50
74
  end
51
75
  expect(json).to eq({
@@ -53,8 +77,8 @@ describe Natives::App do
53
77
  "install_list" => {
54
78
  "npm" => ["foo", "bar"]
55
79
  },
56
- "config" => {
57
- "working_dir" => Dir.pwd
80
+ "configs" => {
81
+ "working_dir" => '/path/to/foo'
58
82
  }
59
83
  }
60
84
  })
@@ -62,7 +86,7 @@ describe Natives::App do
62
86
 
63
87
  it "handles empty package list" do
64
88
  json = nil
65
- app.create_solo_json_tempfile('rubygems', []) do |file|
89
+ app.create_solo_json_tempfile('rubygems', [], {}) do |file|
66
90
  json = JSON.parse(file.read)
67
91
  end
68
92
  expect(json).to eq({
@@ -70,8 +94,7 @@ describe Natives::App do
70
94
  "install_list" => {
71
95
  "rubygems" => []
72
96
  },
73
- "config" => {
74
- "working_dir" => Dir.pwd
97
+ "configs" => {
75
98
  }
76
99
 
77
100
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natives
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huiming Teo