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,6 +1,6 @@
1
- require 'reaper-man'
2
- require 'xmlsimple'
3
- require 'time'
1
+ require "reaper-man"
2
+ require "xmlsimple"
3
+ require "time"
4
4
 
5
5
  module ReaperMan
6
6
  class Generator
@@ -9,20 +9,20 @@ module ReaperMan
9
9
 
10
10
  # Version flag mappings
11
11
  VERSION_FLAGS = {
12
- '2' => 'LT',
13
- '4' => 'GT',
14
- '8' => 'EQ',
15
- '10' => 'LE',
16
- '12' => 'GE'
12
+ "2" => "LT",
13
+ "4" => "GT",
14
+ "8" => "EQ",
15
+ "10" => "LE",
16
+ "12" => "GE",
17
17
  }
18
18
 
19
19
  # Location of xmlns (though all are now defunct)
20
20
  XMLNS_MAP = {
21
- :repo => 'http://linux.duke.edu/metadata/repo',
22
- :common => 'http://linux.duke.edu/metadata/common',
23
- :rpm => 'http://linux.duke.edu/metadata/rpm',
24
- :filelists => 'http://linux.duke.edu/metadata/filelists',
25
- :other => 'http://linux.duke.edu/metadata/other'
21
+ :repo => "http://linux.duke.edu/metadata/repo",
22
+ :common => "http://linux.duke.edu/metadata/common",
23
+ :rpm => "http://linux.duke.edu/metadata/rpm",
24
+ :filelists => "http://linux.duke.edu/metadata/filelists",
25
+ :other => "http://linux.duke.edu/metadata/other",
26
26
  }
27
27
 
28
28
  # Generate the repository
@@ -43,9 +43,8 @@ module ReaperMan
43
43
  f_file = filelist_file(origin_name, dist_name, component_name, packages)
44
44
  sign_file_if_setup do
45
45
  repomd_file(origin_name, dist_name, component_name,
46
- :primary => p_file,
47
- :filelists => f_file
48
- )
46
+ :primary => p_file,
47
+ :filelists => f_file)
49
48
  end
50
49
  end
51
50
  end
@@ -57,9 +56,9 @@ module ReaperMan
57
56
  #
58
57
  # @yield block returning file path
59
58
  # @return [String] file path
60
- def sign_file_if_setup(opts=nil)
59
+ def sign_file_if_setup(opts = nil)
61
60
  path = yield
62
- if(signer && options[:sign])
61
+ if signer && options[:sign]
63
62
  signer.file(path, nil, opts)
64
63
  end
65
64
  path
