gigamo-aurb 0.5.5 → 0.5.6

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.
Files changed (3) hide show
  1. data/aurb.gemspec +2 -2
  2. data/bin/aurb +220 -207
  3. 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.5'
4
- s.date = %q{2009-04-12}
3
+ s.version = '0.5.6'
4
+ s.date = %q{2009-04-13}
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,260 +1,273 @@
1
1
  #!/usr/bin/env ruby
2
- require 'optparse'
3
- require 'fileutils'
4
2
  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'
13
3
 
14
4
  module Aurb
15
- Config = Struct.new(:search, :info, :sync, :dir)
16
- Version = [0, 5, 5]
17
- # Change Me!
18
- DlPath = File.join(File.expand_path('~'), 'abs') # => '/home/gig/abs'
19
5
 
20
- def self.aur
21
- @aur ||= Aur.new
6
+ DlPath = File.join(File.expand_path('~'), 'abs') # Change me!
7
+ Config = Struct.new :search, :info, :sync, :dir
8
+
9
+ def self.aur
10
+ @aur ||= Aur.new
11
+ end
12
+
13
+ module Util
14
+ # Colorize a string
15
+ #
16
+ # color('Text', :green)
17
+ #
18
+ # For a full list of available effects, see
19
+ # http://facets.rubyforge.org/doc/api/more/classes/ANSICode.html
20
+ def color text, effect
21
+ require 'facets/ansicode' unless defined? ANSICode
22
+
23
+ ANSICode.send(effect.to_sym) << text << ANSICode.clear
22
24
  end
25
+ end
23
26
 
24
- module Util
25
- # Colorize a string
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
31
- def color(text, effect)
32
- ANSICode.send(effect.to_sym) << text << ANSICode.clear
33
- end
27
+ class AurbError < Exception; end
28
+
29
+ class Aur
30
+ include Aurb::Util
31
+
32
+ def initialize
33
+ require 'pathname'
34
+
35
+ @config = Config.new(
36
+ 'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
37
+ 'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
38
+ '/var/lib/pacman/sync/community',
39
+ Pathname.new(DlPath).realpath
40
+ )
41
+ @opts = Opts.new(ARGV)
34
42
  end
35
43
 
36
- class AurbError < Exception; end
44
+ # Starts Aurb
45
+ def start
46
+ # Exit peacefully on *INT
47
+ trap(:INT) { exit 0 }
37
48
 
38
- class Aur
39
- include Aurb::Util
49
+ # Evaluate a command in string form
50
+ # Example: instance_eval('search("package")')
51
+ # Which will invoke the search method
52
+ instance_eval(@opts[:cmd])
53
+ rescue AurbError => e
54
+ $stderr.puts e.message
55
+ exit 1
56
+ end
40
57
 
41
- def initialize
42
- @config = Config.new(
43
- 'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
44
- 'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
45
- '/var/lib/pacman/sync/community',
46
- Pathname.new(DlPath).realpath
47
- )
48
- @opts = Opts.new(ARGV)
49
- end
58
+ # Downloads +packages+
59
+ #
60
+ # download('awesome-git', 'aurb')
61
+ #
62
+ def download *packages
63
+ packages.each do |package|
64
+ list(package).each do |names|
65
+ if names.first == package
66
+ # Check if the package exists in the community repo
67
+ # Invoke pacman if so
68
+ if in_sync? package
69
+ puts "#{color('==>', :yellow)} Found #{package} in community repo."
70
+ exec "sudo pacman -S #{package}"
71
+ else
72
+ Dir.chdir(@config.dir) do |dir|
73
+ # Remove old files if they already exist instead of overwriting
74
+ require 'fileutils'
50
75
 
51
- # Starts Aurb
52
- def start
53
- # Exit peacefully on *INT
54
- trap(:INT) { exit 0 }
55
- # Evaluate a command in string form
56
- # Example: instance_eval('search("package")')
57
- # Which will invoke the search method
58
- instance_eval(@opts[:cmd])
59
- rescue AurbError => e
60
- $stderr.puts e.message
61
- exit 1
62
- end
76
+ FileUtils.rm("#{package}.tar.gz") if File.exists?("#{package}.tar.gz")
77
+ fetch(package, dir)
78
+ puts "#{color('==>', :yellow)} Downloaded #{package}"
63
79
 
64
- # Downloads +packages+
65
- #
66
- # download('awesome-git', 'aurb')
67
- #
68
- def download(*packages)
69
- packages.each do |package|
70
- list(package).each do |names|
71
- if names.first == package
72
- # Check if the package exists in the community repo
73
- # Invoke pacman if so
74
- if in_sync? package
75
- puts "#{color('==>', :yellow)} Found #{package} in community repo. \
76
- Pacman will do."
77
- exec "sudo pacman -S #{package}"
78
- else
79
- # Else download and untar it from the AUR
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")
83
- fetch(package, dir)
84
- puts "#{color('==>', :yellow)} Downloaded #{package}"
85
- FileUtils.rm_r(package) if File.directory?(package)
86
- untar(package)
87
- puts "#{color('==>', :yellow)} Unpacked #{package}"
88
- end
80
+ FileUtils.rm_r(package) if File.directory?(package)
81
+ untar(package)
82
+ puts "#{color('==>', :yellow)} Unpacked #{package}"
89
83
  end
90
84
  end
91
85
  end
92
86
  end
93
87
  end
88
+ end
94
89
 
95
- # Searches for +package+
96
- #
97
- # search('awesome')
98
- #
99
- def search(package)
100
- count, threads = 0, []
101
- list(package).each do |names|
102
- # Launch a separate thread for each packagename to be checked
103
- # This is slooow otherwise, because it will have to wait for each result
104
- # to be displayed before going on to the next one
105
- threads << Thread.new do
106
- result = json(@config.info % names[1])
107
- unless result['type'] == 'error'
108
- result = result['results']
109
- # Skip this iteration if the package is found in the community repo
110
- next if in_sync? result['Name']
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
115
- count += 1
116
- puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] \
90
+ # Searches for +package+
91
+ #
92
+ # search('awesome')
93
+ #
94
+ def search package
95
+ count, threads = 0, []
96
+
97
+ list(package).each do |names|
98
+ # Launch a separate thread for each packagename to be checked
99
+ threads << Thread.new do
100
+ result = json(@config.info % names[1])
101
+
102
+ unless result['type'] == 'error'
103
+ result = result['results']
104
+ # Skip this iteration if the package is found in the community repo
105
+ next if in_sync? result['Name']
106
+
107
+ if package.any? do |pac|
108
+ # Check both name and description for matches
109
+ (result['Name'].include?(pac)) || (result['Description'].include?(pac))
110
+ end
111
+ count += 1
112
+ puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] \
117
113
  #{color(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
118
- end
119
114
  end
120
115
  end
121
116
  end
122
- # Join the threads after searching is finished
123
- threads.each { |t| t.join }
117
+ end
118
+ # Join the threads after searching is finished
119
+ threads.each { |t| t.join }
124
120
 
125
- puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
121
+ puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
126
122
  #{count == 1 ? 'result' : 'results'}"
127
- end
123
+ end
128
124
 
129
- # Checks the aur for upgrades to local packages that were not found in any
130
- # official repository.
131
- def check_upgrade
132
- count, upgradable = 0, []
133
- `pacman -Qm`.each_line do |line|
134
- # Pacman -Qm output: name 1.1-1
135
- # Split them up in variables
136
- name, version = line.chomp.split
137
- result = json(@config.info % name)
138
- # Ensure that packages are on the aur before checking
139
- unless result['type'] == 'error'
140
- result = result['results']
141
- # Check if local version != remote version
142
- if (result.is_a?(Hash)) && (result['Version'] != version)
143
- # Make sure the remote version is newer
144
- if VersionNumber.new(result['Version']) > VersionNumber.new(version)
145
- count += 1
146
- # Insert the upgradable package's name into an array which we will
147
- # use later to prompt the download
148
- upgradable << name
149
- puts "#{color(name, :bold)} (#{color(version, :red)}) \
125
+ # Checks the aur for upgrades to local packages that were not found in any
126
+ # official repository.
127
+ def check_upgrade
128
+ count, upgradable = 0, []
129
+
130
+ `pacman -Qm`.each_line do |line|
131
+ # Pacman -Qm output: name 1.1-1
132
+ # Split them up in variables
133
+ name, version = line.chomp.split
134
+ result = json(@config.info % name)
135
+
136
+ # Ensure that packages are on the aur before checking
137
+ unless result['type'] == 'error'
138
+ result = result['results']
139
+
140
+ # Check if local version != remote version
141
+ if (result.is_a?(Hash)) && (result['Version'] != version)
142
+ # Make sure the remote version is newer
143
+ require 'facets/version'
144
+
145
+ if VersionNumber.new(result['Version']) > VersionNumber.new(version)
146
+ count += 1
147
+ # Insert the upgradable package's name into an array which we will
148
+ # use later to prompt the download
149
+ upgradable << name
150
+ puts "#{color(name, :bold)} (#{color(version, :red)}) \
150
151
  can be upgraded to #{color(result['Version'], :green)}"
151
- end
152
- else
153
- puts "#{color(name, :bold)} (#{color(version, :green)}) is up to date"
154
152
  end
153
+ else
154
+ puts "#{color(name, :bold)} (#{color(version, :green)}) is up to date"
155
155
  end
156
156
  end
157
+ end
157
158
 
158
- puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
159
+ puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} \
159
160
  #{count == 1 ? 'upgrade' : 'upgrades'}"
160
- unless upgradable.empty?
161
- # Prompt asking to download the upgrades
162
- upgradable.each do |pkg|
163
- print "#{color('==>', :yellow)} Download '#{pkg}'? [y] "
164
- $stdin.gets.chomp =~ /^y/ ? download(pkg) : next
165
- end
161
+
162
+ unless upgradable.empty?
163
+ # Prompt asking to download the upgrades
164
+ upgradable.each do |pkg|
165
+ print "#{color('==>', :yellow)} Download '#{pkg}'? [y] "
166
+ $stdin.gets.chomp =~ /^y/ ? download(pkg) : next
166
167
  end
167
168
  end
169
+ end
170
+
171
+ private
172
+ # Checks if a package exists in the community repository
173
+ #
174
+ # in_sync?('awesome-git')
175
+ #
176
+ def in_sync? package
177
+ !!Dir["#{@config.sync}/#{package}-*"].first
178
+ end
179
+
180
+ # Returns a list of packages found by a search
181
+ #
182
+ # list('awesome-git')
183
+ #
184
+ def list package
185
+ require 'cgi'
186
+
187
+ info, list = json(@config.search % CGI::escape(package)), []
168
188
 
169
- private
170
- # Checks if a package exists in the community repository
171
- #
172
- # in_sync?('awesome-git')
173
- #
174
- def in_sync?(package)
175
- Dir["#{@config.sync}/#{package}-*"].first ? true : false
189
+ if info['type'] == 'error'
190
+ raise AurbError, "#{color('Fatal', :on_red)}: no results"
176
191
  end
177
192
 
178
- # Returns a list of packages found by a search
179
- #
180
- # list('awesome-git')
181
- #
182
- def list(package)
183
- info, list = json(@config.search % CGI::escape(package)), []
184
- if info['type'] == 'error'
185
- raise AurbError, "#{color('Fatal', :on_red)}: no results"
186
- end
187
- for result in info['results'] do
188
- list << [result['Name'], result['ID']]
189
- end
190
- list.sort unless list.empty?
193
+ info['results'].each do |result|
194
+ list << [result['Name'], result['ID']]
191
195
  end
192
196
 
