Class: RuAUR::AUR
- Inherits:
-
Object
- Object
- RuAUR::AUR
- Defined in:
- lib/ruaur/aur.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #download(package, status = true) ⇒ Object
- #get_dependencies(package) ⇒ Object
- #info(pkg_name) ⇒ Object
-
#initialize(pacman, cache = "/tmp/ruaur-#{ENV["USER"]}") ⇒ AUR
constructor
A new instance of AUR.
- #install(pkg_name, noconfirm = false) ⇒ Object
- #multiinfo(pkgs) ⇒ Object
- #query(pkg_name, info = false) ⇒ Object
- #search(string) ⇒ Object
- #upgrade(noconfirm = false) ⇒ Object
Constructor Details
#initialize(pacman, cache = "/tmp/ruaur-#{ENV["USER"]}") ⇒ AUR
Returns a new instance of AUR.
197 198 199 200 201 202 203 204 |
# File 'lib/ruaur/aur.rb', line 197 def initialize(pacman, cache = "/tmp/ruaur-#{ENV["USER"]}") cache = "/tmp/ruaur-#{ENV["USER"]}" if (cache.nil?) @cache = Pathname.new(cache). FileUtils.mkdir_p(@cache) @installed = pacman.query_aur @pacman = pacman @rpc_url = "https://aur.archlinux.org/rpc.php" end |
Instance Method Details
#clean ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ruaur/aur.rb', line 11 def clean puts hilight_status("Cleaning AUR cache...") Dir.chdir(@cache) do FileUtils.rm_rf(Dir["*"]) end end |
#download(package, status = true) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruaur/aur.rb', line 40 def download(package, status = true) FileUtils.rm_f(Dir["#{package.name}.tar.gz*"]) if (status) puts hilight_status("Downloading #{package.name}...") end tarball(package.name, package.url, "#{package.name}.tar.gz") tgz = Pathname.new("#{package.name}.tar.gz"). if (!tgz.exist?) raise RuAUR::Error::FailedToDownload.new( package.name ) end end |
#get_dependencies(package) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ruaur/aur.rb', line 133 def get_dependencies(package) deps = Array.new Dir.chdir("#{@cache}/#{package.name}") do system("chown -R nobody:nobody .") if (Process.uid == 0) cmd = "su -s /bin/sh nobody -c \"makepkg --printsrcinfo\"" cmd = "makepkg --printsrcinfo" if (Process.uid != 0) %x(#{cmd}).each_line do |line| line.match( /^\s*depends(_i686|_x86_64)?\s*\=\s*([^>=:]+)/ ) do |m| deps.push(m[2].strip) end end end return deps end |
#info(pkg_name) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ruaur/aur.rb', line 174 def info(pkg_name) return nil if (pkg_name.nil? || pkg_name.empty?) query = "type=info&arg=#{pkg_name}" response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5) if (response.timed_out?) raise RuAUR::Error::AUR.new( "Check your internet connection!" ) end return nil if (response.body.empty?) body = JSON.parse(response.body) if (body["type"] == "error") raise RuAUR::Error::AUR.new(body["results"]) end return nil if (body["results"].empty?) return RuAUR::Package.new(body["results"], "aur") end |
#install(pkg_name, noconfirm = false) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/ruaur/aur.rb', line 206 def install(pkg_name, noconfirm = false) package = info(pkg_name) if (package.nil?) raise RuAUR::Error::PackageNotFound.new(pkg_name) end if ( @installed.include?(pkg_name) && !package.newer?(@installed[pkg_name]) ) puts hilight_installed("Already installed: #{pkg_name}") return end Dir.chdir(@cache) do download(package) extract(package) end Dir.chdir("#{@cache}/#{package.name}") do return if (edit_pkgbuild(package, noconfirm)) install_dependencies(package, noconfirm) compiled = compile(package) @pacman.install_local(compiled, noconfirm) end @installed.merge!(@pacman.query_aur(pkg_name)) end |
#multiinfo(pkgs) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/ruaur/aur.rb', line 251 def multiinfo(pkgs) results = Array.new return results if (pkgs.nil? || pkgs.empty?) query = "type=multiinfo&arg[]=#{pkgs.join("&arg[]=")}" response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5) if (response.timed_out?) raise RuAUR::Error::AUR.new( "Check your internet connection!" ) end return results if (response.body.empty?) body = JSON.parse(response.body) if (body["type"] == "error") raise RuAUR::Error::AUR.new(body["results"]) end body["results"].each do |result| results.push(RuAUR::Package.new(result, "aur")) end return results.sort end |
#query(pkg_name, info = false) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/ruaur/aur.rb', line 278 def query(pkg_name, info = false) package = info(pkg_name) return Hash.new if (package.nil?) results = Hash.new json = package.json if (!json.empty?) results[pkg_name] = json["Version"] if (info) max = 12 # Length of "Dependencies" json.each do |k, v| max = k.length if (max < k.length) end out = Array.new json.each do |k, v| filler = Array.new(max - k.length + 2, " ").join out.push("#{k}#{filler}: #{v}") end Dir.chdir(@cache) do download(package, false) extract(package, false) end deps = get_dependencies(package) filler = Array.new(max - 10, " ").join out.push("Dependencies#{filler}: #{deps.join(" ")}") results[pkg_name] = out.join("\n") end end # Clean up Dir.chdir(@cache) do FileUtils.rm_rf(Dir["#{package.name}*"]) end return results end |
#search(string) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/ruaur/aur.rb', line 320 def search(string) results = Array.new return results if (string.nil? || string.empty?) query = "type=search&arg=#{string}" response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5) if (response.timed_out?) raise RuAUR::Error::AUR.new( "Check your internet connection!" ) end return results if (response.body.empty?) body = JSON.parse(response.body) if (body["type"] == "error") raise RuAUR::Error::AUR.new(body["results"]) end body["results"].each do |result| results.push(RuAUR::Package.new(result, "aur")) end results.each do |package| if (@installed.has_key?(package.name)) package.installed(@installed[package.name]) end end return results.sort end |
#upgrade(noconfirm = false) ⇒ Object
378 379 380 381 382 383 384 385 386 |
# File 'lib/ruaur/aur.rb', line 378 def upgrade(noconfirm = false) find_upgrades.each do |pkg_name, versions| old, new = versions puts hilight_status("Upgrading #{pkg_name}...") puts hilight_upgrade(old, new) install(pkg_name, noconfirm) end end |