Class: Xezat::Command::Doctor

Inherits:
Object
  • Object
show all
Defined in:
lib/xezat/command/doctor.rb

Overview

package tree が健全であるかどうかを診断する

Instance Method Summary collapse

Constructor Details

#initialize(program) ⇒ Doctor

Returns a new instance of Doctor.



8
9
10
11
12
13
14
15
16
# File 'lib/xezat/command/doctor.rb', line 8

def initialize(program)
  program.command(:doctor) do |c|
    c.syntax 'doctor'
    c.description 'diagnose installed packages'
    c.action do |args, options|
      execute(c, args, options)
    end
  end
end

Instance Method Details

#execute(c, args, options) ⇒ Object



20
21
22
23
24
# File 'lib/xezat/command/doctor.rb', line 20

def execute(c, args, options)
  get_contents_uniqueness.each do |path, pkg|
    c.logger.warn "#{path} is in multiple packages: #{pkg}" if pkg.length > 1
  end
end

#get_contents_uniqueness(path = '/etc/setup') ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xezat/command/doctor.rb', line 26

def get_contents_uniqueness(path = '/etc/setup')
  content2pkg = {}
  Dir.glob(File.join(path, '*.lst.gz')) do |lst|
    pkg = File.basename(lst, '.lst.gz').intern
    Zlib::GzipReader.open(lst) do |gz|
      gz.each_line do |line|
        line.strip!
        unless line.end_with?('/')
          path = line.intern
          content2pkg[path] = [] unless content2pkg.key?(path)
          content2pkg[path] << pkg
        end
      end
    end
  end
  content2pkg
end