librarian-puppet 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f2563b5575e2082f80e0b75f8b1ece49f070a8a
4
- data.tar.gz: c37295903ceab4b3406d28f3f90537cd2efa20a1
3
+ metadata.gz: 010735fe88618f0ecd15edc880fa37086546d776
4
+ data.tar.gz: fc6e6b124d06ef74f249b813486880649aee3dbd
5
5
  SHA512:
6
- metadata.gz: 7c9a691b88c4813bc4dc9d90011bc194f8ccf3452ca21eb79359a95652294d049b238b955b3d6fd9fc0f13eebf44ac9e698d60621e683a29675675a20b11c9e6
7
- data.tar.gz: 28e9ee98ba396f257dbf233550bc5983c335fe1d85da95e1d5d3621770ef904925b86654c833253dafd446f41a98ebd54e1b5f8457d1e135b7a775e4b2ae9a3d
6
+ metadata.gz: d65097488d97abe1ca30a251d62e02f3b3cebf0fb7ed1f594c7d98e3adec4e578dddf4e4ed5ffd73ee1627bf5eb4524097359e8777fb368f258fd0eb174bdef4
7
+ data.tar.gz: 6ee5fc74eebe8a99f970affcfd53949fce28b3926bbd1c0d9bf740e5c24d4297c01e3679f72e4abec5e4076bcb4bed786124cc454fdd36debd3411eca0c3ed6d
data/README.md CHANGED
@@ -37,17 +37,20 @@ See the [Changelog](Changelog.md) for more details.
37
37
 
38
38
  ## The Puppetfile
39
39
 
40
- Every Puppet repository that uses Librarian-puppet will have a file named
41
- `Puppetfile` in the root directory of that repository. The full specification
42
- for which modules your puppet infrastructure repository depends goes in here.
40
+ Every Puppet repository that uses Librarian-puppet may have a file named
41
+ `Puppetfile`, `metadata.json` or `Modulefile` in the root directory of that repository.
42
+ The full specification
43
+ for which modules your puppet infrastructure repository depends goes in here.
43
44
 
44
- ### Simple Puppetfile
45
+ ### Simple usage
45
46
 
46
- This Puppetfile will download all the dependencies listed in your Modulefile from the Puppet Forge
47
+ If no Puppetfile is present, `librarian-puppet` will download all the dependencies
48
+ listed in your `metadata.json` or `Modulefile` from the Puppet Forge,
49
+ as if the Puppetfile contained
47
50
 
48
51
  forge "https://forgeapi.puppetlabs.com"
49
52
 
50
- modulefile
53
+ metadata
51
54
 
52
55
 
53
56
  ### Example Puppetfile
@@ -0,0 +1 @@
1
+ require "librarian/puppet/action/install"
@@ -0,0 +1,24 @@
1
+ module Librarian
2
+ module Puppet
3
+ module Action
4
+ class Install < Librarian::Action::Install
5
+
6
+ private
7
+
8
+ def create_install_path
9
+ install_path.rmtree if install_path.exist? && destructive?
10
+ install_path.mkpath
11
+ end
12
+
13
+ def destructive?
14
+ environment.config_db.local['destructive'] == 'true'
15
+ end
16
+
17
+ def check_specfile
18
+ # don't fail if Puppetfile doesn't exist as we'll use the Modulefile or metadata.json
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,7 @@ require 'librarian/helpers'
2
2
 
3
3
  require 'librarian/cli'
4
4
  require 'librarian/puppet'
5
+ require 'librarian/puppet/action'
5
6
 
6
7
  module Librarian
7
8
  module Puppet
@@ -47,11 +48,6 @@ module Librarian
47
48
  option "use-v1-api", :type => :boolean, :default => true
48
49
  def install
49
50
 
50
- unless File.exist?('Puppetfile')
51
- say "Could not find Puppetfile in #{Dir.pwd}", :red
52
- exit 1
53
- end
54
-
55
51
  ensure!
56
52
  clean! if options["clean"]
57
53
  unless options["destructive"].nil?
@@ -89,6 +85,14 @@ module Librarian
89
85
  def version
90
86
  say "librarian-puppet v#{Librarian::Puppet::VERSION}"
91
87
  end
88
+
89
+ private
90
+
91
+ # override the actions to use our own
92
+
93
+ def install!(options = { })
94
+ Action::Install.new(environment, options).run
95
+ end
92
96
  end
93
97
  end
94
98
  end
@@ -17,6 +17,14 @@ module Librarian
17
17
  def run(specfile = nil, sources = [])
18
18
  specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
19
19
 
