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
@@ -4,17 +4,15 @@ module Simp
4
4
  module Commands
5
5
  class Clone < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
7
  options = defaults(argv) do |opts|
9
- opts.banner = "Usage: simp-metadata clone <source_release> <target_release>"
8
+ opts.banner = 'Usage: simp-metadata clone <source_release> <target_release>'
10
9
  end
10
+
11
11
  engine, root = get_engine(engine, options)
12
12
 
13
13
  begin
14
14
  engine.releases.create(argv[1], argv[0])
15
- if (root == true)
16
- engine.save((["simp-metadata", "clone"] + argv).join(" "))
17
- end
15
+ engine.save((['simp-metadata', 'clone'] + argv).join(' ')) if root
18
16
  rescue RuntimeError => e
19
17
  Simp::Metadata.critical(e.message)
20
18
  exit 5
@@ -3,105 +3,143 @@ module Simp
3
3
  module Metadata
4
4
  module Commands
5
5
  class Component < Simp::Metadata::Commands::Base
6
-
7
6
  def run(argv, engine = nil)
7
+ subcommand = argv[0]
8
+
9
+ case subcommand
10
+ when '--help', '-h'
11
+ options = defaults(argv) do |opts|
12
+ opts.banner = 'Usage: simp-metadata component [ view | diff | download | build | update | create ]'
13
+ end
14
+
15
+ when 'create'
16
+ options = defaults(argv) do |opts|
17
+ opts.banner = 'Usage: simp-metadata component create <component_name> name=<value>'
18
+ end
19
+ engine, root = get_engine(engine, options)
20
+ component = argv[1]
21
+ argv.shift
22
+ data = { 'locations' => [{ 'primary' => true }] }
23
+ argv.each do |argument|
24
+ splitted = argument.split('=')
25
+ name = splitted[0]
26
+ value = splitted[1]
27
+ case name
28
+ when 'authoritative'
29
+ data['authoritative'] = value.to_s == 'true'
30
+ when 'format'
31
+ data['format'] = value
32
+ when 'component-type'
33
+ data['component-type'] = value
34
+ when 'primary_url'
35
+ data['locations'].first['url'] = value
36
+ when 'primary_url_type'
37
+ data['locations'].first['type'] = value
38
+ end
39
+ end
40
+ engine.components.create(component, data)
8
41
 
42
+ when 'update'
43
+ options = defaults(argv) do |opts|
44
+ opts.banner = 'Usage: simp-metadata component update <component> <setting> <value>'
45
+ end
46
+ engine, root = get_engine(engine, options)
47
+ component = argv[1]
48
+ setting = argv[2]
49
+ value = argv[3]
50
+ object = engine.components[component]
51
+ unless object.methods.include?(setting.to_sym)
52
+ Simp::Metadata.critical("#{setting} is not a valid setting")
53
+ exit 7
54
+ end
55
+ begin
56
+ object.send("#{setting}=".to_sym, value)
57
+ rescue NoMethodError => ex
58
+ Simp::Metadata.critical("#{setting} is a read-only setting")
59
+ exit 6
60
+ end
9
61
 
