apt-spy2 0.3.0 → 0.4.0
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/Gemfile.lock +1 -1
- data/bin/apt-spy2 +7 -1
- data/lib/apt/spy2.rb +14 -8
- data/lib/apt/spy2/version.rb +1 -1
- data/lib/apt/spy2/writer.rb +4 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/bin/apt-spy2
CHANGED
data/lib/apt/spy2.rb
CHANGED
@@ -3,6 +3,7 @@ require 'open-uri'
|
|
3
3
|
require 'colored'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'apt/spy2/writer'
|
6
|
+
require 'json'
|
6
7
|
|
7
8
|
class AptSpy2 < Thor
|
8
9
|
package_name "apt-spy2"
|
@@ -38,9 +39,16 @@ class AptSpy2 < Thor
|
|
38
39
|
|
39
40
|
desc "list", "List the currently available mirrors"
|
40
41
|
option :country, :default => "mirrors"
|
42
|
+
option :format, :default => "shell"
|
41
43
|
def list
|
44
|
+
|
42
45
|
mirrors = retrieve(options[:country])
|
43
|
-
|
46
|
+
@writer = Apt::Spy2::Writer.new(options[:format])
|
47
|
+
|
48
|
+
@writer.set_complete(mirrors)
|
49
|
+
|
50
|
+
puts @writer.to_json if @writer.json?
|
51
|
+
puts mirrors if !@writer.json?
|
44
52
|
end
|
45
53
|
|
46
54
|
private
|
@@ -53,11 +61,9 @@ class AptSpy2 < Thor
|
|
53
61
|
rescue OpenURI::HTTPError => the_error
|
54
62
|
case the_error.io.status[0]
|
55
63
|
when "404"
|
56
|
-
|
57
|
-
exit 1
|
64
|
+
raise "The country code '#{country}' is incorrect."
|
58
65
|
else
|
59
|
-
|
60
|
-
exit 1
|
66
|
+
raise "Status: #{the_error.io.status[0]}"
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
@@ -109,9 +115,9 @@ class AptSpy2 < Thor
|
|
109
115
|
f.write(sources)
|
110
116
|
end
|
111
117
|
rescue
|
112
|
-
|
113
|
-
|
114
|
-
|
118
|
+
msg = "Failed updating #{apt_sources}!"
|
119
|
+
msg << "You probably need sudo!"
|
120
|
+
raise msg
|
115
121
|
end
|
116
122
|
|
117
123
|
puts "Updated '#{apt_sources}' with #{mirror}".green
|
data/lib/apt/spy2/version.rb
CHANGED
data/lib/apt/spy2/writer.rb
CHANGED