@@ -76,85 +75,85 @@ module ReaperMan
76
75
  content = {
77
76
  :metadata => {
78
77
  :@xmlns => XMLNS_MAP[:common],
79
- '@xmlns:rpm' => XMLNS_MAP[:rpm],
78
+ "@xmlns:rpm" => XMLNS_MAP[:rpm],
80
79
  :@packages => packages.size,
81
- :package => packages.map{ |package|
80
+ :package => packages.map { |package|
82
81
  {
83
- :@type => 'rpm',
84
- :name => package['NAME'],
85
- :arch => package['ARCH'],
82
+ :@type => "rpm",
83
+ :name => package["NAME"],
84
+ :arch => package["ARCH"],
86
85
  :version => {
87
- :@epoch => package['EPOCHNUM'],
88
- :@ver => package['VERSION'],
89
- :@rel => package['RELEASE'].split('.').first
86
+ :@epoch => package["EPOCHNUM"],
87
+ :@ver => package["VERSION"],
88
+ :@rel => package["RELEASE"].split(".").first,
90
89
  },
91
90
  :checksum => [
92
91
  {
93
- :@type => 'sha',
94
- :@pkgid => 'YES'
92
+ :@type => "sha",
93
+ :@pkgid => "YES",
95
94
  },
96
- package[:generated_sha]
95
+ package[:generated_sha],
97
96
  ],
98
- :summary => package['SUMMARY'],
99
- :description => [package['DESCRIPTION']].flatten.compact.join(' '),
100
- :packager => package['PACKAGER'],
101
- :url => package['URL'],
97
+ :summary => package["SUMMARY"],
98
+ :description => [package["DESCRIPTION"]].flatten.compact.join(" "),
99
+ :packager => package["PACKAGER"],
100
+ :url => package["URL"],
102
101
  :time => {
103
102
  :@file => Time.now.to_i,
104
- :@build => package['BUILDTIME']
103
+ :@build => package["BUILDTIME"],
105
104
  },
106
105
  :size => {
107
- :@archive => package['ARCHIVESIZE'],
106
+ :@archive => package["ARCHIVESIZE"],
108
107
  :@package => package[:generated_size],
109
- :@installed => package['LONGSIZE']
108
+ :@installed => package["LONGSIZE"],
110
109
  },
111
110
  :location => package[:generated_path],
112
111
  :format => {
113
- 'rpm:license' => package['LICENSE'],
114
- 'rpm:vendor' => package['VENDOR'],
115
- 'rpm:group' => package['GROUP'],
116
- 'rpm:buildhost' => package['BUILDHOST'],
117
- 'rpm:header-range' => {
112
+ "rpm:license" => package["LICENSE"],
113
+ "rpm:vendor" => package["VENDOR"],
114
+ "rpm:group" => package["GROUP"],
115
+ "rpm:buildhost" => package["BUILDHOST"],
116
+ "rpm:header-range" => {
118
117
  :@start => package[:generated_header][:start],
119
- :@end => package[:generated_header][:end]
118
+ :@end => package[:generated_header][:end],
120
119
  },
121
- 'rpm:provides' => {
122
- 'rpm:entry' => Array.new.tap{ |entries|
123
- pro_ver = package['PROVIDEVERSION'].dup
124
- package['PROVIDENAME'].each_with_index do |p_name, p_idx|
120
+ "rpm:provides" => {
121
+ "rpm:entry" => Array.new.tap { |entries|
122
+ pro_ver = package["PROVIDEVERSION"].dup
123
+ package["PROVIDENAME"].each_with_index do |p_name, p_idx|
125
124
  item = {:@name => p_name}
126
- if(p_flag = VERSION_FLAGS[package['PROVIDEFLAGS'][p_idx]])
127
- p_ver, p_rel = pro_ver.shift.split('-', 2)
128
- item.merge!(:@flags => p_flag, :@ver => p_ver, :@rel => p_rel, :@epoch => package['EPOCHNUM'])
125
+ if p_flag = VERSION_FLAGS[package["PROVIDEFLAGS"][p_idx]]
126
+ p_ver, p_rel = pro_ver.shift.split("-", 2)
127
+ item.merge!(:@flags => p_flag, :@ver => p_ver, :@rel => p_rel, :@epoch => package["EPOCHNUM"])
129
128
  end
130
129
  entries.push(item)
131
130
  end
132
- }
131
+ },
133
132
  },
134
- 'rpm:requires' => {
135
- 'rpm:entry' => Array.new.tap{ |entries|
136
- req_ver = package['REQUIREVERSION'].dup
137
- package['REQUIRENAME'].each_with_index do |r_name, r_idx|
133
+ "rpm:requires" => {
134
+ "rpm:entry" => Array.new.tap { |entries|
135
+ req_ver = package["REQUIREVERSION"].dup
136
+ package["REQUIRENAME"].each_with_index do |r_name, r_idx|
138
137
  item = {:@name => r_name}
139
- if(r_flag = VERSION_FLAGS[package['REQUIREFLAGS'][r_idx]])
140
- r_ver, r_rel = req_ver.shift.split('-', 2)
141
- item.merge!(:@flags => r_flag, :@ver => r_ver, :@rel => r_rel, :@epoch => package['EPOCHNUM'])
138
+ if r_flag = VERSION_FLAGS[package["REQUIREFLAGS"][r_idx]]
139
+ r_ver, r_rel = req_ver.shift.split("-", 2)
140
+ item.merge!(:@flags => r_flag, :@ver => r_ver, :@rel => r_rel, :@epoch => package["EPOCHNUM"])
142
141
  end
143
142
  entries.push(item)
144
143
  end
145
- }
146
- }
147
- }
144
+ },
145
+ },
146
+ },
148
147
  }
149
- }
150
- }
148
+ },
149
+ },
151
150
  }
