librarian-puppet 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,3 @@
1
- *.gem
1
+ pkg/
2
2
  Gemfile.lock
3
3
  tmp/
@@ -1,5 +1,6 @@
1
1
  require 'librarian'
2
2
  require 'puppet'
3
+ require 'fileutils'
3
4
 
4
5
  require 'librarian/puppet/extension'
5
6
  require 'librarian/puppet/version'
@@ -43,6 +43,7 @@ module Librarian
43
43
  option "strip-dot-git", :type => :boolean
44
44
  option "path", :type => :string
45
45
  option "destructive", :type => :boolean, :default => false
46
+ option "local", :type => :boolean, :default => false
46
47
  def install
47
48
  ensure!
48
49
  clean! if options["clean"]
@@ -56,10 +57,26 @@ module Librarian
56
57
  if options.include?("path")
57
58
  environment.config_db.local["path"] = options["path"]
58
59
  end
60
+
61
+ environment.config_db.local['mode'] = options['local'] ? 'local' : nil
62
+
59
63
  resolve!
60
64
  install!
61
65
  end
62
66
 
67
+ desc "package", "Cache the puppet modules in vendor/puppet/cache."
68
+ option "quiet", :type => :boolean, :default => false
69
+ option "verbose", :type => :boolean, :default => false
70
+ option "line-numbers", :type => :boolean, :default => false
71
+ option "clean", :type => :boolean, :default => false
72
+ option "strip-dot-git", :type => :boolean
73
+ option "path", :type => :string
74
+ option "destructive", :type => :boolean, :default => false
75
+ def package
76
+ environment.vendor!
77
+ install
78
+ end
79
+
63
80
  def version
64
81
  say "librarian-puppet v#{Librarian::Puppet::VERSION}"
65
82
  end
@@ -16,6 +16,18 @@ module Librarian
16
16
  project_path.join(part)
17
17
  end
18
18
 
19
+ def vendor_path
20
+ project_path.join('vendor/puppet')
21
+ end
22
+
23
+ def vendor_cache
24
+ vendor_path.join('cache')
25
+ end
26
+
27
+ def vendor_source
28
+ vendor_path.join('source')
29
+ end
30
+
19
31
  def cache_path
20
32
  project_path.join(".tmp/librarian/cache")
21
33
  end
@@ -23,6 +35,20 @@ module Librarian
23
35
  def scratch_path
24
36
  project_path.join(".tmp/librarian/scratch")
25
37
  end
38
+
39
+ def vendor!
40
+ vendor_cache.mkpath unless vendor_cache.exist?
41
+ vendor_source.mkpath unless vendor_source.exist?
42
+ end
43
+
44
+ def vendor?
45
+ vendor_path.exist?
46
+ end
47
+
48
+ def local?
49
+ config_db['mode'] == 'local'
50
+ end
51
+
26
52
  end
27
53
  end
28
54
  end
@@ -37,6 +37,14 @@ module Librarian
37
37
  end
38
38
 
39
39
  def install_version!(version, install_path)
40
+ if environment.local? && !vendored?(name, version)
41
+ raise Error, "Could not find a local copy of #{name} at #{version}."
42
+ end
43
+
44
+ if environment.vendor?
45
+ vendor_cache(name, version) unless vendored?(name, version)
46
+ end
47
+
40
48
  cache_version_unpacked! version
41
49
 
42
50
  if install_path.exist?
@@ -69,7 +77,41 @@ module Librarian
69
77
 
70
78
  path.mkpath
71
79
 
