Class: Jah::Pacman

Inherits:
ActPkg::Base show all
Defined in:
lib/jah/act_pkg/pacman.rb

Instance Method Summary collapse

Methods inherited from ActPkg::Base

#run

Instance Method Details

#all(filter = nil) ⇒ Object

-Q installed packages



7
8
9
10
11
12
13
# File 'lib/jah/act_pkg/pacman.rb', line 7

def all(filter = nil)
  res = run("pacman -Q").to_a.map do |line|
    Pkg.new(:installed, *line.split(" "))
  end
  res.select { |p| p.name =~ /#{filter}/ } if filter
  res
end

#info(pkg) ⇒ Object

-Qi info about a pkg (only installed ones)



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jah/act_pkg/pacman.rb', line 28

def info(pkg)
  ary = run("pacman -Qi #{pkg.name}").to_a
  return nil if ary[0] =~ /error/
  ary.map! do |i|
    val = i.split("\s:\s")[1]
    val.strip if val
  end #.reject(&:nil?)
  { :url => ary[2], :license => ary[3], :groups => ary[4], :provides => ary[5],
  :depends => ary[6], :required => ary[8], :size => ary[12], :arch => ary[14],
  :desc => ary[19]}
end

#install(pkgs) ⇒ Object



40
41
42
43
# File 'lib/jah/act_pkg/pacman.rb', line 40

def install(pkgs)
  pkgs = [pkgs] unless pkgs.class == Array
  run "pacman -Sy --noconfirm #{pkgs.map(&:name).join(' ')}"
end

#search(filter = nil) ⇒ Object

-Ss /regex/ search all pkgs



16
17
18
19
20
21
22
23
24
25
# File 'lib/jah/act_pkg/pacman.rb', line 16

def search(filter = nil)
  pkgs = []
  installed = all(filter) # until figure out a memoize for all this
  run("pacman -Ss #{filter}").to_a.each_slice(2) do |info, desc|
    name, version, size = info.split("/")[1].split(" ")
    state = installed.find { |i| i.name == name }
    pkgs << Pkg.new(state ? :installed : :new, name, version, desc.strip)
  end
  pkgs
end

#uninstall(pkg) ⇒ Object



45
46
47
# File 'lib/jah/act_pkg/pacman.rb', line 45

def uninstall(pkg)
  run "pacman -R --noconfirm #{pkg.name}"
end

#updateObject



53
54
55
# File 'lib/jah/act_pkg/pacman.rb', line 53

def update
  run "pacman -Syu"
end

#upgrade(pkg) ⇒ Object



49
50
51
# File 'lib/jah/act_pkg/pacman.rb', line 49

def upgrade(pkg)
  run "pacman -U --noconfirm #{pkg.name}"
end