Class: RuAUR

Inherits:
Object
  • Object
show all
Defined in:
lib/ruaur.rb

Defined Under Namespace

Classes: AUR, Error, Operation, Options, Package, Pacman

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hilight = false) ⇒ RuAUR

Returns a new instance of RuAUR.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruaur.rb', line 41

def initialize(hilight = false)
    [
        "makepkg",
        "pacman",
        "su",
        "sudo"
    ].each do |dep|
        if (ScoobyDoo.where_are_you(dep).nil?)
            raise RuAUR::Error::MissingDependency.new(dep)
        end
    end

    @@hilight = hilight
    @pacman = RuAUR::Pacman.new
    @aur = RuAUR::AUR.new(@pacman, nil)
    @lock = Pathname.new("/tmp/ruaur.lock").expand_path
end

Class Method Details

.hilight?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/ruaur.rb', line 36

def self.hilight?
    @@hilight ||= false
    return @@hilight
end

.validate_options(options) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ruaur.rb', line 156

def self.validate_options(options)
    valid = {
        RuAUR::Operation::Query => {
            "valid" => [
                RuAUR::Options::Info,
                RuAUR::Options::Owns
            ]
        },
        RuAUR::Operation::Remove => {
            "valid" => [
                RuAUR::Options::NoSave
            ]
        },
        RuAUR::Operation::Sync => {
            "valid" => [
                RuAUR::Options::Clean,
                RuAUR::Options::Download,
                RuAUR::Options::NamesOnly,
                RuAUR::Options::NoConfirm,
                RuAUR::Options::Search,
                RuAUR::Options::Upgrade
            ],
            RuAUR::Options::Clean => [
                RuAUR::Options::Clean,
                RuAUR::Options::NoConfirm
            ],
            RuAUR::Options::Download => [
                RuAUR::Options::Download,
                RuAUR::Options::NoConfirm
            ],
            RuAUR::Options::Search => [
                RuAUR::Options::NamesOnly,
                RuAUR::Options::NoConfirm,
                RuAUR::Options::Search
            ],
            RuAUR::Options::Upgrade => [
                RuAUR::Options::NoConfirm,
                RuAUR::Options::Upgrade
            ]
        }
    }

    return false if (valid[options["operation"]].nil?)

    valid[options["operation"]].each do |k, v|
        if ((k == "valid") || options["options"].include?(k))
            options["options"].each do |o|
                return false if (!v.include?(o))
            end
        end
    end

    return true
end

Instance Method Details

#clean(noconfirm) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ruaur.rb', line 14

def clean(noconfirm)
    check_and_lock
    @pacman.clean(noconfirm)
    @aur.clean
ensure
    unlock
end

#download(pkg_names, noconfirm = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruaur.rb', line 22

def download(pkg_names, noconfirm = false)
    pkg_names.each do |pkg_name|
        if (@pacman.exist?(pkg_name))
            @pacman.download(pkg_name, noconfirm)
            system(
                "cp /var/cache/pacman/pkg/#{pkg_name}-[0-9]*.xz ."
            )
        else
            package = @aur.info(pkg_name)
            @aur.download(package)
        end
    end
end

#install(pkg_names, noconfirm = false) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ruaur.rb', line 59

def install(pkg_names, noconfirm = false)
    if (pkg_names.nil? || pkg_names.empty?)
        raise RuAUR::Error::PackageNotFound.new
    end

    check_and_lock

    pkg_names.each do |pkg_name|
        if (@pacman.exist?(pkg_name))
            @pacman.install(pkg_name, noconfirm)
        else
            @aur.install(pkg_name, noconfirm)
        end
    end
ensure
    unlock
end

#query(pkg_names, options = []) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruaur.rb', line 77

def query(pkg_names, options = [])
    info = options.include?(RuAUR::Options::Info)
    owns = options.include?(RuAUR::Options::Owns)

    if (owns)
        puts(@pacman.query_owns(pkg_names.join(" ")))
    else
        pkg_names.each do |pkg_name|
            results = @pacman.query(pkg_name, info)
            results.each do |name, details|
                print "#{name} " if (!info)
                puts(details)
                puts if (info)
            end
            results = @aur.query(pkg_name, info)
            results.each do |name, details|
                print "#{name} " if (!info)
                puts(details)
                puts if (info)
            end
        end
    end
end

#remove(pkg_names, options = []) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/ruaur.rb', line 101

def remove(pkg_names, options = [])
    check_and_lock
    nosave = options.include?(RuAUR::Options::NoSave)
    @pacman.remove(pkg_names, nosave)
ensure
    unlock
end

#search(string, names_only = false) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/ruaur.rb', line 109

def search(string, names_only = false)
    found = @pacman.search(string).concat(@aur.search(string))
    return found if (!names_only)
    names = Array.new
    found.each do |pkg|
        names.push(pkg.name) if (!names.include?(pkg.name))
    end
    return names
end

#sync(packages = [], options = []) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ruaur.rb', line 119

def sync(packages = [], options = [])
    if (options.include?(RuAUR::Options::Clean))
        clean(options.include?(RuAUR::Options::NoConfirm))
    elsif (options.include?(RuAUR::Options::Download))
        download(
            packages,
            options.include?(RuAUR::Options::NoConfirm)
        )
    elsif (options.include?(RuAUR::Options::Search))
        return search(
            packages.join(" "),
            options.include?(RuAUR::Options::NamesOnly)
        )
    elsif (options.include?(RuAUR::Options::Upgrade))
        upgrade(options.include?(RuAUR::Options::NoConfirm))
    else
        install(
            packages,
            options.include?(RuAUR::Options::NoConfirm)
        )
    end
    return nil
end

#upgrade(noconfirm = false) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/ruaur.rb', line 148

def upgrade(noconfirm = false)
    check_and_lock
    @pacman.upgrade(noconfirm)
    @aur.upgrade(noconfirm)
ensure
    unlock
end