Class: ReaperMan::PackageList::Processor::Deb

Inherits:
ReaperMan::PackageList::Processor show all
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

Instance Method Summary collapse

Methods included from Utils::Checksum

#checksum

Methods included from Utils::Process

#child_process_command, #mixlib_shellout_command, #shellout

Constructor Details

#initialize(args = {}) ⇒ Deb

Create new instance

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :origin (String)
  • :codename (String)
  • :component (String)
  • :package_root (String)
  • :package_bucket (String)
  • :all_map (Array<String>)


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_mapArray<String> (readonly)

Returns architectures.

Returns:

  • (Array<String>)

    architectures



16
17
18
# File 'lib/reaper-man/package_list/deb.rb', line 16

def all_map
  @all_map
end

#componentString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/reaper-man/package_list/deb.rb', line 14

def component
  @component
end

#distString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/reaper-man/package_list/deb.rb', line 12

def dist
  @dist
end

#originString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/reaper-man/package_list/deb.rb', line 10

def origin
  @origin
end

#package_bucketString (readonly)

Returns namespace for packages.

Returns:

  • (String)

    namespace for packages



20
21
22
# File 'lib/reaper-man/package_list/deb.rb', line 20

def package_bucket
  @package_bucket
end

#package_rootString (readonly)

Returns prefix for package file location.

Returns:

  • (String)

    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

Parameters:

  • conf (Hash)
  • package (String)

    path to package



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

Parameters:

  • package (String)

    path to package

Returns:

  • (Hash)


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

Parameters:

  • package (String)

    path to package file

Returns:

  • (Hash)

    checksums



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

Parameters:

  • hash (Hash)

    package list contents

  • info (Hash)

    package information

  • package (String)

    path to package file

Returns:

  • (Array<String>)

    package paths within package list contents



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

Parameters:

  • conf (Hash)

    configuration hash

  • package_name (String)

    name

  • version (String)


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