Sha256: 1f94aabf5b75853fb3e72e46b38cc62193a5a281cf3d4048bf1ac31f5469e158

Contents?: true

Size: 1.91 KB

Versions: 13

Compression:

Stored size: 1.91 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|
    if call_command("update")
      run("apt", "upgrade", root: true)
    else
      puts "Error: couldn't 'apt update' package lists"
    end
  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

13 entries across 13 versions & 1 rubygems

Version Path
upm-0.1.18 lib/upm/tools/apt.rb
upm-0.1.17 lib/upm/tools/apt.rb
upm-0.1.16 lib/upm/tools/apt.rb
upm-0.1.15 lib/upm/tools/apt.rb
upm-0.1.14 lib/upm/tools/apt.rb
upm-0.1.13 lib/upm/tools/apt.rb
upm-0.1.12 lib/upm/tools/apt.rb
upm-0.1.11 lib/upm/tools/apt.rb
upm-0.1.10 lib/upm/tools/apt.rb
upm-0.1.9 lib/upm/tools/apt.rb
upm-0.1.8 lib/upm/tools/apt.rb
upm-0.1.7 lib/upm/tools/apt.rb
upm-0.1.6 lib/upm/tools/apt.rb