librarian-puppet 0.0.1.pre → 0.0.1.pre2

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.
@@ -2,6 +2,6 @@ require 'librarian/puppet/extension'
2
2
 
3
3
  module Librarian
4
4
  module Puppet
5
- VERSION = "0.0.1.pre"
5
+ VERSION = "0.0.1.pre2"
6
6
  end
7
7
  end
@@ -20,6 +20,19 @@ module Librarian
20
20
 
21
21
  def init
22
22
  copy_file environment.specfile_name
23
+
24
+ if File.exists? ".gitignore"
25
+ gitignore = File.read('.gitignore').split("\n")
26
+ else
27
+ gitignore = []
28
+ end
29
+
30
+ gitignore << "tmp/" unless gitignore.include? "tmp/"
31
+ gitignore << "modules/" unless gitignore.include? "modules/"
32
+
33
+ File.open(".gitignore", 'w') do |f|
34
+ f.puts gitignore.join("\n")
35
+ end
23
36
  end
24
37
 
25
38
  def version
@@ -7,6 +7,7 @@ module Librarian
7
7
 
8
8
  dependency :mod
9
9
 
10
+ source :forge => Source::Forge
10
11
  source :git => Source::Git
11
12
  source :path => Source::Path
12
13
  end
@@ -13,6 +13,14 @@ module Librarian
13
13
  def install_path
14
14
  project_path.join("modules")
15
15
  end
16
+
17
+ def cache_path
18
+ project_path.join(".tmp/librarian/cache")
19
+ end
20
+
21
+ def scratch_path
22
+ project_path.join(".tmp/librarian/scratch")
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -1,2 +1,3 @@
1
1
  require 'librarian/puppet/source/path'
2
2
  require 'librarian/puppet/source/git'
3
+ require 'librarian/puppet/source/forge'
@@ -0,0 +1,204 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'librarian/helpers/debug'
5
+
6
+ module Librarian
7
+ module Puppet
8
+ module Source
9
+ class Forge
10
+ include Helpers::Debug
11
+ class Repo
12
+
13
+ include Helpers::Debug
14
+ attr_accessor :source, :name
15
+ private :source=, :name=
16
+
17
+ def initialize(source, name)
18
+ self.source = source
19
+ self.name = name
20
+ end
21
+
22
+ def versions
23
+ data = api_call("#{name}.json")
24
+ data['releases'].map { |r| r['version'] }.sort.reverse
25
+ end
26
+
27
+ def dependencies(version)
28
+ data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
29
+ data[name].first['dependencies']
30
+ end
31
+
32
+ def manifests
33
+ versions.map do |version|
34
+ Manifest.new(source, name, version)
35
+ end
36
+ end
37
+
38
+ def install_version!(version, install_path)
39
+ cache_version_unpacked! version
40
+
41
+ if install_path.exist?
42
+ debug { "Deleting #{relative_path_to(install_path)}" }
43
+ install_path.rmtree
44
+ end
45
+
46
+ unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
47
+ debug { "Copying #{relative_path_to(unpacked_path)} to #{relative_path_to(install_path)}" }
48
+ FileUtils.cp_r(unpacked_path, install_path)
49
+ end
50
+
51
+ def environment
52
+ source.environment
53
+ end
54
+
55
+ def cache_path
56
+ @cache_path ||= source.cache_path.join(name)
57
+ end
58
+
59
+ def version_unpacked_cache_path(version)
60
+ cache_path.join('version').join(hexdigest(version.to_s))
61
+ end
62
+
63
+ def hexdigest(value)
64
+ Digest::MD5.hexdigest(value)
65
+ end
66
+
67
+ def cache_version_unpacked!(version)
68
+ path = version_unpacked_cache_path(version)
69
+ return if path.directory?
70
+
71
+ path.mkpath
72
+
73
+ output = `puppet module install -i #{path.to_s} --modulepath #{path.to_s} --ignore-dependencies #{name} 2>&1`
74
+ debug { output }
75
+ end
76
+
77
+ private
78
+
79
+ def api_call(path)
80
+ base_url = source.to_s
81
+ resp = Net::HTTP.get_response(URI.parse("#{base_url}/#{path}"))
82
+ data = resp.body
83
+
84
+ JSON.parse(data)
85
+ end
86
+ end
87
+
88
+ class << self
89
+ LOCK_NAME = 'FORGE'
90
+
91
+ def lock_name
92
+ LOCK_NAME
93
+ end
94
+
95
+ def from_lock_options(environment, options)
96
+ new(environment, options[:remote], options.reject { |k, v| k == :remote })
97
+ end
98
+
99
+ def from_spec_args(environment, uri, options)
100
+ recognised_options = []
101
+ unrecognised_options = options.keys - recognised_options
102
+ unless unrecognised_options.empty?
103
+ raise Error, "unrecognised options: #{unrecognised_options.join(", ")}"
104
+ end
105
+
106
+ new(environment, uri, options)
107
+ end
108
+ end
109
+
110
+ attr_accessor :environment
111
+ private :environment=
112
+ attr_reader :uri
113
+
114
+ def initialize(environment, uri, options = {})
115
+ self.environment = environment
116
+ @uri = uri
117
+ @cache_path = nil
118
+ end
119
+
120
+ def to_s
121
+ uri
122
+ end
123
+
124
+ def ==(other)
125
+ other &&
126
+ self.class == other.class &&
127
+ self.uri == other.uri
128
+ end
129
+
130
+ def to_spec_args
131
+ [uri, {}]
132
+ end
133
+
134
+ def to_lock_options
135
+ {:remote => uri}
136
+ end
137
+
138
+ def pinned?
139
+ false
140
+ end
141
+
142
+ def unpin!
143
+ end
144
+
145
+ def install!(manifest)
146
+ manifest.source == self or raise ArgumentError
147
+
148
+ name = manifest.name
149
+ version = manifest.version
150
+ install_path = install_path(name)
151
+ repo = repo(name)
152
+
153
+ debug { "Installing #{manifest}" }
154
+
155
+ repo.install_version! version, install_path
156
+ end
157
+
158
+ def manifest(name, version, dependencies)
159
+ manifest = Manifest.new(self, name)
160
+ manifest.version = version
161
+ manifest.dependencies = dependencies
162
+ manifest
163
+ end
164
+
165
+ def cache_path
166
+ @cache_path ||= begin
167
+ dir = Digest::MD5.hexdigest(uri)
168
+ environment.cache_path.join("source/puppet/forge/#{dir}")
169
+ end
170
+ end
171
+
172
+ def install_path(name)
173
+ environment.install_path.join(name.split('/').last)
174
+ end
175
+
176
+ def fetch_version(name, version_uri)
177
+ versions = repo(name).versions
178
+ if versions.include? version_uri
179
+ version_uri
180
+ else
181
+ versions.first
182
+ end
183
+ end
184
+
185
+ def fetch_dependencies(name, version, version_uri)
186
+ repo(name).dependencies(version).map do |k, v|
187
+ Dependency.new(k, v, nil)
188
+ end
189
+ end
190
+
191
+ def manifests(name)
192
+ repo(name).manifests
193
+ end
194
+
195
+ private
196
+
197
+ def repo(name)
198
+ @repo ||= {}
199
+ @repo[name] ||= Repo.new(self, name)
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  'lib/librarian/puppet/environment.rb',
24
24
  'lib/librarian/puppet/extension.rb',
25
25
  'lib/librarian/puppet/source.rb',
26
+ 'lib/librarian/puppet/source/forge.rb',
26
27
  'lib/librarian/puppet/source/git.rb',
27
28
  'lib/librarian/puppet/source/local.rb',
28
29
  'lib/librarian/puppet/source/path.rb',
@@ -35,18 +35,18 @@ module Librarian
35
35
  source_type_name = lines.shift
36
36
  source[:type] = source_type_names_map[source_type_name]
37
37
  options = {}
38
- while lines.first =~ /^ {2}([\w-]+):\s+(.+)$/
38
+ while lines.first =~ /^ {2}([\w\/-]+):\s+(.+)$/
39
39
  lines.shift
40
40
  options[$1.to_sym] = $2
41
41
  end
42
42
  source[:options] = options
43
43
  lines.shift # specs
44
44
  manifests = {}
45
- while lines.first =~ /^ {4}([\w-]+) \((.*)\)$/
45
+ while lines.first =~ /^ {4}([\w\/-]+) \((.*)\)$/
46
46
  lines.shift
47
47
  name = $1
48
48
  manifests[name] = {:version => $2, :dependencies => {}}
49
- while lines.first =~ /^ {6}([\w-]+) \((.*)\)$/
49
+ while lines.first =~ /^ {6}([\w\/-]+) \((.*)\)$/
50
50
  lines.shift
51
51
  manifests[name][:dependencies][$1] = $2.split(/,\s*/)
52
52
  end
@@ -58,7 +58,7 @@ module Librarian
58
58
  manifests_index = Hash[manifests.map{|m| [m.name, m]}]
59
59
  raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
60
60
  dependencies = []
61
- while lines.first =~ /^ {2}([\w-]+)(?: \((.*)\))?$/
61
+ while lines.first =~ /^ {2}([\w\/-]+)(?: \((.*)\))?$/
62
62
  lines.shift
63
63
  name, requirement = $1, $2.split(/,\s*/)
64
64
  dependencies << Dependency.new(name, requirement, manifests_index[name].source)
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: 0.0.1.pre
4
+ version: 0.0.1.pre2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-05 00:00:00.000000000 Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70331391132760 !ruby/object:Gem::Requirement
16
+ requirement: &70256438580160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0.15'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70331391132760
24
+ version_requirements: *70256438580160
25
25
  description: another placeholder!
26
26
  email:
27
27
  - tim@sharpe.id.au
@@ -40,6 +40,7 @@ files:
40
40
  - lib/librarian/puppet/environment.rb
41
41
  - lib/librarian/puppet/extension.rb
42
42
  - lib/librarian/puppet/source.rb
43
+ - lib/librarian/puppet/source/forge.rb
43
44
  - lib/librarian/puppet/source/git.rb
44
45
  - lib/librarian/puppet/source/local.rb
45
46
  - lib/librarian/puppet/source/path.rb