reaper-man 0.1.8 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
- require 'reaper-man'
2
- require 'rubygems/package'
1
+ require "reaper-man"
2
+ require "rubygems/package"
3
3
 
4
4
  module ReaperMan
5
5
  class PackageList
@@ -11,6 +11,10 @@ module ReaperMan
11
11
  # @param conf [Hash]
12
12
  # @param package [String] path to package
13
13
  def add(hash, package)
14
+ if hash["rubygem"] && !hash.to_smash.get(:rubygem, :clean)
15
+ hash["rubygem"] = clean(hash["rubygem"])
16
+ hash["rubygem"]["clean"] = true
17
+ end
14
18
  info = extract_fields(package)
15
19
  filenames = inject_package(hash, info, package)
16
20
  filenames
@@ -21,13 +25,13 @@ module ReaperMan
21
25
  # @param conf [Hash] configuration hash
22
26
  # @param package_name [String] name
23
27
  # @param version [String]
24
- def remove(hash, package_name, version, args={})
28
+ def remove(hash, package_name, version, args = {})
25
29
  deleted = false
26
- if(hash['rubygems'][package_name])
27
- if(version)
28
- deleted = hash['rubygems'][package_name].delete(version)
30
+ if hash["rubygems"][package_name]
31
+ if version
32
+ deleted = hash["rubygems"][package_name].delete(version)
29
33
  else
30
- deleted = hash['rubygems'].delete(package_name)
34
+ deleted = hash["rubygems"].delete(package_name)
31
35
  end
32
36
  end
33
37
  !!deleted
@@ -40,12 +44,20 @@ module ReaperMan
40
44
  def extract_fields(package)
41
45
  spec = ::Gem::Package.new(package).spec
42
46
  fields = Smash[
43
- spec.to_yaml_properties.map do |var_name|
44
- [var_name.to_s.tr('@', ''), spec.instance_variable_get(var_name)]
45
- end
47
+ spec.class.attribute_names.map do |var_name|
48
+ value = spec.send(var_name)
49
+ next if value.nil? || (value.respond_to?(:empty?) && value.empty?)
50
+ [var_name, value]
51
+ end.compact
46
52
  ]
47
- fields['dependencies'] = fields['dependencies'].map do |dep|
48
- [dep.name, dep.requirement.to_s.split(',').map(&:strip)]
53
+ if fields["dependencies"]
54
+ fields["dependencies"] = fields["dependencies"].map do |dep|
55
+ [dep.name, dep.requirement.to_s.split(",").map(&:strip)]
56
+ end
57
+ end
58
+ if fields["required_ruby_version"]
59
+ fields["required_ruby_version"] = fields["required_ruby_version"].
60
+ to_s.split(",").map(&:strip)
49
61
  end
50
62
  fields
51
63
  end
@@ -58,22 +70,35 @@ module ReaperMan
58
70
  # @return [Array<String>] package paths within package list contents
59
71
  def inject_package(hash, info, package)
60
72
  package_path = File.join(
61
- 'rubygems', 'gems', "#{info['name']}-#{info['version']}.gem"
73
+ "rubygems", "gems", "#{info["name"]}-#{info["version"]}.gem"
62
74
  )
63
- classification = info['version'].prerelease? ? 'prerelease' : 'release'
64
- info['version'] = info['version'].version
75
+ classification = info["version"].prerelease? ? "prerelease" : "release"
76
+ info["version"] = info["version"].version
65
77
  hash.deep_merge!(
66
- 'rubygem' => {
78
+ "rubygem" => {
67
79
  classification => {
68
- info['name'] => {
69
- info['version'].to_s => info.merge('package_path' => package_path)
70
- }
71
- }
72
- }
80
+ info["name"] => {
81
+ info["version"].to_s => info.merge("package_path" => package_path),
82
+ },
83
+ },
84
+ },
73
85
  )
74
86
  package_path
75
87
  end
76
88
 
89
+ # Clean data hash of empty values
90
+ #
91
+ # @param hash [Hash] package list information
92
+ # @return [Smash]
93
+ def clean(hash)
94
+ Smash[
95
+ hash.map { |k, v|
96
+ v = clean(v) if v.is_a?(Hash)
97
+ next if v.nil? || (v.respond_to?(:empty?) && v.empty?)
98
+ [k, v]
99
+ }
100
+ ]
101
+ end
77
102
  end
78
103
  end
79
104
  end
@@ -1,4 +1,4 @@
1
- require 'reaper-man'
1
+ require "reaper-man"
2
2
 
3
3
  module ReaperMan
4
4
  class PackageList
@@ -20,11 +20,11 @@ module ReaperMan
20
20
  attr_reader :package_bucket
21
21
 
22
22
  # default package root prefix
23
- DEFAULT_ROOT = 'pool'
23
+ DEFAULT_ROOT = "pool"
24
24
  # default namespace for packages
25
- DEFAULT_BUCKET = 'public'
25
+ DEFAULT_BUCKET = "public"
26
26
  # default architectures to define
27
- DEFAULT_ALL_MAP = ['amd64', 'i386']
27
+ DEFAULT_ALL_MAP = ["amd64", "i386"]
28
28
 
29
29
  # Create new instance
30
30
  #
@@ -35,14 +35,14 @@ module ReaperMan
35
35
  # @option args [String] :package_root
36
36
  # @option args [String] :package_bucket
37
37
  # @option args [Array<String>] :all_map
38
- def initialize(args={})
38
+ def initialize(args = {})
39
39
  @origin = args[:origin].to_s
40
40
  @dist = args[:codename].to_s
41
41
  @component = args[:component].to_s
42
42
  @package_root = args.fetch(:package_root, DEFAULT_ROOT)
43
43
  @package_bucket = args.fetch(:package_bucket, DEFAULT_BUCKET)
44
- if(dist.empty? || component.empty?)
45
- raise 'Both `codename` and `component` must contain valid values'
44
+ if dist.empty? || component.empty?
45
+ raise "Both `codename` and `component` must contain valid values"
46
46
  end
47
47
  @all_map = args.fetch(:all_map, DEFAULT_ALL_MAP)
48
48
  end
@@ -63,14 +63,14 @@ module ReaperMan
63
63
  # @param conf [Hash] configuration hash
64
64
  # @param package_name [String] name
65
65
  # @param version [String]
66
- def remove(hash, package_name, version, args={})
66
+ def remove(hash, package_name, version, args = {})
67
67
  hash = hash.to_smash
68
68
  arch = [args.fetch(:arch, all_map)].flatten.compact
69
69
  deleted = false
70
70
  arch.each do |arch_name|
71
71
  arch_name = "binary-#{arch_name}"
72
- if(hash.get(:yum, origin, dist, :components, component, arch_name, package_name))
73
- if(version)
72
+ if hash.get(:yum, origin, dist, :components, component, arch_name, package_name)
73
+ if version
74
74
  deleted = hash[:yum][origin][dist][:components][component][arch_name][package_name].delete(version)
75
75
  else
76
76
  deleted = hash[:yum][origin][dist][:components][component][arch_name].delete(package_name)
@@ -85,9 +85,9 @@ module ReaperMan
85
85
  # @param package [String] path to package
86
86
  # @return [Hash]
87
87
  def extract_fields(package)
88
- fields = shellout('rpm --querytags').stdout.split("\n").map do |line|
88
+ fields = shellout("rpm --querytags").stdout.split("\n").map do |line|
89
89
  line.strip!
90
- unless(line.empty? || line.start_with?('HEADER'))
90
+ unless line.empty? || line.start_with?("HEADER")
91
91
  line
92
92
  end
93
93
  end.compact
@@ -97,18 +97,18 @@ module ReaperMan
97
97
  end.flatten.join("\n")
98
98
 
99
99
  cmd = "rpm -q -p #{package} --queryformat 'output:\n#{fmt}'"
100
- result = shellout(cmd).stdout.sub(/.*output:/, '')
100
+ result = shellout(cmd).stdout.sub(/.*output:/, "")
101
101
 
102
102
  data = Smash.new
103
103
  key = nil
104
104
  result.split("\n").each do |item|
105
105
  item.strip!
106
106
  next if item.empty?
107
- if(item.start_with?('[') && item.end_with?(']'))
108
- key = item.tr('[]', '')
107
+ if item.start_with?("[") && item.end_with?("]")
108
+ key = item.tr("[]", "")
109
109
  else
110
- if(data[key])
111
- if(!data[key].is_a?(Array))
110
+ if data[key]
111
+ if !data[key].is_a?(Array)
112
112
  data[key] = [data[key]]
113
113
  end
114
114
  data[key] << item
@@ -117,7 +117,7 @@ module ReaperMan
117
117
  end
118
118
  end
119
119
  end
120
- data[:generated_sha] = checksum(File.open(package, 'r'), :sha1)
120
+ data[:generated_sha] = checksum(File.open(package, "r"), :sha1)
121
121
  data[:generated_size] = File.size(package)
122
122
  data[:generated_header] = extract_header_information(package)
123
123
  data
@@ -130,31 +130,31 @@ module ReaperMan
130
130
  # @param package [String] path to package file
131
131
  # @return [Array<String>] package paths within package list contents
132
132
  def inject_package(hash, info, package)
133
- arch = info['ARCH']
134
- arch = arch == 'all' ? all_map : [arch]
133
+ arch = info["ARCH"]
134
+ arch = arch == "all" ? all_map : [arch]
135
135
  arch.map do |arch|
136
136
  package_file_name = File.join(
137
137
  package_root, package_bucket, origin,
138
138
  dist, component, File.basename(package)
139
139
  )
140
140
  hash.deep_merge!(
141
- 'yum' => {
141
+ "yum" => {
142
142
  origin => {
143
143
  dist => {
144
- 'components' => {
144
+ "components" => {
145
145
  component => {
146
146
  arch => {
147
- info['NAME'] => {
148
- info['NEVR'] => info.merge(:generated_path => package_file_name)
149
- }
150
- }
151
- }
152
- }
153
- }
154
- }
155
- }
147
+ info["NAME"] => {
148
+ info["NEVR"] => info.merge(:generated_path => package_file_name),
149
+ },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ },
155
+ },
156
156
  )
157
- File.join('yum', origin, package_file_name)
157
+ File.join("yum", origin, package_file_name)
158
158
  end
159
159
  end
160
160
 
@@ -163,11 +163,11 @@ module ReaperMan
163
163
  # @param package [String] path to package file
164
164
  # @return [Hash] checksums
165
165
  def generate_checksums(package)
166
- File.open(package, 'r') do |pkg|
166
+ File.open(package, "r") do |pkg|
167
167
  {
168
- 'MD5sum' => checksum(pkg.rewind && pkg, :md5),
169
- 'SHA1' => checksum(pkg.rewind && pkg, :sha1),
170
- 'SHA256' => checksum(pkg.rewind && pkg, :sha256)
168
+ "MD5sum" => checksum(pkg.rewind && pkg, :md5),
169
+ "SHA1" => checksum(pkg.rewind && pkg, :sha1),
170
+ "SHA256" => checksum(pkg.rewind && pkg, :sha256),
171
171
  }
172
172
  end
173
173
  end
@@ -179,15 +179,15 @@ module ReaperMan
179
179
  # @return [Smash<start,end>]
180
180
  # @note ported from: http://yum.baseurl.org/gitweb?p=yum.git;a=blob;f=yum/packages.py;h=eebeb9dfd264b887b054187276cea12ced3a0bc2;hb=HEAD#l2212
181
181
  def extract_header_information(package)
182
- io = File.open(package, 'rb')
182
+ io = File.open(package, "rb")
183
183
 
184
184
  # read past lead and 8 bytes of signature header
185
185
  io.seek(104)
186
186
  binindex = io.read(4)
187
- sigindex, _ = binindex.unpack('I>')
187
+ sigindex, _ = binindex.unpack("I>")
188
188
 
189
189
  bindata = io.read(4)
190
- sigdata, _ = bindata.unpack('I>')
190
+ sigdata, _ = bindata.unpack("I>")
191
191
 
192
192
  # seeked in to 112 bytes
193
193
 
@@ -199,7 +199,7 @@ module ReaperMan
199
199
  # Round to next 8 byte boundary
200
200
 
201
201
  disttoboundary = (sigsize % 8)
202
- unless(disttoboundary == 0)
202
+ unless disttoboundary == 0
203
203
  disttoboundary = 8 - disttoboundary
204
204
  end
205
205
 
@@ -216,9 +216,9 @@ module ReaperMan
216
216
 
217
217
  binindex = io.read(4)
218
218
 
219
- hdrindex, _ = binindex.unpack('I>')
219
+ hdrindex, _ = binindex.unpack("I>")
220
220
  bindata = io.read(4)
221
- hdrdata, _ = bindata.unpack('I>')
221
+ hdrdata, _ = bindata.unpack("I>")
222
222
 
223
223
  # each index is 4 32bit segments - so each is 16 bytes
224
224
 
@@ -235,10 +235,9 @@ module ReaperMan
235
235
 
236
236
  Smash.new(
237
237
  :start => hdrstart,
238
- :end => hdrend
238
+ :end => hdrend,
239
239
  )
240
240
  end
241
-
242
241
  end
243
242
  end
244
243
  end
@@ -1,12 +1,11 @@
1
- require 'reaper-man'
1
+ require "reaper-man"
2
2
 
3
3
  module ReaperMan
4
4
  # File signer
5
5
  class Signer
6
-
7
- autoload :Rpm, 'reaper-man/signer/rpm'
8
- autoload :Deb, 'reaper-man/signer/deb'
9
- autoload :Rubygems, 'reaper-man/signer/rubygems'
6
+ autoload :Rpm, "reaper-man/signer/rpm"
7
+ autoload :Deb, "reaper-man/signer/deb"
8
+ autoload :Rubygems, "reaper-man/signer/rubygems"
10
9
 
11
10
  include Utils::Process
12
11
 
@@ -19,7 +18,7 @@ module ReaperMan
19
18
  # command to use for file signing
20
19
  HELPER_COMMAND = File.join(
21
20
  File.expand_path(File.dirname(__FILE__)),
22
- 'util-scripts/auto-helper'
21
+ "util-scripts/auto-helper"
23
22
  )
24
23
 
25
24
  # Create new instance
@@ -30,12 +29,12 @@ module ReaperMan
30
29
  # @option args [String] :signing_type (defaults to 'origin')
31
30
  # @option args [String] :key_password (defaults to `ENV['REAPER_KEY_PASSWORD']`)
32
31
  # @option args [String] :package_system
33
- def initialize(args={})
32
+ def initialize(args = {})
34
33
  args = args.to_smash
35
34
  @key_id = args[:signing_key]
36
35
  @sign_chunk_size = args.fetch(:signing_chunk_size, 1)
37
- @sign_type = args.fetch(:signing_type, 'origin')
38
- @key_password = args.fetch(:key_password, ENV['REAPER_KEY_PASSWORD'])
36
+ @sign_type = args.fetch(:signing_type, "origin")
37
+ @key_password = args.fetch(:key_password, ENV["REAPER_KEY_PASSWORD"])
39
38
  @package_system = args[:package_system]
40
39
  case package_system.to_sym
41
40
  when :deb, :apt
@@ -54,24 +53,22 @@ module ReaperMan
54
53
  # @param src [String] path to source file
55
54
  # @param dst [String] path for destination file
56
55
  # @return [String] destination file path
57
- def file(src, dst=nil, sign_opts=nil)
58
- opts = sign_opts ? [sign_opts].flatten.compact : ['--detach-sign', '--armor']
59
- dst ||= src.sub(/#{Regexp.escape(File.extname(src))}$/, '.gpg')
56
+ def file(src, dst = nil, sign_opts = nil)
57
+ opts = sign_opts ? [sign_opts].flatten.compact : ["--detach-sign", "--armor"]
58
+ dst ||= src.sub(/#{Regexp.escape(File.extname(src))}$/, ".gpg")
60
59
  opts << "--output '#{dst}'"
61
- cmd = (["gpg --default-key #{key_id}"] + opts + [src]).join(' ')
62
- if(key_password)
60
+ cmd = (["gpg --default-key #{key_id}"] + opts + [src]).join(" ")
61
+ if key_password
63
62
  shellout(
64
63
  "#{HELPER_COMMAND} #{cmd}",
65
64
  :environment => {
66
- 'REAPER_KEY_PASSWORD' => key_password
67
- }
65
+ "REAPER_KEY_PASSWORD" => key_password,
66
+ },
68
67
  )
69
68
  else
70
69
  shellout(cmd)
71
70
  end
72
71
  dst
73
72
  end
74
-
75
73
  end
76
-
77
74
  end
@@ -1,4 +1,4 @@
1
- require 'reaper-man'
1
+ require "reaper-man"
2
2
 
3
3
  module ReaperMan
4
4
  class Signer
@@ -12,13 +12,13 @@ module ReaperMan
12
12
  def package(*pkgs)
13
13
  pkgs = valid_packages(*pkgs)
14
14
  pkgs.each_slice(sign_chunk_size) do |pkgs|
15
- cmd = %(debsigs --sign="#{sign_type}" --default-key="#{key_id}" #{pkgs.join(' ')})
16
- if(key_password)
15
+ cmd = %(debsigs --sign="#{sign_type}" --default-key="#{key_id}" #{pkgs.join(" ")})
16
+ if key_password
17
17
  shellout(
18
18
  "#{Signer::HELPER_COMMAND} #{cmd}",
19
19
  :environment => {
20
- 'REAPER_KEY_PASSWORD' => key_password
21
- }
20
+ "REAPER_KEY_PASSWORD" => key_password,
21
+ },
22
22
  )
23
23
  else
24
24
  shellout(cmd)
@@ -33,10 +33,9 @@ module ReaperMan
33
33
  # @return [Array<String>]
34
34
  def valid_packages(*pkgs)
35
35
  pkgs.find_all do |pkg|
36
- File.extname(pkg) == '.deb'
36
+ File.extname(pkg) == ".deb"
37
37
  end
38
38
  end
39
-
40
39
  end
41
40
  end
42
41
  end
@@ -1,4 +1,4 @@
1
- require 'reaper-man'
1
+ require "reaper-man"
2
2
 
3
3
  module ReaperMan
4
4
  class Signer
@@ -12,13 +12,13 @@ module ReaperMan
12
12
  def package(*pkgs)
13
13
  pkgs = valid_packages(*pkgs)
14
14
  pkgs.each_slice(sign_chunk_size) do |pkgs|
15
- cmd = %(rpmsign --resign --key-id="#{key_id}" #{pkgs.join(' ')})
16
- if(key_password)
15
+ cmd = %(rpmsign --resign --key-id="#{key_id}" #{pkgs.join(" ")})
16
+ if key_password
17
17
  shellout(
18
18
  "#{Signer::HELPER_COMMAND} #{cmd}",
19
19
  :environment => {
20
- 'REAPER_KEY_PASSWORD' => key_password
21
- }
20
+ "REAPER_KEY_PASSWORD" => key_password,
21
+ },
22
22
  )
23
23
  else
24
24
  shellout(cmd)
@@ -33,10 +33,9 @@ module ReaperMan
33
33
  # @return [Array<String>]
34
34
  def valid_packages(*pkgs)
35
35
  pkgs.find_all do |pkg|
36
- File.extname(pkg) == '.rpm'
36
+ File.extname(pkg) == ".rpm"
37
37
  end
38
38
  end
39
-
40
39
  end
41
40
  end
42
41
  end