Module: Dgh

Extended by:
Dgh
Included in:
Dgh
Defined in:
lib/dgh.rb,
lib/dgh/version.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

VERSION =
[Version::MAJOR, Version::MINOR, Version::PATCH, Version::BUILD].compact.join('.')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dgh.rb', line 31

def run
  optspec = <<-SPEC
Usage: dgh [options] inputfile(s)
---
d,debug Output debug messages
h,help  Output help message
  SPEC
  opts = Slop.optspec(optspec)
  opts.parse!

  if opts.help?
    puts opts
    exit
  end

  log = Logger.new(STDOUT)
  log.level = Logger::DEBUG
  LogBuddy.init :default_loggger => log, :disabled => !opts.debug?

  if ARGV.empty? || ARGV.any? {|a| !File.exist? a}
    puts opts
    puts "You can generate a policy listing by running e.g."
    puts "`dpkg --get-selections|egrep '\\binstall'|awk '{print $1}'|\\"
    puts "  xargs env LANG=C apt-cache policy`"
  else
    ARGV.each do |f|
      d "Parsing #{f}"
      find_downgradable(parse(File.open(f).read).content).each do |pkg|
        puts pkg[:name]
      end
    end
  end
end

Instance Method Details

#find_downgradable(packages) ⇒ Object

Find downgradable packages

Parameters:

  • paca


22
23
24
25
26
27
28
# File 'lib/dgh.rb', line 22

def find_downgradable(packages)
  packages.select do |pkg|
    pkg[:versions].any? do |ver|
      ver[:current] && ver[:sources].length == 1 && ver[:sources][0][:source] == '/var/lib/dpkg/status'
    end
  end
end

#parse(input) ⇒ Object

Parse input with the policy grammar

Parameters:

  • input (String)

    apt-cache policy input

Returns:

  • a list of hashes with info on packages



14
15
16
17
# File 'lib/dgh.rb', line 14

def parse(input)
  @parser ||= PolicyParser.new
  @parser.parse input
end