10
- begin
11
- subcommand = argv[0]
12
- case subcommand
13
- when "--help", "-h"
14
- options = defaults(argv) do |opts|
15
- opts.banner = "Usage: simp-metadata component [ create | view | update | diff ]"
16
- end
17
- when "create"
18
- options = defaults(argv) do |opts|
19
- opts.banner = "Usage: simp-metadata component create <component_name> name=<value>"
20
- end
21
- engine, root = get_engine(engine, options)
22
- component = argv[1]
23
- argv.shift
24
- data = {"locations" => [{"primary" => true}]}
25
- argv.each do |argument|
26
- splitted = argument.split("=")
27
- name = splitted[0]
28
- value = splitted[1]
29
- case name
30
- when "authoritative"
31
- data["authoritiative"] = value.to_s == "true"
32
- when "format"
33
- data["format"] = value
34
- when "component-type"
35
- data["component-type"] = value
36
- when "primary_url"
37
- data["locations"].first["url"] = value
38
- when "primary_url_type"
39
- data["locations"].first["type"] = value
40
- end
41
- end
42
- engine.components.create(component, data)
43
- when "update"
44
- options = defaults(argv) do |opts|
45
- opts.banner = "Usage: simp-metadata component update <component> <setting> <value>"
46
- end
47
- engine, root = get_engine(engine, options)
48
- component = argv[1]
49
- setting = argv[2]
50
- value = argv[3]
51
- object = engine.components[component]
52
- unless (object.methods.include?(setting.to_sym))
53
- Simp::Metadata.critical("#{setting} is not a valid setting")
54
- exit 7
55
- end
56
- begin
57
- object.send("#{setting}=".to_sym, value)
58
- rescue NoMethodError => ex
59
- Simp::Metadata.critical("#{setting} is a read-only setting")
60
- exit 6
61
- end
62
+ when 'view'
63
+ options = defaults(argv) do |opts|
64
+ opts.banner = 'Usage: simp-metadata component view <component> [attribute]'
65
+ end
66
+ engine, root = get_engine(engine, options)
67
+ component = argv[1]
68
+ attribute = argv[2]
69
+ if engine.components.key?(component)
70
+ if options['release'].nil?
71
+ comp = engine.components[component]
72
+ else
73
+ comp = engine.releases[options['release']].components[component]
74
+ end
75
+ view = comp.view(attribute)
76
+ puts view.to_yaml
77
+ else
78
+ Simp::Metadata.critical("Unable to find component named #{component}")
79
+ exit 5
80
+ end
62
81
 
63
- when "view"
64
- options = defaults(argv) do |opts|
65
- opts.banner = "Usage: simp-metadata component view <component> [attribute]"
66
- end
67
- engine, root = get_engine(engine, options)
68
- component = argv[1]
69
- attribute = argv[2]
70
- if (engine.components.key?(component))
71
- if (options["release"] == nil)
72
- comp = engine.components[component]
73
- else
74
- comp = engine.releases[options["release"]].components[component]
75
- end
76
- view = comp.view(attribute)
77
- puts view.to_yaml
78
- else
79
- Simp::Metadata.critical("Unable to find component named #{component}")
80
- exit 5
81
- end
82
+ when 'diff'
83
+ options = defaults(argv) do |opts|
84
+ opts.banner = 'Usage: simp-metadata component diff <release1> <release2> <component> [attribute]'
85
+ end
86
+ engine, root = get_engine(engine, options)
87
+ release1 = argv[1]
88
+ release2 = argv[2]
89
+ component = argv[3]
90
+ attribute = argv[4]
91
+ component1 = engine.releases[release1].components[component]
92
+ component2 = engine.releases[release2].components[component]
93
+ diff = component1.diff(component2, attribute)
94
+ puts diff.to_yaml
82
95
 
83
- when "diff"
84
- options = defaults(argv) do |opts|
85
- opts.banner = "Usage: simp-metadata component diff <release1> <release2> <component> [attribute]"
86
- end
87
- engine, root = get_engine(engine, options)
88
- release1 = argv[1]
89
- release2 = argv[2]
90
- component = argv[3]
91
- attribute = argv[4]
92
- component1 = engine.releases[release1].components[component]
93
- component2 = engine.releases[release2].components[component]
94
- diff = component1.diff(component2, attribute)
95
- puts diff.to_yaml
96
+ when 'download'
97
+ options = defaults(argv) do |opts|
98
+ opts.banner = 'Usage: simp-metadata component download -v <version> <component> [destination] [source]'
99
+ end
100
+ engine, root = get_engine(engine, options)
101
+ component = argv[1]
102
+ destination = argv[2]
103
+ source = argv[3]
104
+ if engine.components.key?(component)
105
+ if options['release'].nil?
106
+ comp = engine.components[component]
107
+ else
108
+ comp = engine.releases[options['release']].components[component]
109
+ end
110
+ comp.download(destination, source)
111
+ else
112
+ Simp::Metadata.critical('Unable to find component to download')
113
+ exit 5
96
114
  end
97
115
 
