class RuAUR::Pacman

Public Class Methods

new() click to toggle source
# File lib/ruaur/pacman.rb, line 39
def initialize
    if (ScoobyDoo.where_are_you("pacman").nil?)
        raise RuAUR::Error::MissingDependency.new("pacman")
    end

    @pac_nocolor = "pacman --color=never"
    @pac_color = "pacman --color=always"
    @pac_cmd = @pac_color
    @pac_cmd = @pac_nocolor if (!RuAUR.hilight?)
    @installed = query
end

Public Instance Methods

clean(noconfirm = false) click to toggle source
# File lib/ruaur/pacman.rb, line 6
def clean(noconfirm = false)
    puts(hilight_status("Cleaning pacman cache..."))
    system("sudo #{@pac_cmd} -Sc") if (!noconfirm)
    system("sudo #{@pac_cmd} -Sc --noconfirm") if (noconfirm)
end
download(pkg_name, noconfirm = false) click to toggle source
# File lib/ruaur/pacman.rb, line 12
def download(pkg_name, noconfirm = false)
    puts(hilight_status("Downloading #{pkg_name}..."))
    if (!noconfirm)
        system("sudo #{@pac_cmd} -Sw #{pkg_name}")
    else
        system("sudo #{@pac_cmd} -Sw #{pkg_name} --noconfirm")
    end
end
exist?(pkg_name) click to toggle source
# File lib/ruaur/pacman.rb, line 21
def exist?(pkg_name)
    return !%x(
        #{@pac_nocolor} -Ss "^#{pkg_name.shellescape}$"
    ).empty?
end
install(pkg_name, noconfirm = false) click to toggle source
# File lib/ruaur/pacman.rb, line 51
def install(pkg_name, noconfirm = false)
    if (@installed.include?(pkg_name))
        puts(hilight_installed("Already installed: #{pkg_name}"))
        return
    end

    puts(hilight_status("Installing #{pkg_name}..."))
    if (!noconfirm)
        system("sudo #{@pac_cmd} -S #{pkg_name} --needed")
    else
        system(
            "sudo #{@pac_cmd} -S #{pkg_name} --needed --noconfirm"
        )
    end

    @installed.merge!(query(pkg_name))
end
install_local(pkgs, noconfirm = false) click to toggle source
# File lib/ruaur/pacman.rb, line 69
def install_local(pkgs, noconfirm = false)
    puts(hilight_status("Installing compiled packages..."))
    xzs = pkgs.join(" ")
    if (!noconfirm)
        system("sudo #{@pac_cmd} -U #{xzs}")
    else
        system("sudo #{@pac_cmd} -U #{xzs} --noconfirm")
    end
end
query(pkg_name = "", info = false) click to toggle source
# File lib/ruaur/pacman.rb, line 79
def query(pkg_name = "", info = false)
    results = Hash.new
    if (info)
        result = %x(#{@pac_nocolor} -Qi #{pkg_name} 2>/dev/null)
        result.strip!
        results[pkg_name] = result if (!result.empty?)
    else
        result = %x(#{@pac_nocolor} -Q #{pkg_name} 2>/dev/null)
        result.strip!
        result.split("\n").each do |l|
            name, version = l.split
            results[name] = version
        end
    end
    return results
end
query_aur(pkg_name = "") click to toggle source
# File lib/ruaur/pacman.rb, line 96
def query_aur(pkg_name = "")
    results = Hash.new
    %x(
        #{@pac_nocolor} -Qm #{pkg_name} 2>/dev/null
    ).each_line do |line|
        line = line.split
        results[line[0]] = line[1]
    end
    return results
end
query_owns(file_names) click to toggle source
# File lib/ruaur/pacman.rb, line 107
def query_owns(file_names)
    return %x(#{@pac_nocolor} -Qo #{file_names})
end
remove(pkg_names, nosave = false) click to toggle source
# File lib/ruaur/pacman.rb, line 111
def remove(pkg_names, nosave = false)
    puts(hilight_status("Removing #{pkg_names.join(" ")}..."))
    if (!nosave)
        system("sudo #{@pac_cmd} -Rs #{pkg_names.join(" ")}")
    else
        system("sudo #{@pac_cmd} -Rns #{pkg_names.join(" ")}")
    end
end
upgrade(noconfirm = false) click to toggle source
# File lib/ruaur/pacman.rb, line 160
def upgrade(noconfirm = false)
    puts(hilight_status("Updating..."))
    system("sudo #{@pac_cmd} -Syyu") if (!noconfirm)
    system("sudo #{@pac_cmd} -Syyu --noconfirm") if (noconfirm)
end

Private Instance Methods

hilight_installed(installed) click to toggle source
# File lib/ruaur/pacman.rb, line 27
def hilight_installed(installed)
    return installed if (!RuAUR.hilight?)
    return installed.light_yellow
end
hilight_status(status) click to toggle source
# File lib/ruaur/pacman.rb, line 33
def hilight_status(status)
    return status if (!RuAUR.hilight?)
    return status.light_white
end