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 +3 -1
- data/README.md +3 -0
- data/apt-spy2.gemspec +1 -0
- data/bin/apt-spy2 +0 -7
- data/lib/apt/spy2/version.rb +1 -1
- data/lib/apt/spy2/writer.rb +51 -0
- data/lib/apt/spy2.rb +19 -5
- metadata +19 -2
data/Gemfile.lock
CHANGED
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
data/bin/apt-spy2
CHANGED
data/lib/apt/spy2/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
75
|
+
data = {"mirror" => mirror }
|
64
76
|
begin
|
65
77
|
mirror_status = open(mirror)
|
66
|
-
|
78
|
+
data["status"] = "up"
|
67
79
|
working_mirrors << mirror
|
68
80
|
rescue OpenURI::HTTPError => the_error
|
69
|
-
|
81
|
+
data["status"] = "broken"
|
70
82
|
rescue Errno::ECONNREFUSED
|
71
|
-
|
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.
|
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-
|
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
|