Class: ReaperMan::PackageList::Processor::Deb
- Inherits:
-
ReaperMan::PackageList::Processor
- Object
- ReaperMan::PackageList::Processor
- ReaperMan::PackageList::Processor::Deb
- Defined in:
- lib/reaper-man/package_list/deb.rb
Overview
Package list process for debian packages
Constant Summary collapse
- DEFAULT_ROOT =
default package root prefix
"pool"
- DEFAULT_BUCKET =
default namespace for packages
"public"
- DEFAULT_ALL_MAP =
default architectures to define
["amd64", "i386"]
Instance Attribute Summary collapse
-
#all_map ⇒ Array<String>
readonly
Architectures.
- #component ⇒ String readonly
- #dist ⇒ String readonly
- #origin ⇒ String readonly
-
#package_bucket ⇒ String
readonly
Namespace for packages.
-
#package_root ⇒ String
readonly
Prefix for package file location.
Instance Method Summary collapse
-
#add(hash, package) ⇒ Object
Add a package to the list.
-
#extract_fields(package) ⇒ Hash
Extract package metadata.
-
#generate_checksums(package) ⇒ Hash
Generate required checksums for given package.
-
#initialize(args = {}) ⇒ Deb
constructor
Create new instance.
-
#inject_package(hash, info, package) ⇒ Array<String>
Insert package information into package list.
-
#remove(hash, package_name, version, args = {}) ⇒ Object
Remove package from the list.
Methods included from Utils::Checksum
Methods included from Utils::Process
#child_process_command, #mixlib_shellout_command, #shellout
Constructor Details
#initialize(args = {}) ⇒ Deb
Create new instance
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reaper-man/package_list/deb.rb', line 38 def initialize(args = {}) @origin = args[:origin].to_s @dist = args[:codename].to_s @component = args[:component].to_s @package_root = args.fetch(:package_root, DEFAULT_ROOT) @package_bucket = args.fetch(:package_bucket, DEFAULT_BUCKET) if dist.empty? || component.empty? raise "Both `codename` and `component` must contain valid values" end @all_map = args.fetch(:all_map, DEFAULT_ALL_MAP) end |
Instance Attribute Details
#all_map ⇒ Array<String> (readonly)
Returns architectures.
16 17 18 |
# File 'lib/reaper-man/package_list/deb.rb', line 16 def all_map @all_map end |
#component ⇒ String (readonly)
14 15 16 |
# File 'lib/reaper-man/package_list/deb.rb', line 14 def component @component end |
#dist ⇒ String (readonly)
12 13 14 |
# File 'lib/reaper-man/package_list/deb.rb', line 12 def dist @dist end |
#origin ⇒ String (readonly)
10 11 12 |
# File 'lib/reaper-man/package_list/deb.rb', line 10 def origin @origin end |
#package_bucket ⇒ String (readonly)
Returns namespace for packages.
20 21 22 |
# File 'lib/reaper-man/package_list/deb.rb', line 20 def package_bucket @package_bucket end |
#package_root ⇒ String (readonly)
Returns prefix for package file location.
18 19 20 |
# File 'lib/reaper-man/package_list/deb.rb', line 18 def package_root @package_root end |
Instance Method Details
#add(hash, package) ⇒ Object
Add a package to the list
54 55 56 57 58 59 |
# File 'lib/reaper-man/package_list/deb.rb', line 54 def add(hash, package) info = extract_fields(package) info.merge!(generate_checksums(package)) filenames = inject_package(hash, info, package) filenames end |
#extract_fields(package) ⇒ Hash
Extract package metadata
87 88 89 90 |
# File 'lib/reaper-man/package_list/deb.rb', line 87 def extract_fields(package) content = shellout("dpkg-deb -f '#{package}'") Smash[content.stdout.scan(/([^\s][^:]+):\s+(([^\n]|\n\s)+)/).map { |a| a.slice(0, 2) }] end |
#generate_checksums(package) ⇒ Hash
Generate required checksums for given package
136 137 138 139 140 141 142 143 144 |
# File 'lib/reaper-man/package_list/deb.rb', line 136 def generate_checksums(package) File.open(package, "r") do |pkg| { "MD5sum" => checksum(pkg.rewind && pkg, :md5), "SHA1" => checksum(pkg.rewind && pkg, :sha1), "SHA256" => checksum(pkg.rewind && pkg, :sha256), } end end |
#inject_package(hash, info, package) ⇒ Array<String>
Insert package information into package list
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/reaper-man/package_list/deb.rb', line 98 def inject_package(hash, info, package) arch = info["Architecture"] arch = arch == "all" ? all_map : [arch] arch.map do |arch| package_file_name = File.join( package_root, package_bucket, origin, dist, component, "binary-#{arch}", File.basename(package) ) hash.deep_merge!( "apt" => { origin => { dist => { "components" => { component => { "binary-#{arch}" => { info["Package"] => { info["Version"] => info.merge!( "Filename" => package_file_name, "Size" => File.size(package), ), }, }, "binary-i386" => {}, }, }, }, }, }, ) File.join("apt", origin, package_file_name) end end |
#remove(hash, package_name, version, args = {}) ⇒ Object
Remove package from the list
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/reaper-man/package_list/deb.rb', line 66 def remove(hash, package_name, version, args = {}) hash = hash.to_smash arch = [args.fetch(:arch, all_map)].flatten.compact deleted = false arch.each do |arch_name| arch_name = "binary-#{arch_name}" if hash.get(:apt, origin, dist, :components, component, arch_name, package_name) if version deleted = hash[:apt][origin][dist][:components][component][arch_name][package_name].delete(version) else deleted = hash[:apt][origin][dist][:components][component][arch_name].delete(package_name) end end end !!deleted end |