98
- if (root == true)
99
- engine.save((["simp-metadata", "component"] + argv).join(" "))
116
+ when 'build'
117
+ options = defaults(argv) do |opts|
118
+ opts.banner = 'Usage: simp-metadata component build <component> [destination]'
119
+ end
120
+ engine, root = get_engine(engine, options)
121
+ component = argv[1]
122
+ destination = argv[2]
123
+ if engine.components.key?(component)
124
+ if options['release'].nil?
125
+ comp = engine.components[component]
126
+ else
127
+ comp = engine.releases[options['release']].components[component]
128
+ end
129
+ comp.build(destination)
130
+ else
131
+ Simp::Metadata.critical('Unable to build component')
132
+ exit 5
100
133
  end
101
- rescue RuntimeError => e
102
- Simp::Metadata.critical(e.message)
103
- exit 5
134
+
135
+ else
136
+ abort(Simp::Metadata.critical("Unrecognized subcommand '#{subcommand}}'.")[0])
104
137
  end
138
+
139
+ engine.save((['simp-metadata', 'component'] + argv).join(' ')) if root
140
+ rescue RuntimeError => e
141
+ Simp::Metadata.critical(e.message)
142
+ exit 5
105
143
  end
106
144
  end
107
145
  end
@@ -4,16 +4,15 @@ module Simp
4
4
  module Commands
5
5
  class Delete < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
- options = defaults(argv) do | opts|
9
- opts.banner = "Usage: simp-metadata delete <component_name>"
7
+ options = defaults(argv) do |opts|
8
+ opts.banner = 'Usage: simp-metadata delete <component_name>'
10
9
  end
11
10
 
12
11
  engine, root = get_engine(engine, options)
13
12
  begin
14
13
  engine.releases.delete(argv[0])
15
- if (root == true)
16
- engine.save((["simp-metadata", "delete"] + argv).join(" "))
14
+ if root == true
15
+ engine.save((['simp-metadata', 'delete'] + argv).join(' '))
17
16
  end
18
17
  rescue RuntimeError => e
19
18
  Simp::Metadata.critical(e.message)
@@ -4,14 +4,12 @@ module Simp
4
4
  module Commands
5
5
  class Pry < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
7
  options = defaults(argv) do |opts|
9
- opts.banner = "Usage: simp-metadata pry"
8
+ opts.banner = 'Usage: simp-metadata pry'
10
9
  end
11
10
 
12
11
  engine, root = get_engine(engine, options)
13
12
  require 'pry'
14
- binding.pry
15
13
  end
16
14
  end
17
15
  end
@@ -4,38 +4,37 @@ module Simp
4
4
  module Commands
5
5
  class Release < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
7
  options = defaults(argv) do |opts|
9
- opts.banner = "Usage: simp-metadata release <release_name> [components]"
10
- opts.banner = " simp-metadata release diff <release1> <release2>"
8
+ opts.banner = 'Usage: simp-metadata release <release_name> [components]'
9
+ opts.banner = ' simp-metadata release diff <release1> <release2>'
11
10
  end
12
-
13
-
14
11
  engine, root = get_engine(engine, options)
15
12
  begin
16
13
  section = argv[0]
14
+
17
15
  case section
18
- when "components"
19
- puts engine.releases[options["release"]].components.keys.join("\n")
16
+ when 'components'
17
+ puts engine.releases[options['release']].components.keys.join("\n")
20
18
 
21
- when "puppetfile"
22
- type = argv[1]
23
- puts engine.releases[options["release"]].puppetfile({ "type" => type})
19
+ when 'puppetfile'
20
+ type = argv[1]
21
+ puts engine.releases[options['release']].puppetfile('type' => type)
24
22
 
25
- when "diff"
26
- release1 = argv[1]
27
- release2 = argv[2]
28
- attribute = argv[3]
29
- release1 = engine.releases[release1]
30
- release2 = engine.releases[release2]
31
- diff = release1.diff(release2, attribute)
32
- puts diff.to_yaml
33
- else
34
- puts "components:"
35
- engine.releases[options["release"]].components.keys.each do |line|
36
- puts " #{line}"
37
- end
23
+ when 'diff'
24
+ release1 = argv[1]
25
+ release2 = argv[2]
26
+ attribute = argv[3]
27
+ release1 = engine.releases[release1]
28
+ release2 = engine.releases[release2]
29
+ diff = release1.diff(release2, attribute)
30
+ puts diff.to_yaml
31
+ else
32
+ puts 'components:'
33
+ engine.releases[options['release']].components.keys.each do |line|
34
+ puts " #{line}"
35
+ end
38
36
  end
37
+
39
38
  rescue RuntimeError => e
40
39
  Simp::Metadata.critical(e.message)
41
40
  exit 5
@@ -4,12 +4,10 @@ module Simp
4
4
  module Commands
5
5
  class Releases < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
7
  options = defaults(argv) do |opts|
9
- opts.banner = "Usage: simp-metadata releases"
8
+ opts.banner = 'Usage: simp-metadata releases'
10
9
  end
11
10
 
12
-
13
11
  engine, root = get_engine(engine, options)
14
12
  begin
15
13
  puts engine.releases.keys
@@ -4,27 +4,24 @@ module Simp
4
4
  module Commands
5
5
  class Save < Simp::Metadata::Commands::Base
6
6
  def run(argv, engine = nil)
7
-
8
7
  options = defaults(argv) do |opts|
9
- opts.banner = "Usage: simp-metadata save [options] [message]"
8
+ opts.banner = 'Usage: simp-metadata save [options] [message]'
10
9
  end
11
10
 
12
-
13
11
  engine, root = get_engine(engine, options)
14
- if (argv.size == 0)
15
- short = "Auto-saving using simp-metadata"
12
+ short = if argv.empty?
13
+ 'Auto-saving using simp-metadata'
14
+ else
15
+ argv.join(' ')
16
+ end
17
+
18
+ if $commandqueue.nil?
19
+ engine.save(short)
16
20
  else
17
- short = argv.join(" ")
18
- end
19
- if ($commandqueue != nil)
20
21
  message = []
21
- while $commandqueue.empty?() == false
22
- message << $commandqueue.pop
23
- end
22
+ message << $commandqueue.pop until $commandqueue.empty?
24
23
  puts message
25
24
  engine.save("#{short}\n\nsimp-metadata log:\n #{message.join("\n ")}")
26
- else
27
- engine.save(short)
28
25
  end
29
26
  end
30
27
  end
@@ -6,30 +6,27 @@ module Simp
6
6
  module Commands
7
7
  class Script < Simp::Metadata::Commands::Base
8
8
  def run(argv, engine = nil)
9
-
10
9
  options = defaults(argv) do |opts|
11
- opts.banner = "Usage: simp-metadata script [options] <filename>"
10
+ opts.banner = 'Usage: simp-metadata script [options] <filename>'
12
11
  end
13
12
 
14
- $commandqueue = Queue.new();
13
+ $commandqueue = Queue.new
15
14
 
16
15
  engine, root = get_engine(engine, options)
17
- unless (argv[0] != nil)
18
- Simp::Metadata.critical("filename must be specified")
16
+ if argv[0].nil?
17
+ Simp::Metadata.critical('filename must be specified')
19
18
  exit 3
20
19
  end
21
20
  data = File.read(argv[0])
22
21
  lines = data.split("\n")
23
22
  lines.each do |line|
24
- temp_argv = line.split(" ")
25
- unless (temp_argv.size == 0)
26
- unless (temp_argv[0] =~ /^#/)
27
- $commandqueue.push(line);
28
- command = Module.const_get("Simp::Metadata::Commands::#{temp_argv[0].gsub("-","_").capitalize}").new()
29
- temp_argv.shift
30
- command.run(temp_argv, engine)
31
- end
32
- end
23
+ temp_argv = line.split(' ')
24
+ next if temp_argv.empty?
25
+ next if temp_argv[0] =~ /^#/
26
+ $commandqueue.push(line)
27
+ command = Module.const_get("Simp::Metadata::Commands::#{temp_argv[0].tr('-', '_').capitalize}").new
28
+ temp_argv.shift
29
+ command.run(temp_argv, engine)
33
30
  end
34
31
  end
35
32
  end