Class: Dobby::PackageSource::DpkgStatusFile

Inherits:
AbstractPackageSource show all
Defined in:
lib/dobby/package_source/dpkg_status_file.rb

Overview

Defines a strategy for creating a Dobby::Package array from /var/lib/dpkg/status or a similarly formatted file.

Defined Under Namespace

Classes: DpkgFormatError

Instance Attribute Summary

Attributes included from Strategy

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Strategy

included, #initialize, #inspect, #log, #setup

Class Method Details

.cli_optionsObject

rubocop:disable Layout/AlignArray



18
19
20
21
22
23
24
25
# File 'lib/dobby/package_source/dpkg_status_file.rb', line 18

def self.cli_options
  [
    ['--release NAME', 'Release code name for package definitions.',
                       'Defaults to the code name of the current system.'],
    ['--dist DIST', 'The full name of the distribution for package definitions.',
                    'Defaults to "Debian".']
  ]
end

Instance Method Details

#parseArray<Package>

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dobby/package_source/dpkg_status_file.rb', line 29

def parse
  packages = []
  File.read(options.file_path).split("\n\n").each do |section|
    begin
      packages << package_from_section(section)
    rescue Package::FieldRequiredError => e
      # If the Version field is missing, this is probably a virtual
      # or meta-package (e.g. little-table-dev) - Skip it. Name and
      # release should never be missing, so reraise the error in those
      # cases.
      next if e.field == 'version'

      raise
    end
  end
  packages
end