mtik 3.1.0 → 3.1.1

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.
Files changed (4) hide show
  1. data/README.txt +11 -2
  2. data/VERSION.txt +1 -1
  3. data/examples/tikfetch.rb +40 -12
  4. metadata +6 -4
data/README.txt CHANGED
@@ -34,6 +34,10 @@ Additional documentation is available at
34
34
  * http://www.aarongifford.com/computers/mtik/
35
35
  * http://wiki.mikrotik.com/wiki/API_Ruby_class
36
36
 
37
+ Source code is available on GitHub:
38
+
39
+ * http://www.github.com/astounding/mtik/
40
+
37
41
  For documentation on the MikroTik RouterOS APi, see
38
42
 
39
43
  * http://wiki.mikrotik.com/wiki/API
@@ -53,8 +57,13 @@ under a BSD-style license. (See the LICENSE.txt file.)
53
57
 
54
58
  == Report Bugs
55
59
 
56
- Please report bugs by going to the author's web site and clicking on the
57
- "Contact Me" link in the left-hand menu. The direct URL is:
60
+ Bugs/issues may also be reported via GitHub:
61
+
62
+ * http://www.github.com/astounding/mtik/issues/
63
+
64
+ ALSO, please send the author a note regarding the issue by clicking on the
65
+ "Contact Me" link in the left-hand menu of the author's web site.
66
+ The direct URL is:
58
67
 
59
68
  * http://www.aarongifford.com/leaveanote.html
60
69
 
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
@@ -44,8 +44,8 @@ require 'mtik'
44
44
  ## output of all API interactions:
45
45
  #MTik::verbose = true
46
46
 
47
- if ARGV.length < 5 || ARGV.length % 2 != 1
48
- print "Usage: #{$0} <device> <user> <pass> <url> <localfilename> [<url> <localfilename>...]\n"
47
+ if ARGV.length < 4
48
+ print "Usage: #{$0} <device> <user> <pass> <url> [<localfilename> [<url> [<localfilename> ... ]]]\n"
49
49
  exit
50
50
  end
51
51
 
@@ -55,7 +55,7 @@ pass = ARGV.shift
55
55
  begin
56
56
  mt = MTik::Connection.new(:host=>host, :user=>user, :pass=>pass)
57
57
  rescue Errno::ETIMEDOUT, Errno::ENETUNREACH, Errno::EHOSTUNREACH, MTik::Error => e
58
- print ">>> ERROR CONNECTING: #{e}"
58
+ print ">>> ERROR CONNECTING: #{e}\n"
59
59
  exit
60
60
  end
61
61
 
@@ -68,27 +68,55 @@ mt.get_reply_each('/file/getall') do |req, s|
68
68
  end
69
69
 
70
70
  while ARGV.length > 0
71
- url, filename = ARGV.shift, ARGV.shift
71
+ url = ARGV.shift
72
+ if ARGV.length > 0
73
+ filename = ARGV.shift
74
+ else
75
+ filename = File.basename(url)
76
+ end
72
77
  if files.key?(filename)
73
78
  print ">>> ERROR: There is a file named '#{filename}' already on the device.\n"
74
79
  else
75
80
  print ">>> OK: Fetching file '#{filename}' from URL '#{url}'...\n"
81
+ oldbytes = 0
82
+ totalbytes = nil
83
+ oldtime = starttime = Time.now
76
84
  mt.fetch(url, filename, 120) do |status, total, bytes, req|
85
+ now = Time.now
77
86
  case status
78
- when 'failed'
79
- print ">>> ERROR: File '#{filename}' download failed!\n"
80
- when 'finished'
81
- print ">>> OK: File '#{filename}' download finished.\n"
82
87
  when 'connecting'
88
+ starttime = now
83
89
  print ">>> OK: Connecting to '#{url}' to download file '#{filename}'\n"
90
+ when 'requesting'
91
+ starttime = now
92
+ print ">> OK: Connected. Sending request for '#{filename}'...\n"
84
93
  when 'downloading'
85
- print ">>> OK: Downloaded #{bytes} bytes of #{total} of file " +
86
- "'#{filename}' " +
87
- (total > 0 ? '%0.2f' % (100.0*bytes/total) : '0') +
88
- "%\n"
94
+ # Unfortunately, the 'total' parameter is only valid for a
95
+ # 'downloading' status update, so we save the value.
96
+ totalbytes = total if totalbytes.nil?
97
+ print (
98
+ ">>> OK: Downloaded #{bytes} KB of #{total} KB " +
99
+ '(%0.2f KBps, %0.2f avgKBps) of ' +
100
+ "'#{filename}' " +
101
+ (total > 0 ? '%0.2f' % (100.0*bytes/total) : '0') +
102
+ '%%' + (oldbytes == bytes ? ' *STALLED*' : '') + "\n"
103
+ ) % [(bytes-oldbytes)/(now-oldtime), bytes/(now-starttime)]
104
+ oldbytes = bytes
105
+ when 'finished'
106
+ unless totalbytes.nil?
107
+ print (
108
+ ">>> OK: Downloaded #{totalbytes} KB of #{totalbytes} KB " +
109
+ '(%0.2f KBps, %0.2f avgKBps) of ' +
110
+ "'#{filename}' 100.00%%\n"
111
+ ) % [(totalbytes-oldbytes)/(now-oldtime), totalbytes/(now-starttime)]
112
+ end
113
+ print ">>> OK: File '#{filename}' download finished in #{'%0.2f' % [now-starttime]} seconds.\n"
114
+ when 'failed'
115
+ print ">>> ERROR: File '#{filename}' download failed!\n"
89
116
  else
90
117
  print ">>> ERROR: The following trap error occured: #{status}\n"
91
118
  end
119
+ oldtime = now
92
120
  end
93
121
  end
94
122
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 1
8
- - 0
9
- version: 3.1.0
8
+ - 1
9
+ version: 3.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron D. Gifford
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-23 00:00:00 -06:00
17
+ date: 2010-12-30 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -53,6 +53,7 @@ rdoc_options: []
53
53
  require_paths:
54
54
  - lib
55
55
  required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
56
57
  requirements:
57
58
  - - ">="
58
59
  - !ruby/object:Gem::Version
@@ -60,6 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
61
  - 0
61
62
  version: "0"
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
63
65
  requirements:
64
66
  - - ">="
65
67
  - !ruby/object:Gem::Version
@@ -69,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  requirements: []
70
72
 
71
73
  rubyforge_project: mtik
72
- rubygems_version: 1.3.6
74
+ rubygems_version: 1.3.7
73
75
  signing_key:
74
76
  specification_version: 3
75
77
  summary: MTik implements the MikroTik RouterOS API for use in Ruby.