gigamo-aurb 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/aurb.gemspec +2 -2
- data/bin/aurb +75 -16
- metadata +2 -2
data/aurb.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'aurb'
|
3
|
-
s.version = '0.5.
|
4
|
-
s.date = %q{2009-04-
|
3
|
+
s.version = '0.5.5'
|
4
|
+
s.date = %q{2009-04-12}
|
5
5
|
s.summary = %q{A simple AUR utility}
|
6
6
|
s.email = %q{gigamo@gmail.com}
|
7
7
|
s.homepage = %q{http://github.com/gigamo/aurb}
|
data/bin/aurb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
require 'optparse'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'cgi'
|
6
|
+
require 'json'
|
7
|
+
require 'open-uri'
|
8
|
+
require 'pathname'
|
9
|
+
require 'zlib'
|
10
|
+
require 'facets/ansicode'
|
11
|
+
require 'facets/minitar'
|
12
|
+
require 'facets/version'
|
5
13
|
|
6
14
|
module Aurb
|
7
15
|
Config = Struct.new(:search, :info, :sync, :dir)
|
8
|
-
Version = [0, 5,
|
16
|
+
Version = [0, 5, 5]
|
9
17
|
# Change Me!
|
10
|
-
DlPath = File.join(File.expand_path('~'), 'abs') # => '/home/gig/abs'
|
18
|
+
DlPath = File.join(File.expand_path('~'), 'abs') # => '/home/gig/abs'
|
11
19
|
|
12
20
|
def self.aur
|
13
21
|
@aur ||= Aur.new
|
@@ -15,7 +23,11 @@ module Aurb
|
|
15
23
|
|
16
24
|
module Util
|
17
25
|
# Colorize a string
|
18
|
-
#
|
26
|
+
#
|
27
|
+
# color('Text', :green)
|
28
|
+
#
|
29
|
+
# For a full list of available effects, see
|
30
|
+
# http://facets.rubyforge.org/doc/api/more/classes/ANSICode.html
|
19
31
|
def color(text, effect)
|
20
32
|
ANSICode.send(effect.to_sym) << text << ANSICode.clear
|
21
33
|
end
|
@@ -36,6 +48,7 @@ module Aurb
|
|
36
48
|
@opts = Opts.new(ARGV)
|
37
49
|
end
|
38
50
|
|
51
|
+
# Starts Aurb
|
39
52
|
def start
|
40
53
|
# Exit peacefully on *INT
|
41
54
|
trap(:INT) { exit 0 }
|
@@ -48,6 +61,10 @@ module Aurb
|
|
48
61
|
exit 1
|
49
62
|
end
|
50
63
|
|
64
|
+
# Downloads +packages+
|
65
|
+
#
|
66
|
+
# download('awesome-git', 'aurb')
|
67
|
+
#
|
51
68
|
def download(*packages)
|
52
69
|
packages.each do |package|
|
53
70
|
list(package).each do |names|
|
@@ -55,13 +72,17 @@ module Aurb
|
|
55
72
|
# Check if the package exists in the community repo
|
56
73
|
# Invoke pacman if so
|
57
74
|
if in_sync? package
|
58
|
-
puts "#{color('==>', :yellow)} Found #{package} in community repo.
|
75
|
+
puts "#{color('==>', :yellow)} Found #{package} in community repo. \
|
76
|
+
Pacman will do."
|
59
77
|
exec "sudo pacman -S #{package}"
|
60
78
|
else
|
61
79
|
# Else download and untar it from the AUR
|
62
80
|
Dir.chdir(@config.dir) do |dir|
|
81
|
+
# Remove old files if they already exist instead of overwriting
|
82
|
+
FileUtils.rm("#{package}.tar.gz") if File.exists?("#{package}.tar.gz")
|
63
83
|
fetch(package, dir)
|
64
84
|
puts "#{color('==>', :yellow)} Downloaded #{package}"
|
85
|
+
FileUtils.rm_r(package) if File.directory?(package)
|
65
86
|
untar(package)
|
66
87
|
puts "#{color('==>', :yellow)} Unpacked #{package}"
|
67
88
|
end
|
@@ -71,6 +92,10 @@ module Aurb
|
|
71
92
|
end
|
72
93
|
end
|
73
94
|
|
95
|
+
# Searches for +package+
|
96
|
+
#
|
97
|
+
# search('awesome')
|
98
|
+
#
|
74
99
|
def search(package)
|
75
100
|
count, threads = 0, []
|
76
101
|
list(package).each do |names|
|
@@ -83,10 +108,13 @@ module Aurb
|
|
83
108
|
result = result['results']
|
84
109
|
# Skip this iteration if the package is found in the community repo
|
85
110
|
next if in_sync? result['Name']
|
86
|
-
|
87
|
-
|
111
|
+
if package.any? do |pac|
|
112
|
+
# Check both name and description for matches
|
113
|
+
(result['Name'].include?(pac)) || (result['Description'].include?(pac))
|
114
|
+
end
|
88
115
|
count += 1
|
89
|
-
puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}]
|
116
|
+
puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] \
|
117
|
+
#{color(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
|
90
118
|
end
|
91
119
|
end
|
92
120
|
end
|
@@ -94,9 +122,12 @@ module Aurb
|
|
94
122
|
# Join the threads after searching is finished
|
95
123
|
threads.each { |t| t.join }
|
96
124
|
|
97
|
-
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)}
|
125
|
+
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
|
126
|
+
#{count == 1 ? 'result' : 'results'}"
|
98
127
|
end
|
99
128
|
|
129
|
+
# Checks the aur for upgrades to local packages that were not found in any
|
130
|
+
# official repository.
|
100
131
|
def check_upgrade
|
101
132
|
count, upgradable = 0, []
|
102
133
|
`pacman -Qm`.each_line do |line|
|
@@ -115,7 +146,8 @@ module Aurb
|
|
115
146
|
# Insert the upgradable package's name into an array which we will
|
116
147
|
# use later to prompt the download
|
117
148
|
upgradable << name
|
118
|
-
puts "#{color(name, :bold)} (#{color(version, :red)})
|
149
|
+
puts "#{color(name, :bold)} (#{color(version, :red)}) \
|
150
|
+
can be upgraded to #{color(result['Version'], :green)}"
|
119
151
|
end
|
120
152
|
else
|
121
153
|
puts "#{color(name, :bold)} (#{color(version, :green)}) is up to date"
|
@@ -123,7 +155,8 @@ module Aurb
|
|
123
155
|
end
|
124
156
|
end
|
125
157
|
|
126
|
-
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)}
|
158
|
+
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
|
159
|
+
#{count == 1 ? 'upgrade' : 'upgrades'}"
|
127
160
|
unless upgradable.empty?
|
128
161
|
# Prompt asking to download the upgrades
|
129
162
|
upgradable.each do |pkg|
|
@@ -134,10 +167,18 @@ module Aurb
|
|
134
167
|
end
|
135
168
|
|
136
169
|
private
|
170
|
+
# Checks if a package exists in the community repository
|
171
|
+
#
|
172
|
+
# in_sync?('awesome-git')
|
173
|
+
#
|
137
174
|
def in_sync?(package)
|
138
175
|
Dir["#{@config.sync}/#{package}-*"].first ? true : false
|
139
176
|
end
|
140
177
|
|
178
|
+
# Returns a list of packages found by a search
|
179
|
+
#
|
180
|
+
# list('awesome-git')
|
181
|
+
#
|
141
182
|
def list(package)
|
142
183
|
info, list = json(@config.search % CGI::escape(package)), []
|
143
184
|
if info['type'] == 'error'
|
@@ -149,6 +190,10 @@ module Aurb
|
|
149
190
|
list.sort unless list.empty?
|
150
191
|
end
|
151
192
|
|
193
|
+
# Downloads given +package+ into +dir+
|
194
|
+
#
|
195
|
+
# fetch('awesome-git', $0.dirname)
|
196
|
+
#
|
152
197
|
def fetch(package, dir)
|
153
198
|
open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
|
154
199
|
File.open("#{dir}/#{package}.tar.gz", 'wb') do |local|
|
@@ -157,10 +202,21 @@ module Aurb
|
|
157
202
|
end
|
158
203
|
end
|
159
204
|
|
205
|
+
# Untars +package+
|
206
|
+
#
|
207
|
+
# untar('awesome-git') #=> .tar.gz is automagically appended
|
208
|
+
#
|
160
209
|
def untar(package)
|
161
|
-
Archive::Tar::Minitar.unpack(
|
210
|
+
Archive::Tar::Minitar.unpack(
|
211
|
+
Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
|
212
|
+
Dir.pwd
|
213
|
+
)
|
162
214
|
end
|
163
215
|
|
216
|
+
# Shortcut to parsing json
|
217
|
+
#
|
218
|
+
# json('http://foo.bar')
|
219
|
+
#
|
164
220
|
def json(item)
|
165
221
|
JSON.parse(open(item).read)
|
166
222
|
end
|
@@ -169,6 +225,8 @@ module Aurb
|
|
169
225
|
class Opts < Hash
|
170
226
|
def initialize(args = ARGV)
|
171
227
|
@@args = args.empty? ? ['-h'] : args
|
228
|
+
|
229
|
+
# Invoke this class's only private method
|
172
230
|
parse
|
173
231
|
end
|
174
232
|
|
@@ -177,9 +235,10 @@ module Aurb
|
|
177
235
|
OptionParser.new do |o|
|
178
236
|
o.version = Version.join('.')
|
179
237
|
o.program_name = 'Aurb'
|
180
|
-
o.release = '2009-04-
|
238
|
+
o.release = '2009-04-12'
|
181
239
|
|
182
|
-
o.on('-D', '--download P1,P2,...', Array,
|
240
|
+
o.on('-D', '--download P1,P2,...', Array, "Download package(s). \
|
241
|
+
Separate by commas if multiple (no spaces).") do |d|
|
183
242
|
self[:cmd] = "download('#{d*"', '"}')"
|
184
243
|
end
|
185
244
|
o.on('-S', '--search PKG', 'Search for a package.') do |s|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gigamo-aurb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gigamo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|