152
- args = [origin_name, dist_name, component_name, 'repodata', 'primary.xml']
151
+ args = [origin_name, dist_name, component_name, "repodata", "primary.xml"]
153
152
  [
154
153
  create_file(*args) do |file|
155
154
  file.puts generate_xml(content)
156
155
  end,
157
- compress_file(*args)
156
+ compress_file(*args),
158
157
  ]
159
158
  end
160
159
 
@@ -167,32 +166,32 @@ module ReaperMan
167
166
  # @return [Array<String>] path to file, path to compressed file
168
167
  def filelist_file(origin_name, dist_name, component_name, packages)
169
168
  content = {
170
- 'filelists' => {
169
+ "filelists" => {
171
170
  :@xmlns => XMLNS_MAP[:filelists],
172
171
  :@packages => packages.size,
173
- :package => packages.map{ |package|
172
+ :package => packages.map { |package|
174
173
  {
175
174
  :@pkgid => package[:generated_sha],
176
- :@name => package['NAME'],
177
- :@arch => package['ARCH'],
175
+ :@name => package["NAME"],
176
+ :@arch => package["ARCH"],
178
177
  :version => {
179
- :@epoch => package['EPOCHNUM'],
180
- :@ver => package['VERSION'],
181
- :@rel => package['RELEASE'].split('.').first
178
+ :@epoch => package["EPOCHNUM"],
179
+ :@ver => package["VERSION"],
180
+ :@rel => package["RELEASE"].split(".").first,
181
+ },
182
+ :file => (package["FILENAMES"] + package["DIRNAMES"]).map { |dir|
183
+ {:@type => "dir", :_content_ => dir}
182
184
  },
183
- :file => (package['FILENAMES'] + package['DIRNAMES']).map{ |dir|
184
- {:@type => 'dir', :_content_ => dir}
185
- }
186
185
  }
187
- }
188
- }
186
+ },
187
+ },
189
188
  }
190
- args = [origin_name, dist_name, component_name, 'repodata', 'filelists.xml']
189
+ args = [origin_name, dist_name, component_name, "repodata", "filelists.xml"]
191
190
  [
192
191
  create_file(*args) do |file|
193
192
  file.puts generate_xml(content)
194
193
  end,
195
- compress_file(*args)
194
+ compress_file(*args),
196
195
  ]
197
196
  end
198
197
 
@@ -207,25 +206,25 @@ module ReaperMan
207
206
  content = {
208
207
  :repomd => {
209
208
  :@xmlns => XMLNS_MAP[:repo],
210
- :data => Hash.new.tap{ |data|
209
+ :data => Hash.new.tap { |data|
211
210
  files.each do |f_name, f_paths|
212
211
  data[f_name] = {
213
- :location => File.join('repodata', File.basename(f_paths.first)),
214
- 'open-checksum' => {
215
- :@type => 'sha',
216
- :_content_ => checksum(File.open(f_paths.first), :sha1)
212
+ :location => File.join("repodata", File.basename(f_paths.first)),
213
+ "open-checksum" => {
214
+ :@type => "sha",
215
+ :_content_ => checksum(File.open(f_paths.first), :sha1),
217
216
  },
218
217
  :checksum => {
219
- :@type => 'sha',
220
- :_content_ => checksum(File.open(f_paths.last), :sha1)
218
+ :@type => "sha",
219
+ :_content_ => checksum(File.open(f_paths.last), :sha1),
221
220
  },
222
- :timestamp => File.mtime(f_paths.first).to_i
221
+ :timestamp => File.mtime(f_paths.first).to_i,
223
222
  }
224
223
  end
225
- }
226
- }
224
+ },
225
+ },
227
226
  }
228
- args = [origin_name, dist_name, component_name, 'repodata', 'repomd.xml']
227
+ args = [origin_name, dist_name, component_name, "repodata", "repomd.xml"]
229
228
  create_file(*args) do |file|
230
229
  file.puts generate_xml(content)
231
230
  end
@@ -237,13 +236,11 @@ module ReaperMan
237
236
  # @return [String]
238
237
  def generate_xml(hash)
