simp-metadata 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +0 -0
  3. data/Rakefile +69 -0
  4. data/exe/simp-install +8 -0
  5. data/exe/simp-media +8 -0
  6. data/exe/simp-metadata +8 -0
  7. data/lib/simp/install.rb +0 -0
  8. data/lib/simp/install/command.rb +70 -0
  9. data/lib/simp/media.rb +9 -0
  10. data/lib/simp/media/command.rb +69 -0
  11. data/lib/simp/media/engine.rb +104 -0
  12. data/lib/simp/media/type.rb +14 -0
  13. data/lib/simp/media/type/base.rb +63 -0
  14. data/lib/simp/media/type/control-repo.rb +211 -0
  15. data/lib/simp/media/type/internet.rb +38 -0
  16. data/lib/simp/media/type/iso.rb +9 -0
  17. data/lib/simp/media/type/local.rb +36 -0
  18. data/lib/simp/media/type/tar.rb +71 -0
  19. data/lib/simp/metadata.rb +416 -0
  20. data/lib/simp/metadata/bootstrap_source.rb +137 -0
  21. data/lib/simp/metadata/buildinfo.rb +58 -0
  22. data/lib/simp/metadata/command.rb +92 -0
  23. data/lib/simp/metadata/commands.rb +21 -0
  24. data/lib/simp/metadata/commands/base.rb +65 -0
  25. data/lib/simp/metadata/commands/clone.rb +26 -0
  26. data/lib/simp/metadata/commands/component.rb +109 -0
  27. data/lib/simp/metadata/commands/delete.rb +26 -0
  28. data/lib/simp/metadata/commands/pry.rb +19 -0
  29. data/lib/simp/metadata/commands/release.rb +47 -0
  30. data/lib/simp/metadata/commands/releases.rb +24 -0
  31. data/lib/simp/metadata/commands/save.rb +33 -0
  32. data/lib/simp/metadata/commands/script.rb +38 -0
  33. data/lib/simp/metadata/commands/search.rb +65 -0
  34. data/lib/simp/metadata/commands/set-write-url.rb +19 -0
  35. data/lib/simp/metadata/commands/set-write.rb +19 -0
  36. data/lib/simp/metadata/commands/update.rb +46 -0
  37. data/lib/simp/metadata/component.rb +388 -0
  38. data/lib/simp/metadata/components.rb +70 -0
  39. data/lib/simp/metadata/engine.rb +101 -0
  40. data/lib/simp/metadata/fake_uri.rb +19 -0
  41. data/lib/simp/metadata/git_ssh_wrapper.sh +6 -0
  42. data/lib/simp/metadata/location.rb +198 -0
  43. data/lib/simp/metadata/locations.rb +54 -0
  44. data/lib/simp/metadata/release.rb +119 -0
  45. data/lib/simp/metadata/releases.rb +57 -0
  46. data/lib/simp/metadata/source.rb +204 -0
  47. data/spec/simp/media/command_spec.rb +12 -0
  48. data/spec/simp/media/engine_spec.rb +28 -0
  49. data/spec/simp/media/type/control_repo_spec.rb +23 -0
  50. data/spec/simp/media/type/internet_spec.rb +29 -0
  51. data/spec/simp/media/type/iso_spec.rb +15 -0
  52. data/spec/simp/media/type/local_spec.rb +16 -0
  53. data/spec/simp/media/type/tar_spec.rb +16 -0
  54. data/spec/simp/metadata/buildinfo_spec.rb +64 -0
  55. data/spec/simp/metadata/commands/clone_spec.rb +8 -0
  56. data/spec/simp/metadata/component_spec.rb +90 -0
  57. data/spec/simp/metadata/engine_spec.rb +70 -0
  58. data/spec/simp/metadata/release_spec.rb +104 -0
  59. data/spec/simp/metadata/source_spec.rb +25 -0
  60. data/spec/simp/metadata_spec.rb +175 -0
  61. data/spec/spec_helper.rb +40 -0
  62. metadata +260 -0
@@ -0,0 +1,70 @@
1
+ module Simp
2
+ module Metadata
3
+ class Components
4
+ include Enumerable
5
+ attr_accessor :engine
6
+ attr_accessor :version
7
+ attr_accessor :type
8
+
9
+ def initialize(engine, version = nil, type = nil)
10
+ @engine = engine
11
+ @version = version
12
+ @type = type
13
+ end
14
+
15
+ def to_s()
16
+ self.keys.to_s
17
+ end
18
+
19
+ def size()
20
+ self.keys.size
21
+ end
22
+
23
+ def each(&block)
24
+ self.keys.each do |version|
25
+ yield self[version]
26
+ end
27
+ end
28
+
29
+ def [](index)
30
+ Simp::Metadata::Component.new(engine, index, version)
31
+ end
32
+
33
+ def key?(name)
34
+ self.keys.include?(name)
35
+ end
36
+
37
+ def keys()
38
+ result = {}
39
+ if (version == nil)
40
+ engine.sources.each do |name, source|
41
+ source.components.keys.each do |name|
42
+ result[name] = true
43
+ end
44
+ end
45
+ else
46
+ engine.sources.each do |name, source|
47
+ if (source.releases.key?(version))
48
+ source.releases[version].each do |component, data|
49
+ result[component] = true
50
+ end
51
+ else
52
+ source.release(version).each do |component, data|
53
+ result[component] = true
54
+ end
55
+ end
56
+ end
57
+ end
58
+ result.keys
59
+ end
60
+
61
+ def create(name, settings = {})
62
+ unless (self.key?(name))
63
+ engine.writable_source.components[name] = settings
64
+ engine.writable_source.dirty = true
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,101 @@
1
+ # vim: set noexpandtab ts=4 sw=4:
2
+ require 'tmpdir'
3
+ require 'simp/metadata'
4
+
5
+ module Simp
6
+ module Metadata
7
+ class Engine
8
+ attr_accessor :sources
9
+
10
+ def initialize(cachepath = nil, metadatarepos = nil, edition = "community", options = {})
11
+
12
+ ENV['GIT_SSH'] = "#{File.dirname(__FILE__)}/git_ssh_wrapper.sh"
13
+ if (options["ssh_key"] != nil)
14
+ ENV['SIMP_METADATA_SSHKEY'] = "#{options["ssh_key"]}"
15
+ end
16
+ @sources = {}
17
+ @writable_source = "simp-metadata"
18
+ priority = 0
19
+ bootstrap_source = Simp::Metadata::Bootstrap_source.new(edition)
20
+ if (metadatarepos.class.to_s == "Hash")
21
+ metadatarepos.each do |reponame, url|
22
+ # XXX: ToDo replace with better logic once Simp::Metadata.download_component gets refactored.
23
+ # MUCH LAYERING VIOLATIONS
24
+ if (bootstrap_source.components.key?(reponame))
25
+ bootstrap_source.components[reponame]["locations"][0]["url"] = url
26
+ bootstrap_source.components[reponame]["locations"][0]["method"] = "git"
27
+ bootstrap_source.components[reponame]["locations"][0]["extract"] = false
28
+ end
29
+ end
30
+ end
31
+ @sources[bootstrap_source.name] = bootstrap_source
32
+ self.components.keys.each do |key|
33
+ component = self.components[key]
34
+ @sources[key] = Simp::Metadata::Source.new({:name => key, :component => component}.merge({cachepath: cachepath, edition: edition, engine: self}))
35
+ end
36
+ end
37
+
38
+ def components()
39
+ return Simp::Metadata::Components.new(self)
40
+ end
41
+
42
+ def releases()
43
+ return Simp::Metadata::Releases.new(self)
44
+ end
45
+
46
+ def dirty?()
47
+ dirty = false
48
+ @sources.each do |name, source|
49
+ if (source.dirty? == true)
50
+ dirty = true
51
+ end
52
+ end
53
+ dirty
54
+ end
55
+
56
+ def writable_source_name=(source)
57
+ @writable_source = source
58
+ end
59
+
60
+ def writable_source_name()
61
+ @writable_source
62
+ end
63
+
64
+
65
+ def writable_source()
66
+ @sources[@writable_source]
67
+ end
68
+
69
+ def writable_url(metadata_name, url)
70
+ @sources[metadata_name].write_url = url
71
+ end
72
+
73
+ def save(message = "Auto-saving using simp-metadata")
74
+ Simp::Metadata.debug2("Saving metadata")
75
+ @sources.each do |name, source|
76
+ if (source.dirty? == true)
77
+ Simp::Metadata.debug1("#{source} - dirty, saving")
78
+ source.save(message)
79
+ else
80
+ Simp::Metadata.debug1("#{source} - clean, not saving")
81
+ end
82
+ end
83
+ end
84
+
85
+ def ssh_key
86
+ @ssh_key
87
+ end
88
+
89
+ def ssh_key= (value)
90
+ @ssh_key = value
91
+ end
92
+
93
+ def cleanup()
94
+ @sources.each do |name, source|
95
+ source.cleanup
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,19 @@
1
+ require 'uri'
2
+
3
+ module Simp
4
+ module Metadata
5
+ class FakeURI
6
+ attr_accessor :scheme
7
+ attr_accessor :host
8
+ attr_accessor :port
9
+ attr_accessor :path
10
+ attr_accessor :user
11
+ def initialize(uri)
12
+ @uri = uri
13
+ end
14
+ def to_s
15
+ @uri
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ #! /bin/sh
2
+ if [ "${SIMP_METADATA_SSHKEY}" != "" ] ; then
3
+ ssh -i "${SIMP_METADATA_SSHKEY}" -o StrictHostKeyChecking=no "$@"
4
+ else
5
+ ssh -o StrictHostKeyChecking=no "$@"
6
+ fi
@@ -0,0 +1,198 @@
1
+ require 'uri'
2
+ module Simp
3
+ module Metadata
4
+ class Location
5
+
6
+ attr_accessor :locationinfo
7
+ attr_accessor :location
8
+ attr_accessor :component
9
+
10
+ def initialize(locationinfo, location, component)
11
+ @locationinfo = locationinfo
12
+ @location = location
13
+ @component = component
14
+ end
15
+
16
+ def to_s
17
+ self.url
18
+ end
19
+
20
+ def primary
21
+ if (location.key?("primary"))
22
+ location["primary"]
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ def keys()
29
+ ["extract", "primary", "method", "type", "url"]
30
+ end
31
+
32
+ def [] (index)
33
+ self.send index.to_sym
34
+ end
35
+
36
+ def each(&block)
37
+ self.keys.each do |key|
38
+ yield key, self[key]
39
+ end
40
+ end
41
+
42
+ def extract
43
+ if (location.key?("extract"))
44
+ location["extract"]
45
+ else
46
+ false
47
+ end
48
+ end
49
+
50
+ def method=(value)
51
+ @local_method = value
52
+ end
53
+
54
+ def method
55
+ if (@local_method)
56
+ @local_method
57
+ else
58
+ if (location.key?("type"))
59
+ if (location["type"] == "git")
60
+ method = "git"
61
+ else
62
+ method = "file"
63
+ end
64
+ else
65
+ if (location.key?("method"))
66
+ location["method"]
67
+ else
68
+ method = "file"
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def type
75
+ location["binary"]
76
+ end
77
+
78
+ def url=(value)
79
+ @local_url = value
80
+ end
81
+
82
+ def url
83
+ if (@local_url)
84
+ @local_url
85
+ else
86
+ base = self.real_url
87
+ uri = Simp::Metadata.uri(base)
88
+ case uri.scheme
89
+ when "simp-enterprise"
90
+ if (uri.query.class == String)
91
+ query_elements = uri.query.split("&")
92
+ newquery = []
93
+ found_version = false
94
+ found_filetype = false
95
+ query_elements.each do |element|
96
+ elements = element.split("=")
97
+ if (elements.size > 1)
98
+ if (elements[0] == "version")
99
+ found_version = true
100
+ elements[1] = component.version
101
+ newquery << elements.join("=")
102
+ elsif (elements[0] == "filetype")
103
+ found_filetype = true
104
+ elements[1] = component.extension
105
+ newquery << elements.join("=")
106
+ else
107
+ newquery << element
108
+ end
109
+ else
110
+ newquery << element
111
+ end
112
+ end
113
+ if (found_version == false)
114
+ newquery << "version=#{component.version}"
115
+ end
116
+ if (found_filetype == false)
117
+ newquery << "filetype=#{component.extension}"
118
+ end
119
+ uri.query = newquery.join("&")
120
+ end
121
+ uri.to_s
122
+
123
+ when "simp"
124
+ if (uri.query.class == String)
125
+ query_elements = uri.query.split("&")
126
+ newquery = []
127
+ found_version = false
128
+ found_filetype = false
129
+ query_elements.each do |element|
130
+ elements = element.split("=")
131
+ if (elements.size > 1)
132
+ if (elements[0] == "version")
133
+ found_version = true
134
+ elements[1] = component.version
135
+ newquery << elements.join("=")
136
+ elsif (elements[0] == "filetype")
137
+ found_filetype = true
138
+ elements[1] = component.extension
139
+ newquery << elements.join("=")
140
+ else
141
+ newquery << element
142
+ end
143
+ else
144
+ newquery << element
145
+ end
146
+ end
147
+ if (found_version == false)
148
+ newquery << "version=#{component.version}"
149
+ end
150
+ if (found_filetype == false)
151
+ newquery << "filetype=#{component.extension}"
152
+ end
153
+ uri.query = newquery.join("&")
154
+ end
155
+ uri.to_s
156
+ else
157
+ case component.component_type
158
+ when "rubygem"
159
+ if (base =~ /.*\.gem/)
160
+ else
161
+ "#{base}/#{component.asset_name}-#{component.version}.gem"
162
+ end
163
+ end
164
+ base
165
+ end
166
+ end
167
+
168
+ end
169
+
170
+ def real_url
171
+ if (component.compiled? == true)
172
+ case component.component_type
173
+ when "rubygem"
174
+ case component.release_source.to_s
175
+ when "simp-metadata"
176
+ return "simp:///#{component.name}/#{component.binaryname}"
177
+ when "enterprise-metadata"
178
+ return "simp-enterprise:///#{component.name}/#{component.binaryname}"
179
+ end
180
+ end
181
+ end
182
+ if (location.key?("url"))
183
+ location["url"]
184
+ else
185
+ if (location.key?("host"))
186
+ if (location.key?("path"))
187
+ if (location.key?("type"))
188
+ "https://#{location["host"]}/#{location["path"]}"
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,54 @@
1
+ module Simp
2
+ module Metadata
3
+ class Locations
4
+ include Enumerable
5
+ attr_accessor :locationinfo
6
+ attr_accessor :component
7
+
8
+ def initialize(locationinfo, component)
9
+ @locationinfo = locationinfo
10
+ @component = component
11
+ end
12
+
13
+ def data()
14
+ if (self.locationinfo["locations"] != nil)
15
+ self.locationinfo["locations"]
16
+ else
17
+ [ self.locationinfo["primary_source"] ] + self.locationinfo["mirrors"]
18
+ end
19
+ end
20
+
21
+ def to_s()
22
+ self.data.to_s
23
+ end
24
+
25
+ def size()
26
+ self.data.size
27
+ end
28
+
29
+ def each(&block)
30
+ self.data.each_index do |location|
31
+ yield self[location]
32
+ end
33
+ end
34
+
35
+ def [](location)
36
+ Simp::Metadata::Location.new(locationinfo,data[location], component)
37
+ end
38
+
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)
45
+ else
46
+ retval = self.first
47
+ end
48
+ end
49
+ return retval
50
+ end
51
+ end
52
+ end
53
+ end
54
+