aurb 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,8 @@ Download one or more packages:
18
18
 
19
19
  $ aurb download hon ioquake3
20
20
 
21
+ *By default, this will save the package to $HOME/abs. Override with `--path=/mypath`*
22
+
21
23
  Search for one or more packages:
22
24
 
23
25
  $ aurb search firefox opera
data/bin/aurb CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require File.expand_path(File.dirname(__FILE__) + '/../lib/aurb/cli')
4
+ require File.expand_path('../../lib/aurb/main', __FILE__)
5
5
 
6
6
  begin
7
- Aurb::CLI.start
8
- rescue Aurb::AurbError => e
9
- puts e.message.colorize(:red)
10
- exit e.status_code
7
+ Aurb::Main.start
8
+ rescue Aurb::Error => e
9
+ abort e.message.colorize(:red)
11
10
  end
@@ -1,59 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
5
-
6
- require 'logger'
7
4
  require 'open-uri'
8
-
9
5
  require 'zlib'
10
6
  require 'yajl'
11
- require 'ansi'
12
7
  require 'archive/tar/minitar'
13
8
 
14
- module Aurb #:nodoc:
15
- autoload :Aur, 'aurb/aur'
16
-
17
- class AurbError < StandardError
18
- def self.status_code(code = nil)
19
- return @code unless code
20
- @code = code
21
- end
22
-
23
- def status_code
24
- self.class.status_code
25
- end
26
- end
27
-
28
- class NoResultsError < AurbError
29
- status_code 7
30
-
31
- def initialize
32
- super('No results found')
33
- end
34
- end
35
-
36
- class DownloadError < AurbError
37
- status_code 10
38
- end
39
-
40
- class << self
41
- def logger
42
- @logger ||= Logger.new(STDOUT)
43
- end
44
-
45
- def aur_rpc_path(type, arg)
46
- "http://aur.archlinux.org/rpc.php?type=#{type}&arg=#{arg}"
47
- end
48
-
49
- def aur_download_path(pkg)
50
- "http://aur.archlinux.org/packages/#{pkg}/#{pkg}.tar.gz"
51
- end
52
-
53
- def aur
54
- @aur ||= Aur.new
55
- end
56
- end
57
- end
9
+ libdir = File.dirname(__FILE__)
10
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
58
11
 