20
+ if specfile.kind_of?(Pathname) and !File.exists?(specfile)
21
+ debug { "Specfile not found, using defaults: #{specfile}" }
22
+ specfile = Proc.new do
23
+ forge "http://forge.puppetlabs.com"
24
+ metadata
25
+ end
26
+ end
27
+
20
28
  Target.new(self).tap do |target|
21
29
  target.precache_sources(sources)
22
30
  debug_named_source_cache("Pre-Cached Sources", target)
@@ -30,17 +38,20 @@ module Librarian
30
38
  end
31
39
 
32
40
  class Receiver < Librarian::Dsl::Receiver
33
- attr_reader :specfile
41
+ attr_reader :specfile, :working_path
34
42
 
35
43
  # save the specfile and call librarian
36
44
  def run(specfile = nil)
45
+ @working_path = specfile.kind_of?(Pathname) ? specfile.parent : Pathname.new(Dir.pwd)
37
46
  @specfile = specfile
38
47
  super
39
48
  end
40
49
 
41
50
  # implement the 'modulefile' syntax for Puppetfile
42
51
  def modulefile
43
- File.read(Pathname.new(specfile).parent.join('Modulefile')).lines.each do |line|
52
+ f = modulefile_path
53
+ raise Error, "Modulefile file does not exist: #{f}" unless File.exists?(f)
54
+ File.read(f).lines.each do |line|
44
55
  regexp = /\s*dependency\s+('|")([^'"]+)\1\s*(?:,\s*('|")([^'"]+)\3)?/
45
56
  regexp =~ line && mod($2, $4)
46
57
  end
@@ -48,11 +59,28 @@ module Librarian
48
59
 
49
60
  # implement the 'metadata' syntax for Puppetfile
50
61
  def metadata
51
- dependencyList = JSON.parse(File.read(Pathname.new(specfile).parent.join('metadata.json')))['dependencies']
62
+ f = working_path.join('metadata.json')
63
+ unless File.exists?(f)
64
+ msg = "Metadata file does not exist: #{f}"
65
+ # try modulefile, in case we don't have a Puppetfile and we are using the default template
66
+ if File.exists?(modulefile_path)
67
+ modulefile
68
+ return
69
+ else
70
+ raise Error, msg
71
+ end
72
+ end
73
+ dependencyList = JSON.parse(File.read(f))['dependencies']
52
74
  dependencyList.each do |d|
53
75
  mod(d['name'], d['version_requirement'])
54
76
  end
55
77
  end
78
+
79
+ private
80
+
81
+ def modulefile_path
82
+ working_path.join('Modulefile')
83
+ end
56
84
  end
57
85
  end
58
86
  end
@@ -13,6 +13,9 @@ module Librarian
13
13
  def initialize(name, requirement, source)
14
14
  assert_name_valid! name
15
15
 
16
+ # Issue #235 fail if forge source is not defined
17
+ raise Error, "forge entry is not defined in Puppetfile" if source.instance_of?(Array) && source.empty?
18
+
16
19
  # let's settle on provider-module syntax instead of provider/module
17
20
  self.name = normalize_name(name)
18
21
  self.requirement = Requirement.new(requirement)
@@ -80,22 +83,6 @@ module Librarian
80
83
  end
81
84
  end
82
85
 
83
- module Action
84
- class Install < Base
85
-
86
- private
87
-
88
- def create_install_path
89
- install_path.rmtree if install_path.exist? && destructive?
90
- install_path.mkpath
91
- end
92
-
93
- def destructive?
94
- environment.config_db.local['destructive'] == 'true'
95
- end
96
- end
97
- end
98
-
99
86
  class ManifestSet
100
87
  include Librarian::Puppet::Util
101
88
 
@@ -94,6 +94,7 @@ module Librarian
94
94
  metadata = ::Puppet::ModuleTool::Metadata.new
95
95
  begin
96
96
  ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
97
+ raise SyntaxError, "Missing version" unless metadata.version
97
98
  rescue ArgumentError, SyntaxError => error
98
99
  warn { "Unable to parse #{modulefile}, ignoring: #{error}" }
99
100
  if metadata.respond_to? :version=
@@ -1,5 +1,5 @@
1
1
  module Librarian
2
2
  module Puppet
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-01 00:00:00.000000000 Z
12
+ date: 2014-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librarian
@@ -154,6 +154,8 @@ files:
154
154
  - README.md
155
155
  - bin/librarian-puppet
156
156
  - lib/librarian/puppet.rb
157
+ - lib/librarian/puppet/action.rb
158
+ - lib/librarian/puppet/action/install.rb
157
159
  - lib/librarian/puppet/cli.rb
158
160
  - lib/librarian/puppet/dsl.rb
159
161
  - lib/librarian/puppet/environment.rb