gigamo-aurb 0.4.1 → 0.5.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 +55 -57
  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.4.1'
4
- s.date = '2009-04-06'
3
+ s.version = '0.5.1'
4
+ s.date = '2009-04-07'
5
5
  s.summary = 'A simple AUR utility'
6
6
  s.email = 'gigamo@gmail.com'
7
7
  s.homepage = 'http://github.com/gigamo/aurb'
data/bin/aurb CHANGED
@@ -1,12 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
- libraries = %w[rubygems zlib facets/version facets/minitar facets/ansicode json cgi open-uri optparse]
3
- for library in libraries do
4
- require library
5
- end
2
+ require 'rubygems'
3
+ require 'zlib'
4
+ require 'facets/minitar'
5
+ require 'facets/version'
6
+ require 'facets/ansicode'
7
+ require 'json'
8
+ require 'cgi'
9
+ require 'open-uri'
10
+ require 'optparse'
11
+ require 'pathname'
6
12
 
7
13
  module Aurb
8
14
  Config = Struct.new(:search, :info, :sync, :dir)
9
- Version = [0, 4, 1]
15
+ Version = {:major => 0, :minor => 5, :tiny => 1}
10
16
 
11
17
  def self.aur
12
18
  @aur ||= Aur.new
@@ -14,7 +20,7 @@ module Aurb
14
20
 
15
21
  module Util
16
22
  def color(text, effect)
17
- return ANSICode.send(effect) << text << ANSICode.clear
23
+ ANSICode.send(effect.to_sym) << text << ANSICode.clear
18
24
  end
19
25
  end
20
26
 
@@ -29,12 +35,14 @@ module Aurb
29
35
  'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
30
36
  '/var/lib/pacman/sync/%s',
31
37
  # Change this to reflect your personal download path
32
- File.join(ENV['HOME'], 'abs')
38
+ Pathname.new(File.join(ENV['HOME'], 'abs')).realpath
33
39
  )
34
40
  @opts = Opts.new(ARGV)
35
41
  end
36
42
 
37
43
  def start
44
+ trap(:INT) { raise AurbError, 'Catched SIGINT' }
45
+
38
46
  if @opts[:cmd]
39
47
  instance_eval(@opts[:cmd])
40
48
  else
@@ -42,57 +50,49 @@ module Aurb
42
50
  end
43
51
  rescue AurbError => e
44
52
  puts e.message
45
- exit
53
+ exit 1
46
54
  end
47
55
 
48
56
  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
+ packages.each do |package|
58
+ puts "#{color('Warning', :on_yellow)}: directory for '#{package}' already exists" if File.exists? File.join(@config.dir, package)
59
+ list(package).each do |names|
60
+ if names.first == package
61
+ Dir.chdir(@config.dir) do |dir|
62
+ if in_sync? package, 'community'
63
+ puts "#{color('==>', :yellow)} Found #{package} in community repo. Pacman will do."
64
+ exec "sudo pacman -S #{package}"
65
+ else
66
+ puts "#{color('==>', :yellow)} Downloading #{package}."
67
+ open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
68
+ File.open("#{dir}/#{package}.tar.gz", 'wb') do |local|
69
+ local.write(remote.read)
64
70
  end
65
71
  end
66
-
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
72
  end
73
+
74
+ puts "#{color('==>', :yellow)} Unpacking #{package}."
75
+ Archive::Tar::Minitar.unpack(Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')), Dir.pwd)
73
76
  end
74
77
  end
75
- else
76
- raise AurbError, "#{color('Fatal', :on_red)}: directory already exists"
77
78
  end
78
79
  end
79
80
  end
80
81
 
81
82
  def search(package)
82
83
  threads, count = [], 0
83
- for name in list(package) do
84
+ list(package).each do |names|
84
85
  threads << Thread.new do
85
- result = JSON.parse(open(@config.info % name[1]).read)
86
+ result = JSON.parse(open(@config.info % names[1]).read)
86
87
  if result['type'] == 'error'
87
88
  raise AurbError, "#{color('Fatal', :on_red)}: no results"
88
89
  else
89
90
  result = result['results']
90
91
  next if in_sync? result['Name'], 'community'
91
92
  if package.any? do |pac|
92
- result['Name'].include? pac or result['Description'].include? pac
93
+ (result['Name'].include?(pac)) || (result['Description'].include?(pac))
93
94
  end
94
95
  count += 1
95
-
96
96
  puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] #{color(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