12
+ require 'aurb/base'
59
13
  require 'aurb/core_ext'
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Aurb
5
+ # Generic Aurb error class.
6
+ class Error < StandardError; end
7
+
8
+ # Raised when a download location wasn't found.
9
+ class DownloadError < Error; end
10
+
11
+ # Raised when a search returns no results.
12
+ class NoResultsError < Error
13
+ def initialize
14
+ super('No results found')
15
+ end
16
+ end
17
+
18
+ # The path to save downloaded packages to.
19
+ SavePath = '~/abs'
20
+
21
+ # The URL to retrieve package info from.
22
+ SearchPath = lambda {|t, a| "http://aur.archlinux.org/rpc.php?type=#{t}&arg=#{a}"}
23
+
24
+ # The URL to retrieve packages from.
25
+ DownloadPath = lambda {|p| "http://aur.archlinux.org/packages/#{p}/#{p}.tar.gz"}
26
+
27
+ # Main Aurb class, interacting with the AUR.
28
+ module Base
29
+ extend self
30
+
31
+ # Compare package versions.
32
+ #
33
+ # Version.new('1.0.0') < Version.new('2.0.0') # => true
34
+ # Version.new('1.1-1') < Version.new('1.0-6') # => false
35
+ class Version
36
+ include Comparable
37
+
38
+ attr_reader :version
39
+
40
+ def initialize(*args)
41
+ @version = args.join('.').split(/\W+/).map &:to_i
42
+ end
43
+
44
+ def <=>(other)
45
+ [self.version.size, other.version.size].max.times do |i|
46
+ c = self.version[i] <=> other.version[i]
47
+ return c if c != 0
48
+ end
49
+ end
50
+ end
51
+
52
+ # Search the AUR for given +packages+.
53
+ # Returns an array of results.
54
+ #
55
+ # search('aurb') # => [{:ID => ..., :Name => 'aurb', ...}, {...}]
56
+ def search(*packages)
57
+ [].tap { |results|
58
+ packages.map {|p| URI.escape(p.to_s)}.inject([]) { |ary, package|
59
+ ary << Thread.new do
60
+ parse_json Aurb::SearchPath[:search, package] do |json|
61
+ next if json.type =~ /error/
62
+ results << json.results
63
+ end
64
+ end
65
+ }.each &:join
66
+ }.flatten.compact
67
+ end
68
+
69
+ # Download +packages+ from the AUR.
70
+ # Returns an array of downloadable package urls.
71
+ #
72
+ # download('aurb') # => ['http://.../aurb.tar.gz']
73
+ def download(*packages)
74
+ packages.map { |package|
75
+ Aurb::DownloadPath[URI.escape(package.to_s)]
76
+ }.select { |package|
77
+ !!(open package rescue false)
78
+ }.compact
79
+ end
80
+
81
+ # Returns all available info for a given package name.
82
+ #
83
+ # info('aurb') # => {:ID => ..., :Name => 'aurb', ...}
84
+ def info(package)
85
+ parse_json Aurb::SearchPath[:info, URI.escape(package.to_s)] do |json|
86
+ return if json.type =~ /error/
87
+ json.results
88
+ end
89
+ end
90
+
91
+ # Returns a +list+ of names of packages that have an upgrade
92
+ # available to them, which could then in turn be passed on to
93
+ # the +download+ method.
94
+ #
95
+ # # With Aurb on the AUR as version 1.1.2-1
96
+ # upgrade('aurb 0.0.0-0', 'aurb 9.9.9-9') # => [:aurb]
97
+ def upgrade(*list)
98
+ [].tap { |upgradables|
99
+ list.inject([]) { |ary, line|
100
+ ary << Thread.new do
101
+ name, version = line.split
102
+
103
+ next if Dir["/var/lib/pacman/sync/community/#{name}-#{version}"].any?
104
+ upgradables << name.to_sym if upgradable?(name, version)
105
+ end
106
+ }.each &:join
107
+ }.compact
108
+ end
109
+
110
+ protected
111
+
112
+ # Shortcut to the +Yajl+ JSON parser.
113
+ def parse_json(json)
114
+ json = Yajl::Parser.new.parse(open(json).read)
115
+ block_given? ? yield(json) : json
116
+ end
117
+
118
+ private
119
+
120
+ # Compare version of local +package+ with the one on the AUR.
121
+ def upgradable?(package, version)
122
+ package = URI.escape(package.to_s)
123
+ local_version = Version.new(version)
124
+ remote_version = nil
125
+
126
+ parse_json Aurb::SearchPath[:info, package] do |json|
127
+ return if json.type =~ /error/
128
+ remote_version = Version.new(json.results.Version)
129
+ end
130
+
131
+ remote_version and local_version < remote_version
132
+ end
133
+ end
134
+
135
+ # Check if +Base+ responds to this unknown method and delegate the method to
136
+ # +Base+ if so.
137
+ def self.method_missing(method, args, &block)
138
+ if Base.respond_to?(method)
139
+ Base.send method, *args, &block
140
+ else
141
+ super
142
+ end
143
+ end
144
+ end
@@ -1,5 +1,4 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
 
3
- require 'core_ext/object'
4
3
  require 'core_ext/hash'
5
4
  require 'core_ext/string'
@@ -14,12 +14,12 @@ module Aurb
14
14
 
15
15
  # Destructively converts all keys to symbols.
16
16
  def symbolize_keys!
17
- self.replace(self.symbolize_keys)
17
+ replace symbolize_keys
18
18
  end
19
19
 
20
20
  # Delegation
21
21
  def method_missing(key)
22
- self.symbolize_keys[key.to_sym]
22
+ symbolize_keys[key.to_sym]
23
23
  end
24
24
  end
25
25
  end
@@ -4,15 +4,18 @@
4
4
  module Aurb
5
5
  module CoreExt
6
6
  module String
7
+ # Available colors for <tt>String#colorize</tt>.
8
+ COLORS = [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white]
9
+
7
10
  # Colors a string with +color+.
8
- # Uses the ANSICode library provided by +facets+.
9
- #
10
- # "Hello".colorize(:blue) # => "\e[34mHello\e[0m"
11
11
  #