72
- output = `puppet module install -i #{path.to_s} --modulepath #{path.to_s} --ignore-dependencies #{name} 2>&1`
80
+ target = vendored?(name, version) ? vendored_path(name, version) : name
81
+
82
+ `puppet module install --target-dir #{path} --modulepath #{path} --ignore-dependencies #{target}`
83
+ end
84
+
85
+ def vendored?(name, version)
86
+ vendored_path(name, version).exist?
87
+ end
88
+
89
+ def vendored_path(name, version)
90
+ environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz")
91
+ end
92
+
93
+ def vendor_cache(name, version)
94
+ File.open(vendored_path(name, version).to_s, 'w') do |f|
95
+ download(name, version) do |data|
96
+ f << data
97
+ end
98
+ end
99
+ end
100
+
101
+ def download(name, version, &block)
102
+ data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
103
+
104
+ info = data[name].detect {|h| h['version'] == version.to_s }
105
+
106
+ stream(info['file'], &block)
107
+ end
108
+
109
+ def stream(file, &block)
110
+ Net::HTTP.get_response(URI.parse("#{source}#{file}")) do |res|
111
+ res.code
112
+
113
+ res.read_body(&block)
114
+ end
73
115
  end
74
116
 
75
117
  private
@@ -14,6 +14,38 @@ module Librarian
14
14
  command = %W(rev-parse #{reference}^{commit} --quiet)
15
15
  run!(command, :chdir => true).strip
16
16
  end
17
+
18
+ # Naming this method 'version' causes an exception to be raised.
19
+ def module_version
20
+ return '0.0.1' unless modulefile?
21
+
22
+ metadata = ::Puppet::ModuleTool::Metadata.new
23
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
24
+
25
+ metadata.version
26
+ end
27
+
28
+ def dependencies
29
+ return {} unless modulefile?
30
+
31
+ metadata = ::Puppet::ModuleTool::Metadata.new
32
+
33
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
34
+
35
+ metadata.dependencies.inject({}) do |h, dependency|
36
+ name = dependency.instance_variable_get(:@full_module_name)
37
+ version = dependency.instance_variable_get(:@version_requirement)
38
+ h.update(name => version)
39
+ end
40
+ end
41
+
42
+ def modulefile
43
+ File.join(path, 'Modulefile')
44
+ end
45
+
46
+ def modulefile?
47
+ File.exists?(modulefile)
48
+ end
17
49
  end
18
50
  end
19
51
  end
@@ -22,6 +54,60 @@ module Librarian
22
54
  module Source
23
55
  class Git < Librarian::Source::Git
24
56
  include Local
57
+
58
+ def cache!
59
+ return vendor_checkout! if vendor_cached?
60
+
61
+ if environment.local?
62
+ raise Error, "Could not find a local copy of #{uri} at #{sha}."
63
+ end
64
+
65
+ super
66
+
67
+ cache_in_vendor(repository.path) if environment.vendor?
68
+ end
69
+
70
+ def vendor_tgz
71
+ environment.vendor_source + "#{sha}.tar.gz"
72
+ end
73
+
74
+ def vendor_cached?
75
+ vendor_tgz.exist?
76
+ end
77
+
78
+ def vendor_checkout!
79
+ repository.path.rmtree if repository.path.exist?
80
+ repository.path.mkpath
81
+
82
+ Dir.chdir(repository.path.to_s) do
83
+ %x{tar xzf #{vendor_tgz}}
84
+ end
85
+
86
+ repository_cached!
87
+ end
88
+
89
+ def cache_in_vendor(tmp_path)
90
+ Dir.chdir(tmp_path.to_s) do
91
+ %x{git archive #{sha} | gzip > #{vendor_tgz}}
92
+ end
93
+ end
94
+
95
+ def fetch_version(name, extra)
96
+ cache!
97
+ found_path = found_path(name)
98
+ repository.module_version
99
+ end
100
+
101
+ def fetch_dependencies(name, version, extra)
102
+ repository.dependencies.map do |k, v|
103
+ Dependency.new(k, v, forge_source)
104
+ end
105
+ end
106
+
107
+ def forge_source
108
+ Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
109
+ end
110
+
25
111
  end
26
112
  end
27
113
  end
@@ -1,5 +1,5 @@
1
1
  module Librarian
2
2
  module Puppet
3
- VERSION = "0.9.3"
3
+ VERSION = "0.9.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 3
10
- version: 0.9.3
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Sharpe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-10 00:00:00 +10:00
18
+ date: 2012-08-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency