Commit MetaInfo

修订版42a8d6a815ce33b175de7247e1ca61fb9db35e38 (tree)
时间2016-07-19 19:41:19
作者Tatsuki Sugiura <sugi@nemu...>
CommiterTatsuki Sugiura

Log Message

Add bandwidth limit option.

更改概述

差异

--- a/lib/osdn/cli.rb
+++ b/lib/osdn/cli.rb
@@ -30,8 +30,17 @@ module OSDN
3030 @@_show_progress = v
3131 end
3232
33+ @@_rate_limit = nil
34+ def _rate_limit
35+ @@_rate_limit
36+ end
37+ def _rate_limit=(v)
38+ @@_rate_limit = v
39+ end
40+
3341 module_function :client_id, :client_secret,
34- :_show_progress, :_show_progress=
42+ :_show_progress, :_show_progress=,
43+ :_rate_limit, :_rate_limit=
3544
3645 module Command
3746 autoload :Login, 'osdn/cli/command/login'
--- a/lib/osdn/cli/command/frs_upload.rb
+++ b/lib/osdn/cli/command/frs_upload.rb
@@ -12,6 +12,7 @@ module OSDN; module CLI; module Command
1212 puts " --force-digest Calc local file digest forcely"
1313 puts " --progress Force to show upload progress"
1414 puts " --no-progress Force to hide upload progress"
15+ puts " --bwlimit=RATE Limit bandwidth (in KB)"
1516 end
1617
1718 def run
@@ -25,6 +26,7 @@ module OSDN; module CLI; module Command
2526 [ '--force-digest', GetoptLong::NO_ARGUMENT],
2627 [ '--progress', GetoptLong::NO_ARGUMENT],
2728 [ '--no-progress', GetoptLong::NO_ARGUMENT],
29+ [ '--bwlimit', GetoptLong::REQUIRED_ARGUMENT ],
2830 )
2931 opts.each do |opt, arg|
3032 case opt
@@ -51,6 +53,9 @@ module OSDN; module CLI; module Command
5153 @show_progress = true
5254 when '--no-progress'
5355 @show_progress = false
56+ when '--bwlimit'
57+ arg.to_i != 0 and
58+ OSDN::CLI._rate_limit = arg.to_i * 1024
5459 end
5560 end
5661
--- a/lib/osdn/cli/command/relfile.rb
+++ b/lib/osdn/cli/command/relfile.rb
@@ -17,6 +17,7 @@ module OSDN; module CLI; module Command
1717 puts " --force-digest Calc local file digest forcely"
1818 puts " --progress Force to show upload progress"
1919 puts " --no-progress Force to hide upload progress"
20+ puts " --bwlimit=RATE Limit bandwidth (in KB)"
2021 end
2122
2223 def self.description
@@ -33,6 +34,7 @@ module OSDN; module CLI; module Command
3334 [ '--force-digest', GetoptLong::NO_ARGUMENT],
3435 [ '--progress', GetoptLong::NO_ARGUMENT],
3536 [ '--no-progress', GetoptLong::NO_ARGUMENT],
37+ [ '--bwlimit', GetoptLong::REQUIRED_ARGUMENT ],
3638 )
3739 opts.each do |opt, arg|
3840 case opt
@@ -60,6 +62,9 @@ module OSDN; module CLI; module Command
6062 @show_progress = true
6163 when '--no-progress'
6264 @show_progress = false
65+ when '--bwlimit'
66+ arg.to_i != 0 and
67+ OSDN::CLI._rate_limit = arg.to_i * 1024
6368 end
6469 end
6570 end
--- a/lib/osdn/cli/overrides.rb
+++ b/lib/osdn/cli/overrides.rb
@@ -5,6 +5,7 @@ module Typhoeus
55 alias_method :get_orig, :get
66 def get(*args)
77 easy = get_orig(*args)
8+
89 if ENV['CURL_CA_BUNDLE']
910 Ethon::Curl.set_option(:cainfo, ENV['CURL_CA_BUNDLE'], easy.handle)
1011 else
@@ -21,12 +22,18 @@ module Typhoeus
2122 Ethon::Curl.set_option(:cainfo, ca, easy.handle)
2223 end
2324 end
25+
2426 if OSDN::CLI._show_progress
2527 Ethon::Curl.set_option(:noprogress, false, easy.handle)
26-
2728 else
2829 Ethon::Curl.set_option(:noprogress, true, easy.handle)
2930 end
31+
32+ if OSDN::CLI._rate_limit
33+ Ethon::Curl.set_option(:max_send_speed_large, OSDN::CLI._rate_limit, easy.handle)
34+ Ethon::Curl.set_option(:max_recv_speed_large, OSDN::CLI._rate_limit, easy.handle)
35+ end
36+
3037 easy
3138 end
3239 end
Show on old repository browser