12
- # For more information on available effects, see
13
- # http://facets.rubyforge.org/apidoc/api/more/classes/ANSICode.html
12
+ # "Hello".colorize(:blue)
14
13
  def colorize(effect)
15
- ANSI::Code.send(effect.to_sym) << self << ANSI::Code.clear
14
+ if STDOUT.tty? && ENV['TERM']
15
+ "\033[0;#{30+COLORS.index(effect.to_sym)}m#{self}\033[0m"
16
+ else
17
+ self
18
+ end
16
19
  rescue
17
20
  self
18
21
  end
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
4
+ require 'rubygems' if RUBY_DESCRIPTION =~ /(rubinius|jruby)/i
5
5
  require 'thor'
6
- require 'aurb'
6
+ require File.expand_path('../../aurb', __FILE__)
7
7
 
8
8
  module Aurb
9
- class CLI < Thor
9
+ class Main < Thor
10
10
  ARGV = ::ARGV.dup
11
11
 
12
12
  map %w[-d --download] => :download,
@@ -17,64 +17,79 @@ module Aurb
17
17
  desc 'download PACKAGES', 'Download packages'
18
18
  method_option :path,
19
19
  :type => :string,
20
- :default => File.join(ENV[:HOME], 'abs'),
20
+ :default => Aurb::SavePath,
21
21
  :banner => 'Specify the path to download to'
22
22
  method_option :keep,
23
23
  :type => :boolean,
24
24
  :banner => 'Keep the tarball after downloading'
25
25
  def download(*pkgs)
26
- pkgs = Aurb.aur.download(*pkgs)
27
- raise Aurb::NoResultsError if pkgs.blank?
28
- path = options.path[0] == '/' ? options.path : File.join(Dir.pwd, options.path)
26
+ pkgs = Aurb.download(*pkgs)
27
+ raise Aurb::NoResultsError if pkgs.empty?
28
+
29
+ path = if options.path.start_with?('/')
30
+ options.path
31
+ else
32
+ File.join(Dir.pwd, options.path)
33
+ end
34
+
29
35
  if File.exist?(path)
30
36
  path = File.expand_path(path)
31
37
  else
32
38
  raise Aurb::DownloadError, "'#{path}' is not a valid path"
33
39
  end
40
+
34
41
  pkgs.each_with_index do |package, index|
35
42
  local = package.split('/')[-1]
43
+
36
44
  Dir.chdir path do
37
45
  open package do |remote|
38
46
  File.open local, 'wb' do |local|
39
47
  local.write remote.read
40
48
  end
41
49
  end
42
- Archive::Tar::Minitar.unpack Zlib::GzipReader.new(File.open(local, 'rb')), Dir.pwd
50
+
51
+ Archive::Tar::Minitar.
52
+ unpack Zlib::GzipReader.new(File.open(local, 'rb')), Dir.pwd
43
53
  File.delete local unless options.keep?
44
54
  end
55
+
45
56
  puts "(#{index+1}/#{pkgs.size}) downloaded #{local}"
46
57
  end
47
58
  end
48
59
 
49
60
  desc 'search PACKAGES', 'Search for packages'
50
61
  def search(*pkgs)
51
- pkgs = Aurb.aur.search(*pkgs)
52
- raise Aurb::NoResultsError if pkgs.blank?
62
+ pkgs = Aurb.search(*pkgs)
63
+ raise Aurb::NoResultsError if pkgs.empty?
64
+
53
65
  pkgs.each do |package|
54
66
  status = package.OutOfDate == '1' ? '✘'.colorize(:red) : '✔'.colorize(:green)
55
- name, version, description = package.Name.colorize(:yellow),
56
- package.Version,
57
- package.Description
58
- puts "[#{status}] #{name} (#{version})\n #{description}"
67
+ name, version, description, votes =
68
+ package.Name.colorize(:yellow), package.Version, package.Description,
69
+ package.NumVotes.colorize(:blue)
70
+
71
+ puts "[#{status}] #{name} #{version} (#{votes})\n #{description}"
59
72
  end
60
73
  end
61
74
 
62
75
  desc 'info PACKAGE', 'List all available information for a given package'
63
76
  def info(pkg)