239
238
  XmlSimple.xml_out(hash,
240
- 'AttrPrefix' => true,
241
- 'KeepRoot' => true,
242
- 'ContentKey' => :_content_,
243
- 'XmlDeclaration' => '<?xml version="1.0" encoding="UTF-8" ?>'
244
- )
239
+ "AttrPrefix" => true,
240
+ "KeepRoot" => true,
241
+ "ContentKey" => :_content_,
242
+ "XmlDeclaration" => '<?xml version="1.0" encoding="UTF-8" ?>')
245
243
  end
246
-
247
244
  end
248
245
  end
249
246
  end
@@ -1,19 +1,19 @@
1
- require 'multi_json'
2
- require 'reaper-man'
1
+ require "multi_json"
2
+ require "reaper-man"
3
3
 
4
4
  module ReaperMan
5
5
  # Package list for repository
6
6
  class PackageList
7
7
  # Package list modification processor
8
8
  class Processor
9
- autoload :Rpm, 'reaper-man/package_list/rpm'
10
- autoload :Deb, 'reaper-man/package_list/deb'
11
- autoload :Gem, 'reaper-man/package_list/gem'
9
+ autoload :Rpm, "reaper-man/package_list/rpm"
10
+ autoload :Deb, "reaper-man/package_list/deb"
11
+ autoload :Gem, "reaper-man/package_list/gem"
12
12
 
13
13
  include Utils::Process
14
14
  include Utils::Checksum
15
15
 
16
- def initialize(_={})
16
+ def initialize(_ = {})
17
17
  end
18
18
 
19
19
  # Add a package to the list
@@ -21,7 +21,7 @@ module ReaperMan
21
21
  # @param conf [Hash]
22
22
  # @param package [String] path to package
23
23
  def add(conf, package)
24
- raise NoMethodError.new 'Not implemented'
24
+ raise NoMethodError.new "Not implemented"
25
25
  end
26
26
 
27
27
  # Remove package from the list
@@ -29,8 +29,8 @@ module ReaperMan
29
29
  # @param conf [Hash] configuration hash
30
30
  # @param package_name [String] name
31
31
  # @param version [String]
32
- def remove(conf, package_name, version=nil)
33
- raise NoMethodError.new 'Not implemented'
32
+ def remove(conf, package_name, version = nil)
33
+ raise NoMethodError.new "Not implemented"
34
34
  end
35
35
  end
36
36
 
@@ -47,7 +47,7 @@ module ReaperMan
47
47
  #
48
48
  # @param path [String] path to package list
49
49
  # @param args [Hash] configuration
50
- def initialize(path, args={})
50
+ def initialize(path, args = {})
51
51
  @path = path
52
52
  @options = args.dup
53
53
  @content = Smash.new
@@ -58,16 +58,16 @@ module ReaperMan
58
58
  #
59
59
  # @param package [Array<String>] path to package file
60
60
  def add_package(package)
61
- [package_handler(File.extname(package).tr('.', '')).add(content, package)].flatten.compact
61
+ [package_handler(File.extname(package).tr(".", "")).add(content, package)].flatten.compact
62
62
  end
63
63
 
64
64
  # Remove package from the package list file
65
65
  #
66
66
  # @param package [String] name of package
67
67
  # @param version [String] version of file
68
- def remove_package(package, version=nil)
69
- ext = File.extname(package).tr('.', '')
70
- if(ext.empty?)
68
+ def remove_package(package, version = nil)
69
+ ext = File.extname(package).tr(".", "")
70
+ if ext.empty?
71
71
  ext = %w(deb) # rpm)
72
72
  else
73
73
  ext = [ext]
@@ -87,9 +87,9 @@ module ReaperMan
87
87
  # @return [Integer] number of bytes written
88
88
  def write!
89
89
  new_file = !File.exists?(path)
90
- File.open(path, File::CREAT|File::RDWR) do |file|
90
+ File.open(path, File::CREAT | File::RDWR) do |file|
91
91
  file.flock(File::LOCK_EX)
92
- if(!new_file && init_mtime != file.mtime)
92
+ if !new_file && init_mtime != file.mtime
93
93
  file.rewind
94
94
  content.deep_merge!(
95
95
  MultiJson.load(
@@ -118,13 +118,12 @@ module ReaperMan
118
118
  @init_mtime = File.mtime(path)
119
119
  content.deep_merge!(
120
120
  MultiJson.load(
121
- File.open(path, 'r') do |file|
121
+ File.open(path, "r") do |file|
122
122
  file.flock(File::LOCK_SH)
123
123
  file.read
124
124
  end
125
125
  )
126
126
  )
127
127
  end
128
-
129
128
  end
130
129
  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(:apt, origin, dist, :components, component, arch_name, package_name))
73
- if(version)
72
+ if hash.get(:apt, origin, dist, :components, component, arch_name, package_name)
73
+ if version
74
74
  deleted = hash[:apt][origin][dist][:components][component][arch_name][package_name].delete(version)
75
75
  else
76
76
  deleted = hash[:apt][origin][dist][:components][component][arch_name].delete(package_name)
@@ -86,7 +86,7 @@ module ReaperMan
86
86
  # @return [Hash]
87
87
  def extract_fields(package)
88
88
  content = shellout("dpkg-deb -f '#{package}'")
89
- Smash[content.stdout.scan(/([^\s][^:]+):\s+(([^\n]|\n\s)+)/).map{|a| a.slice(0,2)}]
89
+ Smash[content.stdout.scan(/([^\s][^:]+):\s+(([^\n]|\n\s)+)/).map { |a| a.slice(0, 2) }]
90
90
  end
91
91
 
92
92
  # Insert package information into package list
@@ -96,8 +96,8 @@ module ReaperMan
96
96
  # @param package [String] path to package file
97
97
  # @return [Array<String>] package paths within package list contents
98
98
  def inject_package(hash, info, package)
99
- arch = info['Architecture']
100
- arch = arch == 'all' ? all_map : [arch]
99
+ arch = info["Architecture"]
100
+ arch = arch == "all" ? all_map : [arch]
101
101
  arch.map do |arch|
102
102
  package_file_name = File.join(
103
103
  package_root, package_bucket, origin,
@@ -105,28 +105,27 @@ module ReaperMan
105
105
  File.basename(package)
106
106
  )
107
107
  hash.deep_merge!(
108
- 'apt' => {
108
+ "apt" => {
109
109
  origin => {
110
110
  dist => {
111
- 'components' => {
111
+ "components" => {
112
112
  component => {
113
113
  "binary-#{arch}" => {
114
- info['Package'] => {
115
- info['Version'] => info.merge!(
116
- 'Filename' => package_file_name,
117
- 'Size' => File.size(package)
118
- )
119
- }
114
+ info["Package"] => {
115
+ info["Version"] => info.merge!(
116
+ "Filename" => package_file_name,
117
+ "Size" => File.size(package),
118
+ ),
119
+ },
120
120
  },
121
- "binary-i386" => {
122
- }
123
- }
124
- }
125
- }
126
- }
127
- }
121
+ "binary-i386" => {},
122
+ },
123
+ },
124
+ },
125
+ },
126
+ },
128
127
  )
129
- File.join('apt', origin, package_file_name)
128
+ File.join("apt", origin, package_file_name)
130
129
  end
131
130
  end
132
131
 
@@ -135,15 +134,14 @@ module ReaperMan
135
134
  # @param package [String] path to package file
136
135
  # @return [Hash] checksums
137
136
  def generate_checksums(package)
138
- File.open(package, 'r') do |pkg|
137
+ File.open(package, "r") do |pkg|
139
138
  {
140
- 'MD5sum' => checksum(pkg.rewind && pkg, :md5),
141
- 'SHA1' => checksum(pkg.rewind && pkg, :sha1),
142
- 'SHA256' => checksum(pkg.rewind && pkg, :sha256)
139
+ "MD5sum" => checksum(pkg.rewind && pkg, :md5),
140
+ "SHA1" => checksum(pkg.rewind && pkg, :sha1),
141
+ "SHA256" => checksum(pkg.rewind && pkg, :sha256),
143
142
  }
144
143
  end
145
144
  end
146
-
147
145
  end
148
146
  end
149
147
  end