gigamo-aurb 0.6.2 → 0.6.3

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 +4 -3
  2. data/bin/aurb +128 -203
  3. metadata +12 -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.6.2'
4
- s.date = %q{2009-04-19}
3
+ s.version = '0.6.3'
4
+ s.date = %q{2009-04-23}
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}
@@ -9,9 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.rubyforge_project = %q{aurb}
10
10
  s.executables = ['aurb']
11
11
  s.has_rdoc = true
12
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Aurb", "--main", "README"]
12
+ s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'Aurb', '--main', 'README']
13
13
  s.authors = ['Gigamo']
14
14
  s.files = ['bin/aurb', 'aurb.gemspec', 'README']
15
15
  s.add_dependency 'json'
16
16
  s.add_dependency 'facets'
17
+ s.add_dependency 'highline'
17
18
  end
data/bin/aurb CHANGED
@@ -1,268 +1,193 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Author:: Gigamo <gigamo@gmail.com>
3
- # License:: GPL
3
+ # License:: Do whatever you want
4
4
  #
5
-
6
- require 'rubygems'
7
- require 'open-uri'
5
+ %w[optparse pathname fileutils zlib open-uri rubygems cgi json highline/import
6
+ facets/ansicode facets/minitar facets/version].each { |lib| require lib }
8
7
 
9
8
  module Aurb
10
9
 
11
- DlPath = File.join File.expand_path('~'), 'abs' # Change me!
12
- Config = Struct.new :search, :info, :dir # Don't change me!
10
+ # Path where PKGBUILDS will get saved to
11
+ DlPath = File.join File.expand_path('~'), 'abs'
13
12
 
14
- def self.aur
15
- @aur ||= Aur.new
16
- end
13
+ # Program Info
14
+ PrInfo = {:name => 'Aurb', :version => [0, 6, 3].join('.'), :release => '2009-04-23'}
15
+
16
+ def self.aur
17
+ @aur ||= Aur.new \
18
+ :search => proc {|t| "http://aur.archlinux.org/rpc.php?type=search&arg=#{t}"},
19
+ :info => proc {|t| "http://aur.archlinux.org/rpc.php?type=info&arg=#{t}"},
20
+ :path => Pathname.new(DlPath).realpath
21
+ end
17
22
 
18
- module Util
19
- # Colorize a string
20
- #
21
- # ansi('Text', :green)
22
- #
23
- # For a full list of available effects, see
24
- # http://facets.rubyforge.org/doc/api/more/classes/ANSICode.html
25
- #
26
- def ansi text, effect
27
- require 'facets/ansicode' unless defined? ANSICode
28
-
29
- if @opts[:color]
30
- ANSICode.send(effect.to_sym) << text << ANSICode.clear
31
- else
23
+ module Util
24
+ def ansi text, effect
25
+ text = ANSICode.send(effect.to_sym) << text << ANSICode.clear if @opts.color
32
26
  text
33
27
  end
34
28
  end
35
- module_function :ansi
36
- end
37
29
 
38
- class Aur
39
- include Aurb::Util
30
+ class Aur
31
+ include Aurb::Util
40
32
 
41
- def initialize
42
- require 'pathname'
33
+ def initialize config = {}
34
+ @config = config
35
+ @opts = Opts.new
36
+ end
43
37
 
44
- @config = Config.new(
45
- 'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
46
- 'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
47
- Pathname.new(DlPath).realpath
48
- )
49
- @opts = Opts.new
50
- end
38
+ def start
39
+ trap :INT do
40
+ puts "\nInterrupt signal received\n\n"
41
+ exit 0
42
+ end
51
43
 
52
- def start
53
- trap :INT do
54
- puts "\nInterrupt signal received\n\n"
55
- exit 0 # Exit peacefully on *INT
44
+ instance_eval @opts.cmd
56
45
  end
57
46
 
58
- # Evaluate a command in string form
59
- #
60
- # instance_eval('search("package")')
61
- #
62
- instance_eval @opts[:cmd]
63
- end
47
+ def download *packages
48
+ packages = packages.first if packages.first.is_a? Array
49
+
50
+ puts "Targets (#{ansi "#{packages.length}", :magenta}): #{packages.join(', ')}"
51
+ answer = ask("Proceed? [Y/n] ") {|q| q.readline = true; q.default = 'y'}
64
52
 
65
- # Downloads +packages+
66
- #
67
- # download('awesome-git', 'aurb')
68
- #
69
- def download *packages
70
- require 'readline'
71
-
72
- packages = packages[0] if packages[0].is_a? Array
73
-
74
- puts "Targets (#{packages.length}): #{packages.join(', ')}"
75
- answer = Readline::readline "Proceed? [y/n] "
76
-
77
- if answer =~ /^y|yes$/i
78
- packages.each do |package|
79
- list(package).each do |names|
80
- if names[0] == package
81
- if in_sync? package
82
- puts ":: Found #{package} in community. Use pacman!"
83
- else
84
- Dir.chdir(@config.dir) do
53
+ if answer =~ /^y|yes$/i
54
+ packages.each do |package|
55
+ list(package).each do |names|
56
+ if names.first == package
57
+ FileUtils.cd @config[:path] do
85
58
  fetch package
86
59
  untar package
87
-
88
- puts "(#{packages.index(package)+1}/#{packages.length}) downloaded #{package}"
89
60
  end
61
+ puts <<DOWNLOAD
62
+ (#{ansi "#{packages.index(package) + 1}", :green}/#{ansi "#{packages.length}", :green}) \
63
+ #{in_sync?(package) ? "did NOT download #{package}" : "downloaded #{package}"}
64
+ DOWNLOAD
90
65
  end
91
66
  end
92
67
  end
93
68
  end
94
69
  end
95
- end
96
-
97
- # Searches for +package+
98
- #
99
- # search('awesome')
100
- #
101
- def search package
102
- count, threads = 0, []
103
-
104
- list(package).each do |names|
105
- result = json(@config.info % names[1])
106
-
107
- unless result['type'] == 'error'
108
- result = result['results']
109
70
 
110
- next if in_sync? result['Name']
71
+ def search package
72
+ list(package).each do |names|
73
+ result = json(@config[:info][names.last])
111
74
 
112
- if package.any? do |pac| # Check both name and description for matches
113
- (result['Name'].include? pac) || (result['Description'].include? pac)
114
- end
115
- count += 1
75
+ unless result['type'] == 'error'
76
+ result = result['results']
77
+ next if in_sync? result['Name']
116
78
 
117
- puts "[#{result['OutOfDate'] == '1' ? ansi('✘', :red) : ansi('✔', :green)}] \
118
- #{ansi result['Name'], :blue} (#{result['Version']}): #{result['Description']}"
79
+ if package.any? do |pac| # Check both name and description for matches
80
+ result['Name'].include?(pac) || result['Description'].include?(pac)
81
+ end
82
+ puts <<SEARCH
83
+ [#{result['OutOfDate'] == '1' ? ansi('✘', :red) : ansi('✔', :green)}] \
84
+ #{ansi result['Name'], :blue} (#{result['Version']}): #{result['Description']}
85
+ SEARCH
86
+ end
119
87
  end
120
88
  end
121
89
  end
122
- end
123
90
 
124
- # Checks the aur for upgrades to local packages that were not found in any
125
- # official repository.
126
- #
127
- def check_upgrade
128
- upgradable = []
91
+ def check_upgrade
92
+ raise 'Pacman binary not found' if `which pacman`.strip == ''
93
+ upgradable = []
129
94
 
130
- puts ":: Searching for upgrades. This may take a while..."
95
+ puts 'Searching for updates'
96
+ `pacman -Qm`.each_line do |line|
97
+ name, version = line.chomp.split
98
+ result = json(@config[:info][name])
131
99
 
132
- `pacman -Qm`.each_line do |line|
133
- name, version = line.chomp.split
134
- result = json(@config.info % name)
135
-
136
- unless result['type'] == 'error'
137
- result = result['results']
138
-
139
- next if in_sync? result['Name']
140
-
141
- if (result.is_a? Hash) && (result['Version'] != version)
142
- require 'facets/version'
100
+ unless result['type'] == 'error'
101
+ result = result['results']
102
+ next if in_sync? result['Name']
143
103
 
144
104
  if VersionNumber.new(result['Version']) > VersionNumber.new(version)
145
- upgradable << name
146
-
147
- puts " #{name}: #{ansi version, :red} => #{ansi result['Version'], :green}"
105
+ upgradable << result['Name']
106
+ puts <<UPDATE
107
+ #{result['Name']}: #{ansi version, :red} => #{ansi result['Version'], :green}
108
+ UPDATE
148
109
  end
149
110
  end
150
111
  end
151
- end
152
-
153
- upgradable.empty? ? puts(':: Everything up to date') : download(upgradable)
154
- end
155
112
 
156
- private
157
- # Checks if a package exists in the community repository
158
- #
159
- # in_sync?('awesome-git')
160
- #
161
- def in_sync? package
162
- !!Dir["/var/lib/pacman/sync/community/#{package}-*"][0]
163
- end
113
+ upgradable.empty? ? puts('Nothing to update') : download(upgradable)
114
+ end
164
115
 
165
- # Returns a list of packages found by a search
166
- #
167
- # list('awesome-git')
168
- #
169
- def list package
170
- require 'cgi'
116
+ private
117
+ def in_sync? package
118
+ !!Dir["/var/lib/pacman/sync/community/#{package}-*"].first
119
+ end
171
120
 
172
- info, list = json(@config.search % CGI::escape(package)), []
121
+ def list package
122
+ info, list = json(@config[:search][CGI::escape(package)]), []
173
123
 
174
- unless info['type'] == 'error'
175
- info['results'].each do |result|
176
- list << [result['Name'], result['ID']]
124
+ unless info['type'] == 'error'
125
+ info['results'].each do |result|
126
+ list << [result['Name'], result['ID']]
127
+ end
177
128
  end
178
- end
179
129
 
180
- list.sort
181
- end
130
+ list.sort
131
+ end
182
132
 
183
- # Downloads given +package+ into +dir+
184
- #
185
- # fetch('awesome-git', $0.dirname)
186
- #
187
- def fetch package
188
- File.delete "#{package}.tar.gz" if File.exists? "#{package}.tar.gz"
133
+ def fetch package
134
+ FileUtils.rm "#{package}.tar.gz" if File.exists? "#{package}.tar.gz"
189
135
 
190
- open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
191
- File.open("#{package}.tar.gz", 'wb') do |local|
192
- local.write(remote.read)
136
+ open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
137
+ File.open("#{package}.tar.gz", 'wb') do |local|
138
+ local.write remote.read
139
+ end
193
140
  end
194
141
  end
195
- end
196
-
197
- # Untars +package+
198
- #
199
- # untar('awesome-git') #=> .tar.gz is automagically appended
200
- #
201
- def untar package
202
- require 'facets/minitar'
203
- require 'zlib'
204
- require 'fileutils'
205
142
 
206
- FileUtils.rm_r package if File.directory? package
207
-
208
- Archive::Tar::Minitar.unpack(
209
- Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')), Dir.pwd
210
- )
211
- end
143
+ def untar package
144
+ FileUtils.rm_r package if File.directory? package
212
145
 
213
- # Shortcut to parsing json
214
- #
215
- # json('http://foo.bar')
216
- #
217
- def json item
218
- require 'json' unless defined? JSON
219
-
220
- JSON.parse(open(item).read)
221
- end
222
- end
146
+ Archive::Tar::Minitar.unpack \
147
+ Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
148
+ Dir.pwd
149
+ end
223
150
 
224
- class Opts < Hash
225
- def initialize
226
- @@args = ARGV.empty? ? ['-h'] : ARGV
227
- parse
151
+ def json item
152
+ JSON.parse(open(item).read)
153
+ end
228
154
  end
229
155
 
230
- private
231
- def parse
232
- require 'optparse'
233
-
234
- self[:color] = true
235
-
236
- OptionParser.new do |o|
237
- o.version = [0, 6, 2].join('.')
238
- o.program_name = 'Aurb'
239
- o.release = '2009-04-19'
156
+ class Opts
157
+ attr_reader :cmd, :color
240
158
 
241
- o.separator 'Actions:'
159
+ def initialize
160
+ @@args = ARGV.empty? ? ['-h'] : ARGV
161
+ @color = true
242
162
 
243
- o.on '-D', '--download P1,P2,...', Array, "Download package(s)." do |d|
244
- self[:cmd] = "download('#{d*"', '"}')"
245
- end
246
-
247
- o.on '-S', '--search PKG', 'Search for a package.' do |s|
248
- self[:cmd] = "search('#{s}')"
249
- end
250
-
251
- o.on '-U', '--upgrade', 'Check the AUR for upgrades.' do
252
- self[:cmd] = 'check_upgrade'
253
- end
163
+ parse!
164
+ end
254
165
 
255
- o.separator 'Optional:'
166
+ private
167
+ def parse!
168
+ OptionParser.new do |o|
169
+ o.program_name, o.version, o.release = \
170
+ [:name, :version, :release].map {|key| PrInfo[key]}
256
171
 
257
- o.on '-C', '--[no-]color', 'Toggle colored output' do |c|
258
- self[:color] = c
259
- end
260
- end.parse! @@args
172
+ o.separator 'Actions (Required):'
173
+ o.on '-D', '--download P1,P2,...', Array, 'download package(s)' do |d|
174
+ @cmd = "download('#{d*"', '"}')"
175
+ end
176
+ o.on '-S', '--search PKG', 'search for a package' do |s|
177
+ @cmd = "search('#{s}')"
178
+ end
179
+ o.on '-U', '--upgrade', 'check the AUR for upgrades' do
180
+ @cmd = 'check_upgrade'
181
+ end
182
+ o.separator 'Optional:'
183
+ o.on '--[no-]color', "use colors? [#{@color ? 'yes' : 'no'}]" do |c|
184
+ @color = c
185
+ end
186
+ end.parse! @@args
187
+ end
261
188
  end
262
189
  end
263
190
 
264
- end
265
-
266
191
  at_exit do
267
192
  if __FILE__ == $0
268
193
  raise $! if $!
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.6.2
4
+ version: 0.6.3
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-19 00:00:00 -07:00
12
+ date: 2009-04-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: highline
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
35
45
  description: A simple AUR utility
36
46
  email: gigamo@gmail.com
37
47
  executables: