gigamo-aurb 0.5.2 → 0.5.4
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/README +11 -1
- data/aurb.gemspec +11 -8
- data/bin/aurb +83 -68
- metadata +33 -9
data/README
CHANGED
data/aurb.gemspec
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'aurb'
|
3
|
-
s.version = '0.5.
|
4
|
-
s.date =
|
5
|
-
s.summary =
|
6
|
-
s.email =
|
7
|
-
s.homepage =
|
3
|
+
s.version = '0.5.4'
|
4
|
+
s.date = %q{2009-04-10}
|
5
|
+
s.summary = %q{A simple AUR utility}
|
6
|
+
s.email = %q{gigamo@gmail.com}
|
7
|
+
s.homepage = %q{http://github.com/gigamo/aurb}
|
8
8
|
s.description = s.summary
|
9
|
-
s.rubyforge_project =
|
10
|
-
s.
|
9
|
+
s.rubyforge_project = %q{aurb}
|
10
|
+
s.executables = ['aurb']
|
11
|
+
s.has_rdoc = true
|
12
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Aurb", "--main", "README"]
|
11
13
|
s.authors = ['Gigamo']
|
12
14
|
s.files = ['bin/aurb', 'aurb.gemspec', 'README']
|
13
|
-
s.
|
15
|
+
s.add_dependency 'json'
|
16
|
+
s.add_dependency 'facets'
|
14
17
|
end
|
data/bin/aurb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'facets/version'
|
6
|
-
require 'facets/ansicode'
|
7
|
-
require 'json'
|
8
|
-
require 'cgi'
|
9
|
-
require 'open-uri'
|
10
|
-
require 'optparse'
|
11
|
-
require 'pathname'
|
2
|
+
%w(optparse rubygems cgi json open-uri pathname zlib facets/ansicode facets/minitar facets/version).each do |lib|
|
3
|
+
require lib
|
4
|
+
end
|
12
5
|
|
13
6
|
module Aurb
|
14
|
-
Config
|
15
|
-
Version =
|
7
|
+
Config = Struct.new(:search, :info, :sync, :dir)
|
8
|
+
Version = [0, 5, 4]
|
9
|
+
# Change Me!
|
10
|
+
DlPath = File.join(File.expand_path('~'), 'abs') # => '/home/gig/abs' in my case
|
16
11
|
|
17
12
|
def self.aur
|
18
13
|
@aur ||= Aur.new
|
19
14
|
end
|
20
15
|
|
21
16
|
module Util
|
17
|
+
# Colorize a string
|
18
|
+
# Example: color('Text', :green)
|
22
19
|
def color(text, effect)
|
23
20
|
ANSICode.send(effect.to_sym) << text << ANSICode.clear
|
24
21
|
end
|
@@ -33,46 +30,41 @@ module Aurb
|
|
33
30
|
@config = Config.new(
|
34
31
|
'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
|
35
32
|
'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
|
36
|
-
'/var/lib/pacman/sync
|
37
|
-
|
38
|
-
Pathname.new(File.join(ENV['HOME'], 'abs')).realpath
|
33
|
+
'/var/lib/pacman/sync/community',
|
34
|
+
Pathname.new(DlPath).realpath
|
39
35
|
)
|
40
36
|
@opts = Opts.new(ARGV)
|
41
37
|
end
|
42
38
|
|
43
39
|
def start
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
40
|
+
# Exit peacefully on *INT
|
41
|
+
trap(:INT) { exit 0 }
|
42
|
+
# Evaluate a command in string form
|
43
|
+
# Example: instance_eval('search("package")')
|
44
|
+
# Which will invoke the search method
|
45
|
+
instance_eval(@opts[:cmd])
|
51
46
|
rescue AurbError => e
|
52
|
-
puts e.message
|
47
|
+
$stderr.puts e.message
|
53
48
|
exit 1
|
54
49
|
end
|
55
50
|
|
56
51
|
def download(*packages)
|
57
52
|
packages.each do |package|
|
58
|
-
puts "#{color('Warning', :on_yellow)}: directory for '#{package}' already exists" if File.exists? File.join(@config.dir, package)
|
59
53
|
list(package).each do |names|
|
60
54
|
if names.first == package
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
55
|
+
# Check if the package exists in the community repo
|
56
|
+
# Invoke pacman if so
|
57
|
+
if in_sync? package
|
58
|
+
puts "#{color('==>', :yellow)} Found #{package} in community repo. Pacman will do."
|
59
|
+
exec "sudo pacman -S #{package}"
|
60
|
+
else
|
61
|
+
# Else download and untar it from the AUR
|
62
|
+
Dir.chdir(@config.dir) do |dir|
|
63
|
+
fetch(package, dir)
|
64
|
+
puts "#{color('==>', :yellow)} Downloaded #{package}"
|
65
|
+
untar(package)
|
66
|
+
puts "#{color('==>', :yellow)} Unpacked #{package}"
|
72
67
|
end
|
73
|
-
|
74
|
-
puts "#{color('==>', :yellow)} Unpacking #{package}"
|
75
|
-
Archive::Tar::Minitar.unpack(Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')), Dir.pwd)
|
76
68
|
end
|
77
69
|
end
|
78
70
|
end
|
@@ -80,41 +72,50 @@ module Aurb
|
|
80
72
|
end
|
81
73
|
|
82
74
|
def search(package)
|
83
|
-
|
75
|
+
count, threads = 0, []
|
84
76
|
list(package).each do |names|
|
77
|
+
# Launch a separate thread for each packagename to be checked
|
78
|
+
# This is slooow otherwise, because it will have to wait for each result
|
79
|
+
# to be displayed before going on to the next one
|
85
80
|
threads << Thread.new do
|
86
|
-
result =
|
81
|
+
result = json(@config.info % names[1])
|
87
82
|
unless result['type'] == 'error'
|
88
83
|
result = result['results']
|
89
|
-
|
90
|
-
if
|
91
|
-
|
92
|
-
|
84
|
+
# Skip this iteration if the package is found in the community repo
|
85
|
+
next if in_sync? result['Name']
|
86
|
+
# Check both name and description for matches
|
87
|
+
if package.any? { |pac| (result['Name'].include?(pac)) || (result['Description'].include?(pac)) }
|
93
88
|
count += 1
|
94
89
|
puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] #{color(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
|
95
90
|
end
|
96
91
|
end
|
97
92
|
end
|
98
93
|
end
|
94
|
+
# Join the threads after searching is finished
|
99
95
|
threads.each { |t| t.join }
|
100
96
|
|
101
|
-
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} #{count == 1 ? 'result' : 'results'}"
|
97
|
+
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} #{count == 1 ? 'result' : 'results'}"
|
102
98
|
end
|
103
99
|
|
104
100
|
def check_upgrade
|
105
|
-
|
106
|
-
puts "#{color('==>', :yellow)} Checking for upgrades"
|
101
|
+
count, upgradable = 0, []
|
107
102
|
`pacman -Qm`.each_line do |line|
|
103
|
+
# Pacman -Qm output: name 1.1-1
|
104
|
+
# Split them up in variables
|
108
105
|
name, version = line.chomp.split
|
109
|
-
result =
|
106
|
+
result = json(@config.info % name)
|
107
|
+
# Ensure that packages are on the aur before checking
|
110
108
|
unless result['type'] == 'error'
|
111
109
|
result = result['results']
|
110
|
+
# Check if local version != remote version
|
112
111
|
if (result.is_a?(Hash)) && (result['Version'] != version)
|
112
|
+
# Make sure the remote version is newer
|
113
113
|
if VersionNumber.new(result['Version']) > VersionNumber.new(version)
|
114
|
-
|
114
|
+
count += 1
|
115
|
+
# Insert the upgradable package's name into an array which we will
|
116
|
+
# use later to prompt the download
|
117
|
+
upgradable << name
|
115
118
|
puts "#{color(name, :bold)} (#{color(version, :red)}) can be upgraded to #{color(result['Version'], :green)}"
|
116
|
-
upcount += 1
|
117
|
-
uppkgs << name
|
118
119
|
end
|
119
120
|
else
|
120
121
|
puts "#{color(name, :bold)} (#{color(version, :green)}) is up to date"
|
@@ -122,50 +123,64 @@ module Aurb
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} #{count == 1 ? 'upgrade' : 'upgrades'}"
|
127
|
+
unless upgradable.empty?
|
128
|
+
# Prompt asking to download the upgrades
|
129
|
+
upgradable.each do |pkg|
|
128
130
|
print "#{color('==>', :yellow)} Download '#{pkg}'? [y] "
|
129
131
|
$stdin.gets.chomp =~ /^y/ ? download(pkg) : next
|
130
132
|
end
|
131
|
-
else
|
132
|
-
puts "\n#{color('==>', :yellow)} All packages are up to date."
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
private
|
137
|
-
def in_sync?(package
|
138
|
-
|
139
|
-
true if Dir["#{repo}/#{package}-*"].first
|
137
|
+
def in_sync?(package)
|
138
|
+
Dir["#{@config.sync}/#{package}-*"].first ? true : false
|
140
139
|
end
|
141
140
|
|
142
141
|
def list(package)
|
143
|
-
info, list =
|
142
|
+
info, list = json(@config.search % CGI::escape(package)), []
|
144
143
|
if info['type'] == 'error'
|
145
144
|
raise AurbError, "#{color('Fatal', :on_red)}: no results"
|
146
145
|
end
|
147
146
|
for result in info['results'] do
|
148
147
|
list << [result['Name'], result['ID']]
|
149
148
|
end
|
150
|
-
|
151
149
|
list.sort unless list.empty?
|
152
150
|
end
|
151
|
+
|
152
|
+
def fetch(package, dir)
|
153
|
+
open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
|
154
|
+
File.open("#{dir}/#{package}.tar.gz", 'wb') do |local|
|
155
|
+
local.write(remote.read)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def untar(package)
|
161
|
+
Archive::Tar::Minitar.unpack(Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')), Dir.pwd)
|
162
|
+
end
|
163
|
+
|
164
|
+
def json(item)
|
165
|
+
JSON.parse(open(item).read)
|
166
|
+
end
|
153
167
|
end
|
154
168
|
|
155
169
|
class Opts < Hash
|
156
|
-
def initialize(args)
|
157
|
-
|
170
|
+
def initialize(args = ARGV)
|
171
|
+
@@args = args.empty? ? ['-h'] : args
|
172
|
+
parse
|
158
173
|
end
|
159
174
|
|
160
175
|
private
|
161
|
-
def parse
|
176
|
+
def parse
|
162
177
|
OptionParser.new do |o|
|
163
|
-
o.version = '
|
178
|
+
o.version = Version.join('.')
|
164
179
|
o.program_name = 'Aurb'
|
165
|
-
o.release = '2009-04-
|
180
|
+
o.release = '2009-04-10'
|
166
181
|
|
167
182
|
o.on('-D', '--download P1,P2,...', Array, 'Download package(s). Separate by commas if multiple (no spaces).') do |d|
|
168
|
-
self[:cmd] = "download('#{d*"', '"}')"
|
183
|
+
self[:cmd] = "download('#{d*"', '"}')"
|
169
184
|
end
|
170
185
|
o.on('-S', '--search PKG', 'Search for a package.') do |s|
|
171
186
|
self[:cmd] = "search('#{s}')"
|
@@ -173,7 +188,7 @@ module Aurb
|
|
173
188
|
o.on('-U', '--upgrade', 'Check for upgrades.') do
|
174
189
|
self[:cmd] = 'check_upgrade'
|
175
190
|
end
|
176
|
-
end.parse!(args)
|
191
|
+
end.parse!(@@args)
|
177
192
|
end
|
178
193
|
end
|
179
194
|
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.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gigamo
|
@@ -9,14 +9,33 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: facets
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
16
35
|
description: A simple AUR utility
|
17
36
|
email: gigamo@gmail.com
|
18
|
-
executables:
|
19
|
-
|
37
|
+
executables:
|
38
|
+
- aurb
|
20
39
|
extensions: []
|
21
40
|
|
22
41
|
extra_rdoc_files: []
|
@@ -25,11 +44,16 @@ files:
|
|
25
44
|
- bin/aurb
|
26
45
|
- aurb.gemspec
|
27
46
|
- README
|
28
|
-
has_rdoc:
|
47
|
+
has_rdoc: true
|
29
48
|
homepage: http://github.com/gigamo/aurb
|
30
49
|
post_install_message:
|
31
|
-
rdoc_options:
|
32
|
-
|
50
|
+
rdoc_options:
|
51
|
+
- --line-numbers
|
52
|
+
- --inline-source
|
53
|
+
- --title
|
54
|
+
- Aurb
|
55
|
+
- --main
|
56
|
+
- README
|
33
57
|
require_paths:
|
34
58
|
- lib
|
35
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|