gigamo-aurb 0.5.8 → 0.6.1

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 +45 -48
  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.8'
4
- s.date = %q{2009-04-15}
3
+ s.version = '0.6.1'
4
+ s.date = %q{2009-04-19}
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,11 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
- require 'open-uri'
2
+ # Author:: Gigamo <gigamo@gmail.com>
3
+ # License:: GPL
4
+ #
5
+
3
6
  require 'rubygems'
7
+ require 'open-uri'
4
8
 
5
9
  module Aurb
6
10
 
7
- DlPath = File.join(File.expand_path('~'), 'abs') # Change me!
8
- Config = Struct.new :search, :info, :sync, :dir # Don't change me!
11
+ DlPath = File.join File.expand_path('~'), 'abs' # Change me!
12
+ Config = Struct.new :search, :info, :dir # Don't change me!
9
13
 
10
14
  def self.aur
11
15
  @aur ||= Aur.new
@@ -18,15 +22,15 @@ module Util
18
22
  #
19
23
  # For a full list of available effects, see
20
24
  # http://facets.rubyforge.org/doc/api/more/classes/ANSICode.html
25
+ #
21
26
  def ansi text, effect
22
27
  require 'facets/ansicode' unless defined? ANSICode
23
28
 
24
29
  ANSICode.send(effect.to_sym) << text << ANSICode.clear
25
30
  end
31
+ module_function :ansi
26
32
  end
27
33
 
28
- class AurbError < Exception; end
29
-
30
34
  class Aur
31
35
  include Aurb::Util
32
36
 
@@ -36,22 +40,22 @@ class Aur
36
40
  @config = Config.new(
37
41
  'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
38
42
  'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
39
- '/var/lib/pacman/sync/community',
40
43
  Pathname.new(DlPath).realpath
41
44
  )
42
- @opts = Opts.new(ARGV)
45
+ @opts = Opts.new
43
46
  end
44
47
 
45
48
  def start
46
- trap(:INT) { exit 0 } # Exit peacefully on *INT
49
+ trap :INT do
50
+ puts "\nInterrupt signal received\n\n"
51
+ exit 0 # Exit peacefully on *INT
52
+ end
47
53
 
48
54
  # Evaluate a command in string form
49
- # Example: instance_eval('search("package")')
50
- # Which will invoke the search method
55
+ #
56
+ # instance_eval('search("package")')
57
+ #
51
58
  instance_eval @opts[:cmd]
52
- rescue AurbError => e
53
- $stderr.puts e.message
54
- exit 1
55
59
  end
56
60
 
57
61
  # Downloads +packages+
@@ -59,15 +63,17 @@ class Aur
59
63
  # download('awesome-git', 'aurb')
60
64
  #
61
65
  def download *packages
66
+ packages = packages[0] if packages[0].is_a? Array
62
67
  packages.each do |package|
63
68
  list(package).each do |names|
64
- if names.first == package
69
+ if names[0] == package
65
70
  if in_sync? package
66
- puts "#{ansi('==>', :yellow)} Found #{package} in community. Use pacman!"
71
+ puts ":: Found #{package} in community. Use pacman!"
67
72
  else
68
73
  Dir.chdir(@config.dir) do
69
74
  fetch package
70
75
  untar package
76
+ puts " (#{packages.index(package)+1}/#{packages.length}) Downloaded #{package}"
71
77
  end
72
78
  end
73
79
  end
@@ -91,12 +97,12 @@ class Aur
91
97
  next if in_sync? result['Name']
92
98
 
93
99
  if package.any? do |pac| # Check both name and description for matches
94
- (result['Name'].include?(pac)) || (result['Description'].include?(pac))
100
+ (result['Name'].include? pac) || (result['Description'].include? pac)
95
101
  end
96
102
  count += 1
97
103
 
98
104
  puts "[#{result['OutOfDate'] == '1' ? ansi('✘', :red) : ansi('✔', :green)}] \
99
- #{ansi(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
105
+ #{ansi result['Name'], :blue} (#{result['Version']}): #{result['Description']}"
100
106
  end
101
107
  end
102
108
  end
@@ -106,9 +112,10 @@ class Aur
106
112
  # official repository.
107
113
  #
108
114
  def check_upgrade
109
- count, upgradable = 0, []
115
+ upgradable = []
116
+
117
+ puts ":: Searching for upgrades. This may take a while..."
110
118
 
111
- puts "#{ansi('==>', :yellow)} Searching for upgrades. This may take a while..."
112
119
  `pacman -Qm`.each_line do |line|
113
120
  name, version = line.chomp.split
114
121
  result = json(@config.info % name)
@@ -118,30 +125,27 @@ class Aur
118
125
 
119
126
  next if in_sync? result['Name']
120
127
 
121
- if (result.is_a?(Hash)) && (result['Version'] != version)
128
+ if (result.is_a? Hash) && (result['Version'] != version)
122
129
  require 'facets/version'
123
130
 
124
131
  if VersionNumber.new(result['Version']) > VersionNumber.new(version)
125
- count += 1
126
132
  upgradable << name
127
133
 
128
- puts "#{ansi(name, :bold)} #{ansi(version, :red)} -> \
129
- #{ansi(result['Version'], :green)}"
134
+ puts " #{name}: #{ansi version, :red} => #{ansi result['Version'], :green}"
130
135
  end
131
136
  end
132
137
  end
133
138
  end
134
139
 
135
- if upgradable.empty? && count == 0
136
- puts "#{ansi('==>', :yellow)} Everything is up to date"
140
+ if upgradable.empty?
141
+ puts ":: Everything is up to date"
137
142
  else
138
143
  require 'readline'
139
144
 
140
- puts "#{ansi('==>', :yellow)} Targets (#{count}): #{upgradable.join(', ')}"
141
-
142
- upgradable.each do |pkg|
143
- answer = Readline::readline("#{ansi('==>', :yellow)} Download #{pkg}? ")
144
- answer =~ /^y|yes$/i ? download(pkg) : next
145
+ puts ":: Targets (#{upgradable.length}): #{upgradable.join(', ')}"
146
+ answer = Readline::readline "Proceed by downloading these packages? [y/n] "
147
+ if answer =~ /^y|yes$/i
148
+ download upgradable
145
149
  end
146
150
  end
147
151
  end
@@ -152,7 +156,7 @@ private
152
156
  # in_sync?('awesome-git')
153
157
  #
154
158
  def in_sync? package
155
- !!Dir["#{@config.sync}/#{package}-*"].first
159
+ !!Dir["/var/lib/pacman/sync/community/#{package}-*"][0]
156
160
  end
157
161
 
158
162
  # Returns a list of packages found by a search
@@ -178,15 +182,13 @@ private
178
182
  # fetch('awesome-git', $0.dirname)
179
183
  #
180
184
  def fetch package
181
- File.delete("#{package}.tar.gz") if File.exists?("#{package}.tar.gz")
185
+ File.delete "#{package}.tar.gz" if File.exists? "#{package}.tar.gz"
182
186
 
183
187
  open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
184
188
  File.open("#{package}.tar.gz", 'wb') do |local|
185
189
  local.write(remote.read)
186
190
  end
187
191
  end
188
-
189
- puts "#{ansi('==>', :yellow)} Fetched #{package}.tar.gz"
190
192
  end
191
193
 
192
194
  # Untars +package+
@@ -198,13 +200,11 @@ private
198
200
  require 'zlib'
199
201
  require 'fileutils'
200
202
 
201
- FileUtils.rm_r(package) if File.directory?(package)
203
+ FileUtils.rm_r package if File.directory? package
202
204
 
203
205
  Archive::Tar::Minitar.unpack(
204
206
  Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')), Dir.pwd
205
207
  )
206
-
207
- puts "#{ansi('==>', :yellow)} Untarred #{package}.tar.gz"
208
208
  end
209
209
 
210
210
  # Shortcut to parsing json
@@ -212,15 +212,15 @@ private
212
212
  # json('http://foo.bar')
213
213
  #
214
214
  def json item
215
- require 'json'
215
+ require 'json' unless defined? JSON
216
216
 
217
217
  JSON.parse(open(item).read)
218
218
  end
219
219
  end
220
220
 
221
221
  class Opts < Hash
222
- def initialize(args = ARGV)
223
- @@args = args.empty? ? ['-h'] : args
222
+ def initialize
223
+ @@args = ARGV.empty? ? ['-h'] : ARGV
224
224
  parse
225
225
  end
226
226
 
@@ -229,19 +229,19 @@ private
229
229
  require 'optparse'
230
230
 
231
231
  OptionParser.new do |o|
232
- o.version = [0, 5, 8].join('.')
232
+ o.version = [0, 6, 1].join('.')
233
233
  o.program_name = 'Aurb'
234
- o.release = '2009-04-15'
234
+ o.release = '2009-04-19'
235
235
 
236
- o.on('-D', '--download P1,P2,...', Array, "Download package(s).") do |d|
236
+ o.on '-D', '--download P1,P2,...', Array, "Download package(s)." do |d|
237
237
  self[:cmd] = "download('#{d*"', '"}')"
238
238
  end
239
239
 
240
- o.on('-S', '--search PKG', 'Search for a package.') do |s|
240
+ o.on '-S', '--search PKG', 'Search for a package.' do |s|
241
241
  self[:cmd] = "search('#{s}')"
242
242
  end
243
243
 
244
- o.on('-U', '--upgrade', 'Check the AUR for upgrades.') do
244
+ o.on '-U', '--upgrade', 'Check the AUR for upgrades.' do
245
245
  self[:cmd] = 'check_upgrade'
246
246
  end
247
247
  end.parse! @@args
@@ -254,8 +254,5 @@ at_exit do
254
254
  if __FILE__ == $0
255
255
  raise $! if $!
256
256
  Aurb.aur.start
257
- else
258
- $stderr.puts 'Please only run me by myself. Thanks.'
259
- exit 1
260
257
  end
261
258
  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.8
4
+ version: 0.6.1
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-15 00:00:00 -07:00
12
+ date: 2009-04-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency