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 = "Usage: dgh [options] inputfile(s)\n---\nd,debug Output debug messages\nh,help  Output help message\n  SPEC\n  opts = Slop.optspec(optspec)\n  opts.parse!\n\n  if opts.help?\n    puts opts\n    exit\n  end\n\n  log = Logger.new(STDOUT)\n  log.level = Logger::DEBUG\n  LogBuddy.init :default_loggger => log, :disabled => !opts.debug?\n\n  if ARGV.empty? || ARGV.any? {|a| !File.exist? a}\n    puts opts\n    puts \"You can generate a policy listing by running e.g.\"\n    puts \"`dpkg --get-selections|egrep '\\\\binstall'|awk '{print $1}'|\\\\\"\n    puts \"  xargs env LANG=C apt-cache policy`\"\n  else\n    ARGV.each do |f|\n      d \"Parsing \#{f}\"\n      find_downgradable(parse(File.open(f).read).content).each do |pkg|\n        puts pkg[:name]\n      end\n    end\n  end\nend\n"

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