64
- info = Aurb.aur.info(pkg)
65
- raise Aurb::NoResultsError if info.blank?
77
+ info = Aurb.info(pkg)
78
+ raise Aurb::NoResultsError if info.empty?
79
+
66
80
  info.each do |key, value|
67
- print key.colorize(:yellow)
68
- (key.size..11).each { print ' ' }
69
- print value, "\n"
81
+ (key.size..10).each { print ' ' }
82
+ print key.colorize(:yellow) + ' '
83
+ puts value
70
84
  end
71
85
  end
72
86
 
73
87
  desc 'upgrade', 'Search for upgrades to installed packages'
74
88
  def upgrade
75
89
  list = `pacman -Qm`.split(/\n/)
76
- pkgs = Aurb.aur.upgrade(*list)
77
- raise Aurb::NoResultsError if pkgs.blank?
90
+ pkgs = Aurb.upgrade(*list)
91
+ raise Aurb::NoResultsError if pkgs.empty?
92
+
78
93
  pkgs.each do |package|
79
94
  puts "#{package.to_s.colorize(:yellow)} has an upgrade available"
80
95
  end
@@ -1,3 +1,3 @@
1
1
  module Aurb
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'
3
3
  end
@@ -1,17 +1,10 @@
1
- require 'pp'
1
+ require 'rubygems' if RUBY_DESCRIPTION =~ /rubinius/i
2
2
  require 'benchmark'
3
-
4
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
-
6
- require 'aurb'
3
+ require File.expand_path('../../lib/aurb', __FILE__)
7
4
 
8
5
  Benchmark.bm 20 do |x|
9
- x.report 'aurb upgrade' do
10
- Aurb.aur.upgrade *`pacman -Qm`.split(/\n/)
11
- end
12
-
13
6
  x.report 'aurb search' do
14
- Aurb.aur.search *:quake
7
+ Aurb.aur.search :quake
15
8
  end
16
9
 
17
10
  x.report 'slurpy search' do
@@ -1,6 +1,2 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../lib/aurb')
2
-
1
+ require File.expand_path('../../lib/aurb', __FILE__)
3
2
  require 'shoulda'
4
-
5
- class Test::Unit::TestCase
6
- end
@@ -0,0 +1,96 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ context 'Aurb::Base' do
5
+ context 'Version' do
6
+ should 'be able to compare versions and return the newest' do
7
+ versions = [
8
+ {:old => '1', :new => '2' },
9
+ {:old => '1-3', :new => '2-1' },
10
+ {:old => '1.0.0-2', :new => '2.0.0-3'},
11
+ {:old => '1.0.pre', :new => '1.0.1' }
12
+ ]
13
+ versions.each do |version|
14
+ assert_operator Aurb::Base::Version.new(version[:old]), :<, Aurb::Base::Version.new(version[:new])
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'Aurb::Base' do
21
+ context 'info' do
22
+ setup do
23
+ @package_working = 'aurb'
24
+ @package_faulty = 'foobarbaz'
25
+ end
26
+
27
+ should 'return a hash of results' do
28
+ assert_operator Hash, :===, Aurb::Base.info(@package_working)
29
+ end
30
+
31
+ should 'return nothing when a package does not exist' do
32
+ assert Aurb::Base.info(@package_faulty).nil?
33
+ assert_nil Aurb::Base.info(@package_faulty)
34
+ end
35
+ end
36
+
37
+ context 'upgrade' do
38
+ setup do
39
+ @list = "aurb 0.0.0-0\naurb 9.9.9-9".split(/\n/)
40
+ end
41
+
42
+ should 'return an array' do
43
+ assert_operator Array, :===, Aurb::Base.upgrade(*@list)
44
+ end
45
+
46
+ should 'contain only upgradable packages' do
47
+ assert_not_equal [:aurb, :aurb], Aurb::Base.upgrade(*@list)
48
+ assert_equal [:aurb], Aurb::Base.upgrade(*@list)
49
+ end
50
+ end
51
+
52
+ context 'download' do
53
+ setup do
54
+ @package_working = 'aurb'
55
+ @package_faulty = 'foobarbaz'
56
+ end
57
+
58
+ should 'return an array' do
59
+ assert_operator Array, :===, Aurb::Base.download(*@package_working)
60
+ assert_operator Array, :===, Aurb::Base.download(*@package_faulty)
61
+ end
62
+
63
+ should 'return download links' do
64
+ assert_equal [Aurb::DownloadPath[*@package_working]], Aurb::Base.download(*@package_working)
65
+ end
66
+
67
+ should 'filter out non-existant packages' do
68
+ assert Aurb::Base.download(*@package_faulty).empty?
69
+ assert_equal [], Aurb::Base.download(*@package_faulty)
70
+ end
71
+ end
72
+
73
+ context 'search' do
74
+ setup do
75
+ @package_working = 'aurb'
76
+ @package_faulty = 'foobarbaz'
77
+ end
78
+
79
+ should 'return an array of results' do
80
+ assert_operator Array, :===, Aurb::Base.search(*@package_working)
81
+ assert_operator Array, :===, Aurb::Base.search(*@package_faulty)
82
+ end
83
+
84
+ should 'filter out non-existant packages' do
85
+ assert Aurb::Base.search(*@package_faulty).empty?
86
+ assert_equal [], Aurb::Base.search(*@package_faulty)
87
+ end
88
+
89
+ context 'result' do
90
+ should 'return an array containing hashes' do
91
+ assert_operator Hash, :===, Aurb::Base.search(*@package_working).first
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,14 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
1
+ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  class SupportTest < Test::Unit::TestCase
4
- context 'Object' do
5
- should 'be able to check for blank' do
6
- assert ''.blank?
7
- assert nil.blank?
8
- assert [].blank?
9
- end
10
- end
11
-
12
4
  context 'Hash' do
13
5
  setup do
14
6
  @hash_str = {'hello' => 'world'}
@@ -28,13 +20,12 @@ class SupportTest < Test::Unit::TestCase
28
20
  end
29
21
 
30
22
  context 'String' do
31
- setup do
32
- @str = 'foo'
33
- end
34
-
35
- should 'be able to colorize itself through the ansi library' do
36
- assert @str.colorize(:blue)
37
- assert_equal "\e[34mfoo\e[0m", @str.colorize(:blue)
23
+ should 'be able to colorize itself' do
24
+ str = 'foo'
25
+ String::COLORS.each_with_index do |color, i|
26
+ assert str.colorize(color)
27
+ assert_equal "\e[0;#{30+i}m#{str}\e[0m", str.colorize(color)
28
+ end
38
29
  end
39
30
  end
40
31
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aurb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ prerelease:
5
+ version: 1.4.0
5
6
  platform: ruby
6
7
  authors:
7
8
  - Gigamo
@@ -9,117 +10,104 @@ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2010-03-07 00:00:00 +01:00
13
+ date: 2011-09-21 00:00:00 +02:00
13
14
  default_executable: aurb
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: yajl-ruby
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
24
  version: "0"
24
- version:
25
+ type: :runtime
26
+ version_requirements: *id001
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: thor
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
30
32
  requirements:
31
33
  - - ">="
32
34
  - !ruby/object:Gem::Version
33
35
  version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: ansi
37
36
  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:
37
+ version_requirements: *id002
45
38
  - !ruby/object:Gem::Dependency
46
39
  name: archive-tar-minitar
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
50
43
  requirements:
51
44
  - - ">="
52
45
  - !ruby/object:Gem::Version
53
46
  version: "0"
54
- version:
47
+ type: :runtime
48
+ version_requirements: *id003
55
49
  - !ruby/object:Gem::Dependency
56
50
  name: shoulda
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
60
54
  requirements:
61
55
  - - ">="
62
56
  - !ruby/object:Gem::Version
63
57
  version: "0"
64
- version:
65
- description:
66
- email: gigamo@gmail.com
58
+ type: :development
59
+ version_requirements: *id004
60
+ description: An AUR (Arch User Repository) utility
61
+ email:
62
+ - gigamo@gmail.com
67
63
  executables:
68
64
  - aurb
69
65
  extensions: []
70
66
 
71
- extra_rdoc_files:
72
- - LICENSE
73
- - README.md
67
+ extra_rdoc_files: []
68
+
74
69
  files:
75
- - .gitignore
76
- - LICENSE
77
- - README.md
78
- - Rakefile
79
- - VERSION
80
- - aurb.gemspec
81
70
  - bin/aurb
82
- - lib/aurb.rb
83
- - lib/aurb/aur.rb
84
- - lib/aurb/cli.rb
85
- - lib/aurb/core_ext.rb
71
+ - lib/aurb/base.rb
86
72
  - lib/aurb/core_ext/hash.rb
87
- - lib/aurb/core_ext/object.rb
88
73
  - lib/aurb/core_ext/string.rb
74
+ - lib/aurb/core_ext.rb
75
+ - lib/aurb/main.rb
89
76
  - lib/aurb/version.rb
90
- - performance/aur.rb
77
+ - lib/aurb.rb
91
78
  - test/test_helper.rb
92
- - test/unit/aur_test.rb
79
+ - test/unit/base_test.rb
93
80
  - test/unit/support_test.rb
81
+ - performance/aur.rb
82
+ - LICENSE
83
+ - README.md
94
84
  has_rdoc: true
95
85
  homepage: http://github.com/gigamo/aurb
96
86
  licenses: []
97
87
 
98
88
  post_install_message:
99
- rdoc_options:
100
- - --charset=UTF-8
89
+ rdoc_options: []
90
+
101
91
  require_paths:
102
92
  - lib
103
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
104
95
  requirements:
105
96
  - - ">="
106
97
  - !ruby/object:Gem::Version
107
98
  version: "0"
108
- version:
109
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
110
101
  requirements:
111
102
  - - ">="
112
103
  - !ruby/object:Gem::Version
113
- version: "0"
114
- version:
104
+ version: 1.3.6
115
105
  requirements: []
116
106
 
117
- rubyforge_project:
118
- rubygems_version: 1.3.5
107
+ rubyforge_project: aurb
108
+ rubygems_version: 1.5.0
119
109
  signing_key:
120
110
  specification_version: 3
121
111
  summary: An AUR (Arch User Repository) utility
