simp-metadata 0.4.3
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 +7 -0
- data/README.md +0 -0
- data/Rakefile +69 -0
- data/exe/simp-install +8 -0
- data/exe/simp-media +8 -0
- data/exe/simp-metadata +8 -0
- data/lib/simp/install.rb +0 -0
- data/lib/simp/install/command.rb +70 -0
- data/lib/simp/media.rb +9 -0
- data/lib/simp/media/command.rb +69 -0
- data/lib/simp/media/engine.rb +104 -0
- data/lib/simp/media/type.rb +14 -0
- data/lib/simp/media/type/base.rb +63 -0
- data/lib/simp/media/type/control-repo.rb +211 -0
- data/lib/simp/media/type/internet.rb +38 -0
- data/lib/simp/media/type/iso.rb +9 -0
- data/lib/simp/media/type/local.rb +36 -0
- data/lib/simp/media/type/tar.rb +71 -0
- data/lib/simp/metadata.rb +416 -0
- data/lib/simp/metadata/bootstrap_source.rb +137 -0
- data/lib/simp/metadata/buildinfo.rb +58 -0
- data/lib/simp/metadata/command.rb +92 -0
- data/lib/simp/metadata/commands.rb +21 -0
- data/lib/simp/metadata/commands/base.rb +65 -0
- data/lib/simp/metadata/commands/clone.rb +26 -0
- data/lib/simp/metadata/commands/component.rb +109 -0
- data/lib/simp/metadata/commands/delete.rb +26 -0
- data/lib/simp/metadata/commands/pry.rb +19 -0
- data/lib/simp/metadata/commands/release.rb +47 -0
- data/lib/simp/metadata/commands/releases.rb +24 -0
- data/lib/simp/metadata/commands/save.rb +33 -0
- data/lib/simp/metadata/commands/script.rb +38 -0
- data/lib/simp/metadata/commands/search.rb +65 -0
- data/lib/simp/metadata/commands/set-write-url.rb +19 -0
- data/lib/simp/metadata/commands/set-write.rb +19 -0
- data/lib/simp/metadata/commands/update.rb +46 -0
- data/lib/simp/metadata/component.rb +388 -0
- data/lib/simp/metadata/components.rb +70 -0
- data/lib/simp/metadata/engine.rb +101 -0
- data/lib/simp/metadata/fake_uri.rb +19 -0
- data/lib/simp/metadata/git_ssh_wrapper.sh +6 -0
- data/lib/simp/metadata/location.rb +198 -0
- data/lib/simp/metadata/locations.rb +54 -0
- data/lib/simp/metadata/release.rb +119 -0
- data/lib/simp/metadata/releases.rb +57 -0
- data/lib/simp/metadata/source.rb +204 -0
- data/spec/simp/media/command_spec.rb +12 -0
- data/spec/simp/media/engine_spec.rb +28 -0
- data/spec/simp/media/type/control_repo_spec.rb +23 -0
- data/spec/simp/media/type/internet_spec.rb +29 -0
- data/spec/simp/media/type/iso_spec.rb +15 -0
- data/spec/simp/media/type/local_spec.rb +16 -0
- data/spec/simp/media/type/tar_spec.rb +16 -0
- data/spec/simp/metadata/buildinfo_spec.rb +64 -0
- data/spec/simp/metadata/commands/clone_spec.rb +8 -0
- data/spec/simp/metadata/component_spec.rb +90 -0
- data/spec/simp/metadata/engine_spec.rb +70 -0
- data/spec/simp/metadata/release_spec.rb +104 -0
- data/spec/simp/metadata/source_spec.rb +25 -0
- data/spec/simp/metadata_spec.rb +175 -0
- data/spec/spec_helper.rb +40 -0
- metadata +260 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'simp/metadata/components'
|
2
|
+
module Simp
|
3
|
+
module Metadata
|
4
|
+
class Release
|
5
|
+
attr_accessor :engine
|
6
|
+
attr_accessor :version
|
7
|
+
|
8
|
+
def initialize(engine, version)
|
9
|
+
@engine = engine
|
10
|
+
@version = version
|
11
|
+
end
|
12
|
+
|
13
|
+
def components(type = nil)
|
14
|
+
Simp::Metadata::Components.new(engine, version, type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def puppetfile_component(component, options)
|
18
|
+
contents = []
|
19
|
+
contents << "mod '#{component.name("puppetfile")}',"
|
20
|
+
contents << " :git => '#{component.primary.url}',"
|
21
|
+
if (component.ref == nil)
|
22
|
+
contents << " :tag => '#{component.tag}'"
|
23
|
+
else
|
24
|
+
contents << " :ref => '#{component.ref}'"
|
25
|
+
end
|
26
|
+
contents << ""
|
27
|
+
contents
|
28
|
+
end
|
29
|
+
|
30
|
+
def puppetfile(options = {})
|
31
|
+
contents = []
|
32
|
+
if (options["type"] == "simp-core")
|
33
|
+
contents << "moduledir 'src'"
|
34
|
+
contents << ""
|
35
|
+
contents << puppetfile_component(components['simp-doc'], options)
|
36
|
+
contents << puppetfile_component(components['simp-rsync'], options)
|
37
|
+
contents << "moduledir 'src/assets'"
|
38
|
+
contents << ""
|
39
|
+
components.each do |component|
|
40
|
+
if (component.component_type == "rpm")
|
41
|
+
contents << puppetfile_component(component, options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
contents << "moduledir 'src/rubygems'"
|
45
|
+
contents << ""
|
46
|
+
components.each do |component|
|
47
|
+
if (component.component_type == "rubygem")
|
48
|
+
contents << puppetfile_component(component, options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
contents << "moduledir 'src/puppet/modules'"
|
52
|
+
contents << ""
|
53
|
+
end
|
54
|
+
components.each do |component|
|
55
|
+
if (component.component_type == "puppet-module")
|
56
|
+
contents << puppetfile_component(component, options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
contents.join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s()
|
63
|
+
self.components.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def diff(compare_release, attribute)
|
67
|
+
diff = {}
|
68
|
+
|
69
|
+
current_hash = {}
|
70
|
+
compare_hash = {}
|
71
|
+
self.components.each do |comp|
|
72
|
+
self_component_hash = {}
|
73
|
+
comp.each do |key, value|
|
74
|
+
if (attribute != nil)
|
75
|
+
if (key.to_s == attribute)
|
76
|
+
self_component_hash[key] = value.to_s
|
77
|
+
end
|
78
|
+
else
|
79
|
+
self_component_hash[key] = value.to_s
|
80
|
+
end
|
81
|
+
current_hash[comp.name] = self_component_hash
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
compare_release.components.each do |comp|
|
86
|
+
self_component_hash = {}
|
87
|
+
comp.each do |key, value|
|
88
|
+
if (attribute != nil)
|
89
|
+
if (key.to_s == attribute)
|
90
|
+
self_component_hash[key] = value.to_s
|
91
|
+
end
|
92
|
+
else
|
93
|
+
self_component_hash[key] = value.to_s
|
94
|
+
end
|
95
|
+
compare_hash[comp.name] = self_component_hash
|
96
|
+
end
|
97
|
+
end
|
98
|
+
current_hash.each do |comp, hash|
|
99
|
+
|
100
|
+
diff_hash = {}
|
101
|
+
hash.each do |key, value|
|
102
|
+
if (compare_hash.key?(comp))
|
103
|
+
if (compare_hash[comp][key] != value)
|
104
|
+
diff_hash[key] = {
|
105
|
+
"original" => "#{value}",
|
106
|
+
"changed" => "#{compare_hash[comp][key]}"
|
107
|
+
}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
unless diff_hash.empty?
|
112
|
+
diff[comp] = diff_hash
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return diff
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'simp/metadata/release'
|
2
|
+
|
3
|
+
module Simp
|
4
|
+
module Metadata
|
5
|
+
class Releases
|
6
|
+
include Enumerable
|
7
|
+
attr_accessor :engine
|
8
|
+
|
9
|
+
def initialize(engine)
|
10
|
+
@engine = engine
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(&block)
|
14
|
+
self.keys.each do |version|
|
15
|
+
yield self[version]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](index)
|
20
|
+
Simp::Metadata::Release.new(engine, index)
|
21
|
+
end
|
22
|
+
|
23
|
+
def keys()
|
24
|
+
result = {}
|
25
|
+
engine.sources.each do |name, source|
|
26
|
+
source.releases.keys.each do |name|
|
27
|
+
result[name] = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
result.keys
|
31
|
+
end
|
32
|
+
|
33
|
+
def size()
|
34
|
+
self.keys.size
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s()
|
38
|
+
self.keys.to_s
|
39
|
+
end
|
40
|
+
def delete(version)
|
41
|
+
engine.sources.each do |name, metadata_source|
|
42
|
+
if (metadata_source.writable?)
|
43
|
+
metadata_source.delete_release(version)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def create(destination, source = 'master')
|
48
|
+
engine.sources.each do |name, metadata_source|
|
49
|
+
if (metadata_source.writable?)
|
50
|
+
metadata_source.create_release(destination, source)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Simp
|
5
|
+
module Metadata
|
6
|
+
class Source
|
7
|
+
|
8
|
+
attr_accessor :url
|
9
|
+
attr_accessor :cachepath
|
10
|
+
attr_accessor :components
|
11
|
+
attr_accessor :releases
|
12
|
+
attr_accessor :basename
|
13
|
+
attr_accessor :data
|
14
|
+
attr_accessor :releases
|
15
|
+
attr_accessor :components
|
16
|
+
attr_accessor :name
|
17
|
+
attr_accessor :edition
|
18
|
+
attr_accessor :engine
|
19
|
+
|
20
|
+
def initialize(args)
|
21
|
+
unless (args.key?(:engine))
|
22
|
+
raise ":engine must be specified when initializing a metadata source"
|
23
|
+
end
|
24
|
+
unless (args.key?(:name))
|
25
|
+
raise ":name must be specified when initializing a metadata source"
|
26
|
+
end
|
27
|
+
unless (args.key?(:component))
|
28
|
+
raise ":component must be specified when initializing a metadata source"
|
29
|
+
end
|
30
|
+
unless (args.key?(:edition))
|
31
|
+
raise ":edition must be specified when initializing a metadata source"
|
32
|
+
end
|
33
|
+
|
34
|
+
@engine = args[:engine]
|
35
|
+
@name = args[:name]
|
36
|
+
@component = args[:component]
|
37
|
+
@edition = args[:edition]
|
38
|
+
|
39
|
+
if (args[:url])
|
40
|
+
@url = args[:url]
|
41
|
+
else
|
42
|
+
@url = @component.primary.url
|
43
|
+
end
|
44
|
+
@write_url = @url
|
45
|
+
cachepath = args[:cachepath]
|
46
|
+
@components = {}
|
47
|
+
@releases = {}
|
48
|
+
@data = {}
|
49
|
+
@cleanup = []
|
50
|
+
|
51
|
+
if (cachepath == nil)
|
52
|
+
@cachepath = Dir.mktmpdir("cachedir")
|
53
|
+
@cleanup << @cachepath
|
54
|
+
else
|
55
|
+
@cachepath = File.absolute_path(cachepath);
|
56
|
+
end
|
57
|
+
retval = Simp::Metadata.download_component(@component, {"target" => @cachepath})
|
58
|
+
load_from_dir(retval["path"])
|
59
|
+
|
60
|
+
@dirty = false
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_s()
|
64
|
+
self.name
|
65
|
+
end
|
66
|
+
|
67
|
+
def writable?()
|
68
|
+
true
|
69
|
+
end
|
70
|
+
def write_url
|
71
|
+
@write_url
|
72
|
+
end
|
73
|
+
def write_url=(value)
|
74
|
+
if (value != @url)
|
75
|
+
@write_url = value
|
76
|
+
FileUtils.rm_r("#{@cachepath}/#{@component.name}")
|
77
|
+
retval = Simp::Metadata.download_component(@component, {"target" => @cachepath, "url" => value})
|
78
|
+
load_from_dir(retval["path"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
def release(version)
|
82
|
+
if (self.releases.key?(version))
|
83
|
+
self.releases[version]
|
84
|
+
else
|
85
|
+
{}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def delete_release(version)
|
90
|
+
if (@releases.key?(version))
|
91
|
+
self.dirty = true
|
92
|
+
@releases.delete(version)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_release(destination, source = 'master')
|
97
|
+
if (@releases.key?(destination))
|
98
|
+
raise "destination version #{destination} already exists"
|
99
|
+
end
|
100
|
+
unless (@releases.key?(source))
|
101
|
+
raise "source version #{source} doesn't exist"
|
102
|
+
end
|
103
|
+
self.dirty = true
|
104
|
+
@releases[destination] = Marshal.load(Marshal.dump(@releases[source]))
|
105
|
+
end
|
106
|
+
|
107
|
+
def dirty?()
|
108
|
+
@dirty
|
109
|
+
end
|
110
|
+
|
111
|
+
def dirty=(value)
|
112
|
+
@dirty = value
|
113
|
+
end
|
114
|
+
|
115
|
+
def save(message = "Auto-saving using simp-metadata")
|
116
|
+
if (self.dirty? == true)
|
117
|
+
puts @load_path
|
118
|
+
# XXX ToDo: Write files to yaml, commit and push (where appropriate)
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
Simp::Metadata.run("cd #{@load_path} && rm -rf v1")
|
123
|
+
FileUtils.mkdir_p("#{@load_path}/v1")
|
124
|
+
File.open("#{@load_path}/v1/components.yaml", 'w') {|file| file.write({"components" => @components}.to_yaml)}
|
125
|
+
@releases.each do |releasename, data|
|
126
|
+
directory = "releases"
|
127
|
+
case releasename
|
128
|
+
when /.*-[Aa][Ll][Pp][Hh][Aa].*/
|
129
|
+
directory = "prereleases"
|
130
|
+
when /.*-[Bb][Ee][Tt][Aa].*/
|
131
|
+
directory = "prereleases"
|
132
|
+
when /.*-[Rr][Cc].*/
|
133
|
+
directory = "prereleases"
|
134
|
+
when /^nightly\-/
|
135
|
+
directory = "nightlies"
|
136
|
+
when /develop/
|
137
|
+
directory = "channels"
|
138
|
+
when /development/
|
139
|
+
directory = "channels"
|
140
|
+
when /master/
|
141
|
+
directory = "channels"
|
142
|
+
when /^test\-/
|
143
|
+
directory = "tests"
|
144
|
+
else
|
145
|
+
directory = "releases"
|
146
|
+
end
|
147
|
+
FileUtils.mkdir_p("#{@load_path}/v1/#{directory}")
|
148
|
+
File.open("#{@load_path}/v1/#{directory}/#{releasename}.yaml", 'w') {|file| file.write({"releases" => {"#{releasename}" => data}}.to_yaml)}
|
149
|
+
end
|
150
|
+
Simp::Metadata.run("cd #{@load_path} && git remote add upstream #{write_url}")
|
151
|
+
Simp::Metadata.run("cd #{@load_path} && git remote set-url upstream #{write_url}")
|
152
|
+
exitcode = Simp::Metadata.run("cd #{@load_path} && git add -A && git commit -m '#{message}'; git push upstream master")
|
153
|
+
if (exitcode != 0)
|
154
|
+
Simp::Metadata.critical("error committing changes")
|
155
|
+
raise "#{exitcode}"
|
156
|
+
else
|
157
|
+
puts "Successfully updated #{name}"
|
158
|
+
end
|
159
|
+
self.dirty = false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def load_from_dir(path)
|
164
|
+
@load_path = path
|
165
|
+
Dir.chdir(path) do
|
166
|
+
Dir.glob("**/*.yaml") do |filename|
|
167
|
+
begin
|
168
|
+
hash = YAML.load_file(filename)
|
169
|
+
@data = deep_merge(@data, hash)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
unless @data['releases'] == nil
|
174
|
+
@releases = @data['releases']
|
175
|
+
end
|
176
|
+
unless @data['components'] == nil
|
177
|
+
@components = @data['components']
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def deep_merge(target_hash, source_hash)
|
182
|
+
source_hash.each do |key, value|
|
183
|
+
if (target_hash.key?(key))
|
184
|
+
if (value.class == Hash)
|
185
|
+
self.deep_merge(target_hash[key], value)
|
186
|
+
else
|
187
|
+
target_hash[key] = value
|
188
|
+
end
|
189
|
+
else
|
190
|
+
target_hash[key] = value
|
191
|
+
end
|
192
|
+
end
|
193
|
+
target_hash
|
194
|
+
end
|
195
|
+
|
196
|
+
def cleanup()
|
197
|
+
@cleanup.each do |path|
|
198
|
+
FileUtils.rmtree(path)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simp/media'
|
3
|
+
require 'simp/media/command'
|
4
|
+
|
5
|
+
describe Simp::Media::Command do
|
6
|
+
xit "Should display help when no options are passed" do
|
7
|
+
# Create an output capture system.
|
8
|
+
command = Simp::Media::Command.new()
|
9
|
+
command.run([])
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simp/media'
|
3
|
+
|
4
|
+
describe Simp::Media::Engine do
|
5
|
+
it "should throw an error if input_type is nil" do
|
6
|
+
expect { engine = Simp::Media::Engine.new({"version" => "test-stub", "input_type" => nil}) }.to raise_error(RuntimeError, "input_type must be specified")
|
7
|
+
end
|
8
|
+
it "should throw an error if output_type is nil" do
|
9
|
+
expect { engine = Simp::Media::Engine.new({"version" => "test-stub", "output_type" => nil}) }.to raise_error(RuntimeError, "output_type must be specified")
|
10
|
+
end
|
11
|
+
it "should instantiate without errors" do
|
12
|
+
tempdir = Dir.mktmpdir("simp-media-rspec")
|
13
|
+
engine = Simp::Media::Engine.new({"version" => "test-stub", "edition" => "community", "output_type" => "tar", "output" => "#{tempdir}/test.tgz"})
|
14
|
+
expect(engine.loaded?).to match(true)
|
15
|
+
engine.cleanup()
|
16
|
+
engine = nil
|
17
|
+
FileUtils.rmtree(tempdir)
|
18
|
+
end
|
19
|
+
it "should run without errors" do
|
20
|
+
tempdir = Dir.mktmpdir("simp-media-rspec")
|
21
|
+
engine = Simp::Media::Engine.new({"version" => "test-stub", "edition" => "community", "output_type" => "tar", "output" => "#{tempdir}/test.tgz"})
|
22
|
+
expect(engine.loaded?).to match(true)
|
23
|
+
engine.run
|
24
|
+
engine.cleanup()
|
25
|
+
engine = nil
|
26
|
+
FileUtils.rmtree(tempdir)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simp/media'
|
3
|
+
|
4
|
+
describe Simp::Media::Type::Control_repo do
|
5
|
+
|
6
|
+
it "should throw an error if output is nil" do
|
7
|
+
expect { engine = Simp::Media::Engine.new({"version" => "test-stub", "output" => nil}) }.to raise_error(RuntimeError, "output must be specified for control-repo output")
|
8
|
+
end
|
9
|
+
it "should throw an error if output is not a git repo and it's not a local directory" do
|
10
|
+
expect { engine = Simp::Media::Engine.new({"version" => "test-stub", "output" => "https://localhost:6666/repo.git"}) }.to raise_error(RuntimeError, "output is not a valid control-repo")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create a bare repo when .git is part of the path" do
|
14
|
+
tempdir = Dir.mktmpdir("simp-media-rspec")
|
15
|
+
engine = Simp::Media::Engine.new({"version" => "test-stub", "output" => "file://#{tempdir}/control-repo.git"})
|
16
|
+
expect(engine.loaded?).to match(true)
|
17
|
+
engine.run()
|
18
|
+
engine.cleanup()
|
19
|
+
engine = nil
|
20
|
+
FileUtils.rmtree(tempdir)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|