Sha256: f1b311fd5e8ec6f42c2255f125c2fac05ddb933ef20176544e4d712c647140d3

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

UPM::Tool.new "apt" do

  os "debian", "ubuntu"

  command "install",  "apt install", root: true
  command "update",   "apt update",  root: true
  
  command "upgrade" do |args|
    call_command("update")
    run("apt", "upgrade", root: true)
  end

  command "remove",   "apt remove",  root: true

  command "files",  "dpkg-query -L", paged: true
  command "search", "apt search",    paged: true
  command "info",   "apt show",      paged: true

  command "list" do |args|
    if args.any?
      query = args.join
      run("dpkg", "-l", grep: query, paged: true)
    else
      run("dpkg", "-l", paged: true)
    end
  end
  
  command "mirrors" do
    print_files("/etc/apt/sources.list", *Dir["/etc/apt/sources.list.d/*"], exclude: /^(#|$)/)
  end

  command "log" do
    UPM::LogParser.new(DpkgEvent, "/var/log/dpkg*").display
  end

  class DpkgEvent < Struct.new(:datestr, :date, :cmd, :name, :v1, :v2)

    # 2010-12-03 01:36:56 remove gir1.0-mutter-2.31 2.31.5-0ubuntu9 2.31.5-0ubuntu9
    # 2010-12-03 01:36:58 install gir1.0-mutter-2.91 <none> 2.91.2+git20101114.982a10ac-0ubuntu1~11.04~ricotz0  
    #LINE_RE = /^(.+ .+) (status \w+|\w+) (.+) (.+)$/
    LINE_RE = /^(.+ .+) (remove|install|upgrade) (.+) (.+) (.+)$/

    CMD_COLORS = {
      'remove' => :light_red,
      'install' => :light_yellow,
      'upgrade' => :light_green,
      nil => :white,
    }
    
    def self.parse_date(date)
      DateTime.strptime(date, "%Y-%m-%d %H:%M:%S")
    end
   
    def self.from_line(line)
      if line =~ LINE_RE
        new($1, parse_date($1), $2, $3, $4, $5)
      else
        nil
      end
    end    
    
    def cmd_color
      CMD_COLORS[cmd]
    end

    def to_s
      date, time = datestr.split
      "<grey>[<white>#{date} #{time}<grey>] <#{cmd_color}>#{cmd} <light_cyan>#{name} <light_white>#{v2} <white>(#{v1})".colorize
    end  

  end
      
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
upm-0.1.5 lib/upm/tools/apt.rb
upm-0.1.3 lib/upm/tools/apt.rb
upm-0.1.2 lib/upm/tools/apt.rb