simp-metadata 0.4.4 → 0.5.2

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