gigamo-aurb 0.3.1 → 0.4.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.
- data/aurb.gemspec +2 -2
- data/bin/aurb +62 -52
- metadata +2 -2
data/aurb.gemspec
CHANGED
data/bin/aurb
CHANGED
@@ -6,16 +6,22 @@ end
|
|
6
6
|
|
7
7
|
module Aurb
|
8
8
|
Config = Struct.new(:search, :info, :sync, :dir)
|
9
|
-
Version = [0,
|
9
|
+
Version = [0, 4, 1]
|
10
10
|
|
11
11
|
def self.aur
|
12
12
|
@aur ||= Aur.new
|
13
13
|
end
|
14
14
|
|
15
|
+
module Util
|
16
|
+
def color(text, effect)
|
17
|
+
return ANSICode.send(effect) << text << ANSICode.clear
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
class AurbError < Exception; end
|
16
22
|
|
17
23
|
class Aur
|
18
|
-
|
24
|
+
include Aurb::Util
|
19
25
|
|
20
26
|
def initialize
|
21
27
|
@config = Config.new(
|
@@ -29,45 +35,46 @@ module Aurb
|
|
29
35
|
end
|
30
36
|
|
31
37
|
def start
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
raise AurbError, "#{color('Fatal', :on_red)}: no option given, see --help"
|
37
|
-
end
|
38
|
-
rescue AurbError => e
|
39
|
-
puts e.message
|
38
|
+
if @opts[:cmd]
|
39
|
+
instance_eval(@opts[:cmd])
|
40
|
+
else
|
41
|
+
raise AurbError, "#{color('Fatal', :on_red)}: no option given, see --help"
|
40
42
|
end
|
43
|
+
rescue AurbError => e
|
44
|
+
puts e.message
|
45
|
+
exit
|
41
46
|
end
|
42
47
|
|
43
|
-
def download(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
def download(*packages)
|
49
|
+
for package in packages do
|
50
|
+
unless File.exists? File.join(@config.dir, package)
|
51
|
+
for names in list(package) do
|
52
|
+
if names.first == package
|
53
|
+
Dir.chdir(@config.dir) do |dir|
|
54
|
+
if in_sync? package, 'community'
|
55
|
+
puts "#{color('==>', :yellow)} Found #{package} in community repo. Pacman will do."
|
56
|
+
# exec will automatically terminate the script
|
57
|
+
exec "sudo pacman -S #{package}"
|
58
|
+
else
|
59
|
+
puts "#{color('==>', :yellow)} Downloading #{package}."
|
60
|
+
open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
|
61
|
+
File.open("#{dir}/#{package}.tar.gz", 'wb') do |file|
|
62
|
+
file.write(remote.read)
|
63
|
+
end
|
57
64
|
end
|
58
65
|
end
|
59
|
-
end
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
puts "#{color('==>', :yellow)} Unpacking #{package}."
|
68
|
+
Archive::Tar::Minitar.unpack(
|
69
|
+
Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
|
70
|
+
Dir.pwd
|
71
|
+
)
|
72
|
+
end
|
66
73
|
end
|
67
74
|
end
|
75
|
+
else
|
76
|
+
raise AurbError, "#{color('Fatal', :on_red)}: directory already exists"
|
68
77
|
end
|
69
|
-
else
|
70
|
-
raise AurbError, "#{color('Fatal', :on_red)}: directory already exists"
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
@@ -93,38 +100,41 @@ module Aurb
|
|
93
100
|
end
|
94
101
|
threads.each { |t| t.join }
|
95
102
|
|
96
|
-
|
103
|
+
if count == 0
|
104
|
+
raise AurbError, "#{color('Fatal', :on_red)}: no results"
|
105
|
+
else
|
106
|
+
puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} #{count == 1 ? 'result' : 'results'}."
|
107
|
+
end
|
97
108
|
end
|
98
109
|
|
99
110
|
def check_upgrade
|
100
|
-
threads, found = [], false
|
111
|
+
threads, found, upcount = [], false, 0
|
101
112
|
puts "#{color('==>', :yellow)} Checking for upgrades."
|
102
|
-
|
103
113
|
`pacman -Qm`.each_line do |line|
|
104
114
|
threads << Thread.new do
|
105
115
|
name, version = line.chomp.split
|
106
116
|
result = JSON.parse(open(@config.info % name).read)
|
107
117
|
if result === Hash && result['Version'] != version
|
108
118
|
found = true
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if aver > iver
|
113
|
-
puts "#{color(name, :bold)}: #{color(version, :red)} -> #{color(result['Version'])}"
|
119
|
+
if VersionNumber.new(result['Version']) > VersionNumber.new(version)
|
120
|
+
puts "#{color(name, :bold)}: #{color(version, :red)} -> #{color(result['Version'], :green)}"
|
121
|
+
upcount += 1
|
114
122
|
end
|
123
|
+
else
|
124
|
+
puts "#{color(name, :bold)} is up to date"
|
115
125
|
end
|
116
126
|
end
|
117
127
|
end
|
118
128
|
threads.each { |t| t.join }
|
119
129
|
|
120
|
-
|
130
|
+
if found
|
131
|
+
puts "\n#{color('==>', :yellow)} Found #{color(upcount.to_s, :magenta)} #{upcount == 1 ? 'upgrade' : 'upgrades'}."
|
132
|
+
else
|
133
|
+
puts "\n#{color('==>', :yellow)} All packages are up to date."
|
134
|
+
end
|
121
135
|
end
|
122
136
|
|
123
137
|
private
|
124
|
-
def color(text, effect)
|
125
|
-
return ANSICode.send(effect) << text << ANSICode.clear
|
126
|
-
end
|
127
|
-
|
128
138
|
def in_sync?(package, repo)
|
129
139
|
repo = @config.sync % repo
|
130
140
|
return true if Dir["#{repo}/#{package}-*"].first
|
@@ -133,7 +143,7 @@ module Aurb
|
|
133
143
|
def list(package)
|
134
144
|
info, list = JSON.parse(open(@config.search % CGI::escape(package)).read), []
|
135
145
|
if info['type'] == 'error'
|
136
|
-
raise AurbError, "#{color('Fatal', :on_red)}:
|
146
|
+
raise AurbError, "#{color('Fatal', :on_red)}: no results"
|
137
147
|
end
|
138
148
|
for result in info['results'] do
|
139
149
|
list << [result['Name'], result['ID']]
|
@@ -153,15 +163,15 @@ module Aurb
|
|
153
163
|
OptionParser.new do |o|
|
154
164
|
o.version = Version*'.'
|
155
165
|
o.program_name = 'Aurb'
|
156
|
-
o.release = '2009-04-
|
166
|
+
o.release = '2009-04-06'
|
157
167
|
|
158
|
-
o.on('-D', '--download
|
159
|
-
self[:cmd] = "download('#{
|
168
|
+
o.on('-D', '--download P1,P2,...', Array, 'Download package(s). Separate by commas if multiple (no spaces).') do |d|
|
169
|
+
self[:cmd] = "download('#{d*'\', \''}')" # wow. ugly
|
160
170
|
end
|
161
|
-
o.on('-S', '--search
|
162
|
-
self[:cmd] = "search('#{
|
171
|
+
o.on('-S', '--search PKG', 'Search for a package.') do |s|
|
172
|
+
self[:cmd] = "search('#{s}')" % s
|
163
173
|
end
|
164
|
-
o.on('-U', '--upgrade', 'Check for upgrades') do
|
174
|
+
o.on('-U', '--upgrade', 'Check for upgrades.') do
|
165
175
|
self[:cmd] = 'check_upgrade'
|
166
176
|
end
|
167
177
|
end.parse!(args)
|
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.
|
4
|
+
version: 0.4.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-
|
12
|
+
date: 2009-04-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|