97
97
  end
98
98
  end
@@ -100,35 +100,33 @@ module Aurb
100
100
  end
101
101
  threads.each { |t| t.join }
102
102
 
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
103
+ puts "\n#{color('==>', :yellow)} Found #{color(count.to_s, :magenta)} #{count == 1 ? 'result' : 'results'}." if count > 0
108
104
  end
109
105
 
110
106
  def check_upgrade
111
- threads, found, upcount = [], false, 0
107
+ uppkgs, found, upcount = [], false, 0
112
108
  puts "#{color('==>', :yellow)} Checking for upgrades."
113
109
  `pacman -Qm`.each_line do |line|
114
- threads << Thread.new do
115
- name, version = line.chomp.split
116
- result = JSON.parse(open(@config.info % name).read)
117
- if result === Hash && result['Version'] != version
110
+ name, version = line.chomp.split
111
+ result = JSON.parse(open(@config.info % name).read)['results']
112
+ if (result.is_a?(Hash)) && (result['Version'] != version)
113
+ if VersionNumber.new(result['Version']) > VersionNumber.new(version)
118
114
  found = true
119
- if VersionNumber.new(result['Version']) > VersionNumber.new(version)
120
- puts "#{color(name, :bold)}: #{color(version, :red)} -> #{color(result['Version'], :green)}"
121
- upcount += 1
122
- end
123
- else
124
- puts "#{color(name, :bold)} is up to date"
115
+ puts "#{color(name, :bold)}: #{color(version, :red)} -> #{color(result['Version'], :green)}"
116
+ upcount += 1
117
+ uppkgs << name
125
118
  end
119
+ else
120
+ puts "#{color(name, :bold)} is up to date"
126
121
  end
127
122
  end
128
- threads.each { |t| t.join }
129
123
 
130
124
  if found
131
125
  puts "\n#{color('==>', :yellow)} Found #{color(upcount.to_s, :magenta)} #{upcount == 1 ? 'upgrade' : 'upgrades'}."
126
+ uppkgs.each do |pkg|
127
+ print "#{color('==>', :yellow)} Download '#{pkg}'? [y] "
128
+ $stdin.gets.chomp =~ /^y/ ? download(pkg) : next
129
+ end
132
130
  else
133
131
  puts "\n#{color('==>', :yellow)} All packages are up to date."
134
132
  end
@@ -137,7 +135,7 @@ module Aurb
137
135
  private
138
136
  def in_sync?(package, repo)
139
137
  repo = @config.sync % repo
140
- return true if Dir["#{repo}/#{package}-*"].first
138
+ true if Dir["#{repo}/#{package}-*"].first
141
139
  end
142
140
 
143
141
  def list(package)
@@ -149,7 +147,7 @@ module Aurb
149
147
  list << [result['Name'], result['ID']]
150
148
  end
151
149
 
152
- return list.sort
150
+ list.sort unless list.empty?
153
151
  end
154
152
  end
155
153
 
@@ -161,15 +159,15 @@ module Aurb
161
159
  private
162
160
  def parse(args)
163
161
  OptionParser.new do |o|
164
- o.version = Version*'.'
162
+ o.version = '%s.%s.%s' % [:major, :minor, :tiny].map {|v| Version[v]}
165
163
  o.program_name = 'Aurb'
166
164
  o.release = '2009-04-06'
167
165
 
168
166
  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
167
+ self[:cmd] = "download('#{d*"', '"}')" # wow. ugly
170
168
  end
171
169
  o.on('-S', '--search PKG', 'Search for a package.') do |s|
172
- self[:cmd] = "search('#{s}')" % s
170
+ self[:cmd] = "search('#{s}')"
173
171
  end
174
172
  o.on('-U', '--upgrade', 'Check for upgrades.') do
175
173
  self[:cmd] = 'check_upgrade'
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.1
4
+ version: 0.5.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-06 00:00:00 -07:00
12
+ date: 2009-04-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15