193
- # Downloads given +package+ into +dir+
194
- #
195
- # fetch('awesome-git', $0.dirname)
196
- #
197
- def fetch(package, dir)
198
- open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
199
- File.open("#{dir}/#{package}.tar.gz", 'wb') do |local|
200
- local.write(remote.read)
201
- end
197
+ list.empty ? nil : list.sort
198
+ end
199
+
200
+ # Downloads given +package+ into +dir+
201
+ #
202
+ # fetch('awesome-git', $0.dirname)
203
+ #
204
+ def fetch package, dir
205
+ open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
206
+ File.open("#{dir}/#{package}.tar.gz", 'wb') do |local|
207
+ local.write(remote.read)
202
208
  end
203
209
  end
210
+ end
204
211
 
205
- # Untars +package+
206
- #
207
- # untar('awesome-git') #=> .tar.gz is automagically appended
208
- #
209
- def untar(package)
210
- Archive::Tar::Minitar.unpack(
211
- Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
212
- Dir.pwd
213
- )
214
- end
212
+ # Untars +package+
213
+ #
214
+ # untar('awesome-git') #=> .tar.gz is automagically appended
215
+ #
216
+ def untar package
217
+ require 'facets/minitar'
218
+ require 'zlib'
215
219
 
216
- # Shortcut to parsing json
217
- #
218
- # json('http://foo.bar')
219
- #
220
- def json(item)
221
- JSON.parse(open(item).read)
222
- end
220
+ Archive::Tar::Minitar.unpack(
221
+ Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
222
+ Dir.pwd
223
+ )
223
224
  end
224
225
 
225
- class Opts < Hash
226
- def initialize(args = ARGV)
227
- @@args = args.empty? ? ['-h'] : args
226
+ # Shortcut to parsing json
227
+ #
228
+ # json('http://foo.bar')
229
+ #
230
+ def json item
231
+ require 'json'
232
+ require 'open-uri'
228
233
 
229
- # Invoke this class's only private method
230
- parse
231
- end
234
+ JSON.parse(open(item).read)
235
+ end
236
+ end
232
237
 
233
- private
234
- def parse
235
- OptionParser.new do |o|
236
- o.version = Version.join('.')
237
- o.program_name = 'Aurb'
238
- o.release = '2009-04-12'
238
+ class Opts < Hash
239
+ def initialize(args = ARGV)
240
+ @@args = args.empty? ? ['-h'] : args
241
+ parse
242
+ end
239
243
 
240
- o.on('-D', '--download P1,P2,...', Array, "Download package(s). \
241
- Separate by commas if multiple (no spaces).") do |d|
242
- self[:cmd] = "download('#{d*"', '"}')"
243
- end
244
- o.on('-S', '--search PKG', 'Search for a package.') do |s|
245
- self[:cmd] = "search('#{s}')"
246
- end
247
- o.on('-U', '--upgrade', 'Check for upgrades.') do
248
- self[:cmd] = 'check_upgrade'
249
- end
250
- end.parse!(@@args)
251
- end
244
+ private
245
+ def parse
246
+ require 'optparse'
247
+
248
+ OptionParser.new do |o|
249
+ o.version = [0, 5, 6].join('.')
250
+ o.program_name = 'Aurb'
251
+ o.release = '2009-04-13'
252
+
253
+ o.on('-D', '--download P1,P2,...', Array, "Download package(s).") do |d|
254
+ self[:cmd] = "download('#{d*"', '"}')"
255
+ end
256
+ o.on('-S', '--search PKG', 'Search for a package.') do |s|
257
+ self[:cmd] = "search('#{s}')"
258
+ end
259
+ o.on('-U', '--upgrade', 'Check the AUR for upgrades.') do
260
+ self[:cmd] = 'check_upgrade'
261
+ end
262
+ end.parse!(@@args)
252
263
  end
253
264
  end
265
+ end
254
266
 
255
267
  at_exit do
256
- if __FILE__ == $0
257
- raise $! if $!
258
- Aurb.aur.start
259
- end
268
+ if __FILE__ == $0
269
+ raise $! if $!
270
+ Aurb.aur.start
271
+ end
272
+
260
273
  end
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.5
4
+ version: 0.5.6
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 00:00:00 -07:00
12
+ date: 2009-04-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency