apt-spy2 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apt-spy2 (0.2.2)
4
+ apt-spy2 (0.3.0)
5
5
  colored (>= 1.2)
6
+ json
6
7
  thor (>= 0.18.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
12
  colored (1.2)
13
+ json (1.8.0)
12
14
  rake (10.1.0)
13
15
  thor (0.18.1)
14
16
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # apt-spy2 or, "apt-spy for ubuntu"
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/apt-spy2.png)](http://badge.fury.io/rb/apt-spy2)
4
+ [![Code Climate](https://codeclimate.com/github/lagged/apt-spy2.png)](https://codeclimate.com/github/lagged/apt-spy2)
5
+
3
6
 
4
7
  ## setup
5
8
 
data/apt-spy2.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'thor', '>= 0.18.1'
22
22
  spec.add_dependency 'colored', '>= 1.2'
23
+ spec.add_dependency 'json'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
data/bin/apt-spy2 CHANGED
@@ -1,12 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- #require 'rubygems'
4
- #require 'bundler/setup'
5
-
6
- require 'thor'
7
- require 'open-uri'
8
- require 'colored'
9
- require 'fileutils'
10
3
  require 'apt/spy2'
11
4
 
12
5
  AptSpy2.start
@@ -1,5 +1,5 @@
1
1
  module Apt
2
2
  module Spy2
3
- VERSION = "0.2.3"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,51 @@
1
+ require 'colored'
2
+ require 'json'
3
+
4
+ module Apt
5
+ module Spy2
6
+ class Writer
7
+ def initialize(format)
8
+
9
+ if !["json", "shell"].include?(format)
10
+ raise "Unknown format: #{format}"
11
+ end
12
+
13
+ @format = format
14
+ @complete = []
15
+ end
16
+
17
+ def echo(data)
18
+ if @format == 'json'
19
+ @complete.push(data)
20
+ return
21
+ end
22
+
23
+ print "Mirror: #{data["mirror"]} - "
24
+
25
+ case data["status"]
26
+ when "up"
27
+ puts data["status"].upcase.green
28
+ when "down"
29
+ puts data["status"].upcase.red
30
+ when "broken"
31
+ puts data["status"].upcase.yellow
32
+ else
33
+ puts "Unknown status: #{data["status"]}".white_on_red
34
+ end
35
+ end
36
+
37
+ def json?
38
+ if @format == 'json'
39
+ return true
40
+ end
41
+
42
+ return false
43
+ end
44
+
45
+ def to_json
46
+ JSON.generate(@complete)
47
+ end
48
+
49
+ end
50
+ end
51
+ end
data/lib/apt/spy2.rb CHANGED
@@ -1,3 +1,9 @@
1
+ require 'thor'
2
+ require 'open-uri'
3
+ require 'colored'
4
+ require 'fileutils'
5
+ require 'apt/spy2/writer'
6
+
1
7
  class AptSpy2 < Thor
2
8
  package_name "apt-spy2"
3
9
 
@@ -19,9 +25,15 @@ class AptSpy2 < Thor
19
25
  desc "check", "Evaluate mirrors"
20
26
  option :country, :default => "mirrors"
21
27
  option :output, :type => :boolean, :default => true
28
+ option :format, :default => "shell"
22
29
  def check
30
+
31
+ @writer = Apt::Spy2::Writer.new(options[:format])
32
+
23
33
  mirrors = retrieve(options[:country])
24
- return filter(mirrors, options[:output])
34
+ filter(mirrors, options[:output])
35
+
36
+ puts @writer.to_json if @writer.json?
25
37
  end
26
38
 
27
39
  desc "list", "List the currently available mirrors"
@@ -60,16 +72,18 @@ class AptSpy2 < Thor
60
72
  working_mirrors = []
61
73
 
62
74
  mirrors.each do |mirror|
63
- print "Mirror: #{mirror} - " if output
75
+ data = {"mirror" => mirror }
64
76
  begin
65
77
  mirror_status = open(mirror)
66
- puts "UP".green if output
78
+ data["status"] = "up"
67
79
  working_mirrors << mirror
68
80
  rescue OpenURI::HTTPError => the_error
69
- puts "BROKEN: #{the_error.io.status[0]}".yellow_on_red if output
81
+ data["status"] = "broken"
70
82
  rescue Errno::ECONNREFUSED
71
- puts "DOWN".red if output
83
+ data["status"] = "down"
72
84
  end
85
+
86
+ @writer.echo(data) if output
73
87
  end
74
88
 
75
89
  return working_mirrors
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apt-spy2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-22 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '1.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: bundler
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +109,7 @@ files:
93
109
  - bin/apt-spy2
94
110
  - lib/apt/spy2.rb
95
111
  - lib/apt/spy2/version.rb
112
+ - lib/apt/spy2/writer.rb
96
113
  homepage: https://github.com/lagged/apt-spy2
97
114
  licenses:
98
115
  - BSD