122
- test_files:
123
- - test/unit/aur_test.rb
124
- - test/unit/support_test.rb
125
- - test/test_helper.rb
112
+ test_files: []
113
+
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- .config
2
- InstalledFiles
3
- *.swp
4
- *.rbc
5
- doc
6
- pkg
7
- .yardoc
8
- *.gem
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- require 'rake'
2
- require 'jeweler'
3
- require 'yard'
4
- require 'yard/rake/yardoc_task'
5
-
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = 'aurb'
8
- gem.summary = %Q{An AUR (Arch User Repository) utility}
9
- gem.email = 'gigamo@gmail.com'
10
- gem.homepage = 'http://github.com/gigamo/aurb'
11
- gem.authors = ['Gigamo']
12
-
13
- gem.add_dependency('yajl-ruby')
14
- gem.add_dependency('thor')
15
- gem.add_dependency('ansi')
16
- gem.add_dependency('archive-tar-minitar')
17
-
18
- gem.add_development_dependency('shoulda')
19
- end
20
-
21
- Jeweler::GemcutterTasks.new
22
-
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'test'
26
- test.ruby_opts << '-rubygems'
27
- test.pattern = 'test/**/*_test.rb'
28
- test.verbose = true
29
- end
30
-
31
- namespace :test do
32
- Rake::TestTask.new(:units) do |test|
33
- test.libs << 'test'
34
- test.ruby_opts << '-rubygems'
35
- test.pattern = 'test/unit/**/*_test.rb'
36
- test.verbose = true
37
- end
38
- end
39
-
40
- task :default => :test
41
- task :test => :check_dependencies
42
-
43
- YARD::Rake::YardocTask.new(:doc) do |t|
44
- t.options = ['--legacy'] if RUBY_VERSION < '1.9.0'
45
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.3.0
@@ -1,77 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{aurb}
8
- s.version = "1.3.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Gigamo"]
12
- s.date = %q{2010-03-07}
13
- s.default_executable = %q{aurb}
14
- s.email = %q{gigamo@gmail.com}
15
- s.executables = ["aurb"]
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- "LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "aurb.gemspec",
27
- "bin/aurb",
28
- "lib/aurb.rb",
29
- "lib/aurb/aur.rb",
30
- "lib/aurb/cli.rb",
31
- "lib/aurb/core_ext.rb",
32
- "lib/aurb/core_ext/hash.rb",
33
- "lib/aurb/core_ext/object.rb",
34
- "lib/aurb/core_ext/string.rb",
35
- "lib/aurb/version.rb",
36
- "performance/aur.rb",
37
- "test/test_helper.rb",
38
- "test/unit/aur_test.rb",
39
- "test/unit/support_test.rb"
40
- ]
41
- s.homepage = %q{http://github.com/gigamo/aurb}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.5}
45
- s.summary = %q{An AUR (Arch User Repository) utility}
46
- s.test_files = [
47
- "test/unit/aur_test.rb",
48
- "test/unit/support_test.rb",
49
- "test/test_helper.rb"
50
- ]
51
-
52
- if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
58
- s.add_runtime_dependency(%q<thor>, [">= 0"])
59
- s.add_runtime_dependency(%q<ansi>, [">= 0"])
60
- s.add_runtime_dependency(%q<archive-tar-minitar>, [">= 0"])
61
- s.add_development_dependency(%q<shoulda>, [">= 0"])
62
- else
63
- s.add_dependency(%q<yajl-ruby>, [">= 0"])
64
- s.add_dependency(%q<thor>, [">= 0"])
65
- s.add_dependency(%q<ansi>, [">= 0"])
66
- s.add_dependency(%q<archive-tar-minitar>, [">= 0"])
67
- s.add_dependency(%q<shoulda>, [">= 0"])
68
- end
69
- else
70
- s.add_dependency(%q<yajl-ruby>, [">= 0"])
71
- s.add_dependency(%q<thor>, [">= 0"])
72
- s.add_dependency(%q<ansi>, [">= 0"])
73
- s.add_dependency(%q<archive-tar-minitar>, [">= 0"])
74
- s.add_dependency(%q<shoulda>, [">= 0"])
75
- end
76
- end
77
-
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- module Aurb
5
- class Aur
6
- # Compare package versions.
7
- #
8
- # Version.new('1.0.0') < Version.new('2.0.0') # => true
9
- # Version.new('1.1-1') < Version.new('1.0-6') # => false
10
- class Version
11
- include Comparable
12
-
13
- attr_reader :version
14
-
15
- def initialize(*args)
16
- @version = args.join('.').split(/\W+/).map(&:to_i)
17
- end
18
-
19
- def <=>(other)
20
- [self.version.size, other.version.size].max.times do |i|
21
- c = self.version[i] <=> other.version[i]
22
- return c if c != 0
23
- end
24
- end
25
- end
26
-
27
- # Search the AUR for given +packages+.
28
- # Returns an array of results.
29
- #
30
- # search('aurb') # => [{:ID => ..., :Name => 'aurb', ...}, {...}]
31
- def search(*packages)
32
- results = []
33
- packages.inject([]) do |ary, package|
34
- ary << Thread.new do
35
- parse_json Aurb.aur_rpc_path(:search, URI.escape(package.to_s)) do |json|
36
- next if json.type =~ /error/
37
- results << json.results
38
- end
39
- end
40
- end.each(&:join)
41
- results.flatten.delete_if(&:blank?)
42
- end
43
-
44
- # Download +packages+ from the AUR.
45
- # Returns an array of downloadable package urls.
46
- #
47
- # download('aurb') # => ['http://.../aurb.tar.gz']
48
- def download(*packages)
49
- packages.map do |package|
50
- Aurb.aur_download_path URI.escape(package.to_s)
51
- end.select do |package|
52
- !!(open package rescue false)
53
- end.delete_if(&:blank?)
54
- end
55
-
56
- # Returns all available info for a given package name.
57
- #
58
- # info('aurb') # => {:ID => ..., :Name => 'aurb', ...}
59
- def info(package)
60
- parse_json Aurb.aur_rpc_path(:info, package.to_s) do |json|
61
- return if json.type =~ /error/
62
- json.results
63
- end
64
- end
65
-
66
- # Returns a +list+ of names of packages that have an upgrade
67
- # available to them, which could then in turn be passed on to
68
- # the +download+ method.
69
- #
70
- # # With Aurb on the AUR as version 1.1.2-1
71
- # upgrade('aurb 0.0.0-0', 'aurb 0.9.9-9') # => [:aurb]
72
- def upgrade(*list)
73
- upgradables = []
74
- list.inject([]) do |ary, line|
75
- ary << Thread.new do
76
- name, version = line.split
77
- next if Dir["/var/lib/pacman/sync/community/#{name}-#{version}"].any?
78
- upgradables << name.to_sym if upgradable?(name, version)
79
- end
80
- end.each(&:join)
81
- upgradables.delete_if(&:blank?)
82
- end
83
-
84
- protected
85
-
86
- # Shortcut to the +Yajl+ JSON parser.
87
- def parse_json(json)
88
- json = Yajl::Parser.new.parse(open(json).read)
89
- yield json rescue json
90
- end
91
-
92
- private
93
-
94
- # Compare version of local +package+ with the one on the AUR.
95
- def upgradable?(package, version)
96
- local_version = Version.new(version)
97
- remote_version = nil
98
- parse_json Aurb.aur_rpc_path(:info, package.to_s) do |json|
99
- return if json.type =~ /error/
100
- remote_version = Version.new(json.results.Version)
101
- end
102
- remote_version && local_version < remote_version
103
- end
104
- end
105
- end
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- module Aurb
5
- module CoreExt
6
- module Object
7
- # An object is blank if it's false, empty or a whitespace string.
8
- def blank?
9
- respond_to?(:empty?) ? empty? : !self
10
- end
11
- end
12
- end
13
- end
14
-
15
- Object.send :include, Aurb::CoreExt::Object
@@ -1,81 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- class AurTest < Test::Unit::TestCase
4
- context 'Aurb::Aur ::' do
5
- context 'Version' do
6
- should 'be able to compare versions and return the newest' do
7
- versions = [
8
- {:old => '1', :new => '2' },
9
- {:old => '1-3', :new => '2-1' },
10
- {:old => '1.0.0-2', :new => '2.0.0-3'},
11
- {:old => '1.0.pre', :new => '1.0.1' }
12
- ]
13
-
14
- versions.each do |version|
15
- assert_operator Aurb::Aur::Version.new(version[:old]), :<, Aurb::Aur::Version.new(version[:new])
16
- end
17
- end
18
- end
19
- end
20
-
21
- context 'Aurb::Aur #' do
22
- context 'upgrade' do
23
- setup do
24
- @list = "aurb 0.0.0-0\naurb 9.9.9-9".split(/\n/)
25
- end
26
-
27
- should 'return an array' do
28
- assert_operator Array, :===, Aurb.aur.upgrade(*@list)
29
- end
30
-
31
- should 'contain only upgradable packages' do
32
- assert_not_equal [:aurb, :aurb], Aurb.aur.upgrade(*@list)
33
- assert_equal [:aurb], Aurb.aur.upgrade(*@list)
34
- end
35
- end
36
-
37
- context 'download' do
38
- setup do
39
- @package_working = 'aurb'
40
- @package_faulty = 'foobarbaz'
41
- end
42
-
43
- should 'return an array' do
44
- assert_operator Array, :===, Aurb.aur.download(*@package_working)
45
- assert_operator Array, :===, Aurb.aur.download(*@package_faulty)
46
- end
47
-
48
- should 'return download links' do
49
- assert_equal [Aurb.aur_download_path(*@package_working)], Aurb.aur.download(*@package_working)
50
- end
51
-
52
- should 'filter out non-existant packages' do
53
- assert Aurb.aur.download(*@package_faulty).blank?
54
- assert_equal [], Aurb.aur.download(*@package_faulty)
55
- end
56
- end
57
-
58
- context 'search' do
59
- setup do
60
- @package_working = 'aurb'
61
- @package_faulty = 'foobarbaz'
62
- end
63
-
64
- should 'return an array of results' do
65
- assert_operator Array, :===, Aurb.aur.search(*@package_working)
66
- assert_operator Array, :===, Aurb.aur.search(*@package_faulty)
67
- end
68
-
69
- should 'filter out non-existant packages' do
70
- assert Aurb.aur.search(*@package_faulty).blank?
71
- assert_equal [], Aurb.aur.search(*@package_faulty)
72
- end
73
-
74
- context 'result' do
75
- should 'return an array containing hashes' do
76
- assert_operator Hash, :===, Aurb.aur.search(*@package_working).first
77
- end
78
- end
79
- end
80
- end
81
- end