da_funk 0.4.19 → 0.4.20
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/RELEASE_NOTES.md +15 -0
- data/Rakefile +0 -1
- data/lib/da_funk/helper.rb +9 -0
- data/lib/da_funk/rake_task.rb +5 -1
- data/lib/da_funk/screen.rb +13 -11
- data/lib/device/display.rb +2 -1
- data/lib/device/notification.rb +53 -16
- data/lib/device/params_dat.rb +16 -12
- data/lib/device/setting.rb +4 -3
- data/lib/device/version.rb +1 -1
- data/lib/ext/string.rb +4 -0
- data/lib/serfx/commands.rb +2 -2
- data/lib/serfx/connection.rb +5 -1
- data/test/test_helper.rb +2 -2
- data/test/unit/device/display_test.rb +33 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62c2f815b4a2aac3e8a15cf969b0f9d7ce842140
|
4
|
+
data.tar.gz: 0d585d8bf8eec09129472b764119775a91ad290a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ed08db806c6b47c2845c9dbca87c021b3a3256b00b0dd81261e2ad06437d594840a44299d8860b600a63ebfb51d2f428bb4a21ac33b6ba51d9e7723e562b978
|
7
|
+
data.tar.gz: 1ec0cd499e3221a80d0537949c77939294ac2bdbb68dde23364e1adfa42d55337ca2539a8364316f0349cb9758b74c26478155d516ce104849cbdf3ce9bec5cc
|
data/Gemfile.lock
CHANGED
@@ -7,7 +7,7 @@ GIT
|
|
7
7
|
PATH
|
8
8
|
remote: .
|
9
9
|
specs:
|
10
|
-
da_funk (0.4.
|
10
|
+
da_funk (0.4.20)
|
11
11
|
bundler (~> 1.7)
|
12
12
|
cloudwalk_handshake (~> 0.4)
|
13
13
|
rake (~> 10.4)
|
@@ -16,7 +16,7 @@ PATH
|
|
16
16
|
GEM
|
17
17
|
remote: https://rubygems.org/
|
18
18
|
specs:
|
19
|
-
cloudwalk_handshake (0.4.
|
19
|
+
cloudwalk_handshake (0.4.11)
|
20
20
|
rake (10.4.2)
|
21
21
|
yard (0.8.7.6)
|
22
22
|
|
data/RELEASE_NOTES.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# DaFunk
|
2
2
|
|
3
|
+
### 0.4.20 - 2015-12-10 - Refactoring Notification
|
4
|
+
- Implement try method on helper to be use on by communication tries.
|
5
|
+
- Serfx#auth now receives the authentication key as a parameter too, so that could be called externally in a determined moment, example TOTP authentication on the right moment (after socket open, avoiding authentication problems).
|
6
|
+
- Treat authentication error clearing cw_pos_timezone to perform entire handshake on next time.
|
7
|
+
- Make Device::Display.print call STDOUT.print if row and column are not sent.
|
8
|
+
- On Device::Display#clear call STDOUT.fresh to change the Screen state to 0(x and y).
|
9
|
+
- Refactor download of file on ParamsDat to implement method try, adopted initially 3 times.
|
10
|
+
- On Screen.setup define STDOUT on Object, instead of Kernel.
|
11
|
+
- Update cloudwalk_handshake to version 0.4.11.
|
12
|
+
- Fix Screen jump line to not jump before print if size is less than max_x.
|
13
|
+
- Support to keep alive Notifications restarting in intervals.
|
14
|
+
- On Notification Callback to display message use `getc(0)` (wait a key to be pressed forever) instead of getc(nil) (wait a key to be pressed in default time.
|
15
|
+
- Implement String#chars extension.
|
16
|
+
- Support to execute a unique file test, example: `rake test test/unit/file_test.rb`.
|
17
|
+
|
3
18
|
### 0.4.19 - 2015-12-04 - Refactoring Device::Setting.to_production!/.to_staging!
|
4
19
|
- Implement FileDb#update_attributes to update more than one key in a unique save.
|
5
20
|
- Refactoring Device::Setting.to_production!/.to_staging! to clean company_name if the last environment is different.
|
data/Rakefile
CHANGED
data/lib/da_funk/helper.rb
CHANGED
data/lib/da_funk/rake_task.rb
CHANGED
data/lib/da_funk/screen.rb
CHANGED
@@ -5,10 +5,10 @@ class Screen
|
|
5
5
|
|
6
6
|
attr_accessor :x, :y, :max_x, :max_y
|
7
7
|
|
8
|
-
def self.setup(max_x, max_y)
|
8
|
+
def self.setup(max_x = SCREEN_X_SIZE, max_y = SCREEN_Y_SIZE)
|
9
9
|
$stdout.close
|
10
|
-
|
11
|
-
$stdout =
|
10
|
+
Object.const_set(:STDOUT, self.new(max_x, max_y))
|
11
|
+
$stdout = Object::STDOUT
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(max_x = SCREEN_X_SIZE, max_y = SCREEN_Y_SIZE)
|
@@ -17,7 +17,7 @@ class Screen
|
|
17
17
|
self.fresh
|
18
18
|
end
|
19
19
|
|
20
|
-
def fresh(value_y =
|
20
|
+
def fresh(value_y = 0, value_x = 0)
|
21
21
|
@x = value_x || 0
|
22
22
|
@y = value_y || 0
|
23
23
|
end
|
@@ -53,16 +53,18 @@ class Screen
|
|
53
53
|
private
|
54
54
|
def loop_split_strings(*args)
|
55
55
|
str, value_y, value_x = *args
|
56
|
+
@y = value_y if value_y
|
57
|
+
@x = value_x if value_x
|
56
58
|
|
57
|
-
str.lines.each_with_index do |string, index|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
str.to_s.lines.each_with_index do |string, index|
|
60
|
+
buf = string.chomp
|
61
|
+
if (@x + buf.size) < @max_x
|
62
|
+
Device::Display.print(buf, @y, @x)
|
63
|
+
@x += buf.size
|
64
|
+
jump_line if string[-1] == "\n"
|
63
65
|
else
|
64
66
|
space = @max_x - @x
|
65
|
-
Device::
|
67
|
+
Device::Display.print("#{string[0..(space - 1)]}", @y, @x)
|
66
68
|
jump_line
|
67
69
|
loop_split_strings("#{string[(space)..-1]}")
|
68
70
|
end
|
data/lib/device/display.rb
CHANGED
@@ -12,7 +12,7 @@ class Device
|
|
12
12
|
# @return [NilClass] nil.
|
13
13
|
def self.print(buf, row = nil, column = nil)
|
14
14
|
if row.nil? && column.nil?
|
15
|
-
|
15
|
+
STDOUT.print(buf)
|
16
16
|
else
|
17
17
|
adapter.print_in_line(buf, row, column)
|
18
18
|
end
|
@@ -38,6 +38,7 @@ class Device
|
|
38
38
|
# @param line [Fixnum] Line to clear
|
39
39
|
def self.clear(line = nil)
|
40
40
|
if line.nil?
|
41
|
+
STDOUT.fresh
|
41
42
|
adapter.clear
|
42
43
|
else
|
43
44
|
adapter.clear_line line
|
data/lib/device/notification.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
|
1
2
|
class Device
|
2
3
|
class Notification
|
3
|
-
DEFAULT_TIMEOUT
|
4
|
-
DEFAULT_INTERVAL
|
5
|
-
DEFAULT_STREAM_TIMEOUT
|
4
|
+
DEFAULT_TIMEOUT = 20
|
5
|
+
DEFAULT_INTERVAL = 10
|
6
|
+
DEFAULT_STREAM_TIMEOUT = 0
|
7
|
+
DEFAULT_CREATION_INTERVAL = 3600
|
6
8
|
|
7
9
|
class << self
|
8
|
-
attr_accessor :callbacks, :current
|
10
|
+
attr_accessor :callbacks, :current, :last_creation, :creation_interval
|
9
11
|
end
|
10
12
|
|
11
13
|
self.callbacks = Hash.new
|
14
|
+
self.creation_interval = DEFAULT_CREATION_INTERVAL
|
12
15
|
|
13
16
|
attr_reader :fiber, :timeout, :interval, :last_check, :stream_timeout
|
14
17
|
|
@@ -30,6 +33,7 @@ class Device
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def self.config
|
36
|
+
self.creation_interval = Device::Setting.notification_socket_timeout.empty? ? DEFAULT_CREATION_INTERVAL : Device::Setting.notification_socket_timeout.to_i
|
33
37
|
notification_timeout = Device::Setting.notification_timeout.empty? ? DEFAULT_TIMEOUT : Device::Setting.notification_timeout.to_i
|
34
38
|
notification_interval = Device::Setting.notification_interval.empty? ? DEFAULT_INTERVAL : Device::Setting.notification_interval.to_i
|
35
39
|
notification_stream_timeout = Device::Setting.notification_stream_timeout.empty? ? DEFAULT_STREAM_TIMEOUT : Device::Setting.notification_stream_timeout.to_i
|
@@ -37,7 +41,7 @@ class Device
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def self.start
|
40
|
-
|
44
|
+
if create_fiber? && Device::Network.connected?
|
41
45
|
unless Device::Notification.current && Device::Notification.current.closed?
|
42
46
|
self.new(*self.config)
|
43
47
|
end
|
@@ -57,10 +61,22 @@ class Device
|
|
57
61
|
date = datetime.sub(" ", "-").split("-")
|
58
62
|
Device::Display.print_line("#{date[1]}/#{date[0]}/#{date[2]} #{date[3]}", 0)
|
59
63
|
Device::Display.print_line("#{message}", 2)
|
60
|
-
getc
|
64
|
+
getc(0)
|
61
65
|
}
|
62
66
|
end
|
63
67
|
|
68
|
+
def self.create_fiber?
|
69
|
+
(! Device::Setting.company_name.empty?) && (! Device::Setting.logical_number.empty?) && self.valid_creation_interval?
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.valid_creation_interval?
|
73
|
+
if @last_creation
|
74
|
+
(@last_creation + self.creation_interval) < Time.now
|
75
|
+
else
|
76
|
+
true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
64
80
|
def initialize(timeout = DEFAULT_TIMEOUT, interval = DEFAULT_INTERVAL, stream_timeout = DEFAULT_STREAM_TIMEOUT)
|
65
81
|
@timeout = timeout
|
66
82
|
@stream_timeout = stream_timeout
|
@@ -71,24 +87,34 @@ class Device
|
|
71
87
|
|
72
88
|
# Check if there is any notification
|
73
89
|
def check
|
74
|
-
if
|
75
|
-
if
|
76
|
-
|
90
|
+
if valid_check_interval? && Device::Network.connected?
|
91
|
+
if @fiber.alive?
|
92
|
+
if (notification = @fiber.resume)
|
93
|
+
Notification.execute(NotificationEvent.new(notification))
|
94
|
+
end
|
95
|
+
@last_check = Time.now
|
96
|
+
if Device::Notification.create_fiber?
|
97
|
+
self.close
|
98
|
+
@fiber = create_fiber
|
99
|
+
end
|
77
100
|
end
|
78
|
-
@last_check = Time.now
|
79
101
|
end
|
80
102
|
end
|
81
103
|
|
82
104
|
# Close socket and finish Fiber execution
|
83
105
|
def close
|
84
|
-
|
106
|
+
if closed?
|
107
|
+
true
|
108
|
+
else
|
109
|
+
! @fiber.resume "close"
|
110
|
+
end
|
85
111
|
end
|
86
112
|
|
87
113
|
def closed?
|
88
114
|
! @fiber.alive?
|
89
115
|
end
|
90
116
|
|
91
|
-
def
|
117
|
+
def valid_check_interval?
|
92
118
|
if @last_check
|
93
119
|
(@last_check + self.interval) < Time.now
|
94
120
|
else
|
@@ -107,16 +133,27 @@ class Device
|
|
107
133
|
end
|
108
134
|
end
|
109
135
|
|
136
|
+
def check_errors(exception)
|
137
|
+
case exception.message
|
138
|
+
when "Invalid authentication token"
|
139
|
+
Device::Setting.cw_pos_timezone = "" # Clear timezone if authentication error
|
140
|
+
when "Socket closed"
|
141
|
+
else
|
142
|
+
end
|
143
|
+
false
|
144
|
+
end
|
145
|
+
|
110
146
|
def create_fiber
|
111
147
|
Fiber.new do
|
112
148
|
begin
|
113
|
-
|
114
|
-
|
149
|
+
Serfx.connect(socket_block: Device::Network.socket, timeout: timeout, stream_timeout: stream_timeout) do |conn|
|
150
|
+
conn.auth(CloudwalkTOTP.at)
|
151
|
+
Device::Notification.last_creation = Time.now
|
115
152
|
conn.stream(subscription) { |ev| reply(conn, ev) }
|
116
153
|
end
|
117
154
|
true
|
118
|
-
rescue =>
|
119
|
-
|
155
|
+
rescue Serfx::RPCError => exception
|
156
|
+
check_errors(exception)
|
120
157
|
end
|
121
158
|
end
|
122
159
|
end
|
data/lib/device/params_dat.rb
CHANGED
@@ -46,13 +46,14 @@ class Device
|
|
46
46
|
|
47
47
|
def self.download
|
48
48
|
if attach
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
value = try(3) do |tried|
|
50
|
+
Device::Display.clear
|
51
|
+
puts "Downloading (#{tried})"
|
52
|
+
puts "Parameters"
|
53
|
+
ret = Device::Transaction::Download.request_param_file(FILE_NAME)
|
54
|
+
check_download_error(ret)
|
55
55
|
end
|
56
|
+
parse_apps if value
|
56
57
|
value
|
57
58
|
end
|
58
59
|
end
|
@@ -79,12 +80,15 @@ class Device
|
|
79
80
|
|
80
81
|
def self.update_app(application)
|
81
82
|
if attach && application
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
try(3) do |tried|
|
84
|
+
Device::Display.clear
|
85
|
+
puts "Downloading (#{tried})"
|
86
|
+
puts "#{application.file}..."
|
87
|
+
ret = Device::Transaction::Download.request_file(application.file, application.zip)
|
88
|
+
|
89
|
+
ret = check_download_error(ret)
|
90
|
+
sleep(1)
|
91
|
+
ret
|
88
92
|
end
|
89
93
|
end
|
90
94
|
end
|
data/lib/device/setting.rb
CHANGED
@@ -29,9 +29,10 @@ class Device
|
|
29
29
|
"logical_number" => "",
|
30
30
|
"network_configured" => "",
|
31
31
|
"environment" => "",
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"
|
32
|
+
"notification_socket_timeout" => "", # Period to create fiber
|
33
|
+
"notification_timeout" => "", # Time to wait message to read
|
34
|
+
"notification_interval" => "", # Check interval
|
35
|
+
"notification_stream_timeout" => "", # Time to wait stream message to read
|
35
36
|
"cw_switch_version" => "",
|
36
37
|
"cw_pos_timezone" => "",
|
37
38
|
"uclreceivetimeout" => "0",
|
data/lib/device/version.rb
CHANGED
data/lib/ext/string.rb
CHANGED
data/lib/serfx/commands.rb
CHANGED
@@ -15,8 +15,8 @@ module Serfx
|
|
15
15
|
# `auth` has to be second command, immediately after `handshake`.
|
16
16
|
#
|
17
17
|
# @return [Response]
|
18
|
-
def auth
|
19
|
-
tcp_send(:auth, 'AuthKey' =>
|
18
|
+
def auth(key = @authkey)
|
19
|
+
tcp_send(:auth, 'AuthKey' => key)
|
20
20
|
read_response(:auth)
|
21
21
|
end
|
22
22
|
# fires an user event
|
data/lib/serfx/connection.rb
CHANGED
@@ -65,6 +65,7 @@ module Serfx
|
|
65
65
|
def read_data(read_timeout = self.timeout)
|
66
66
|
buf = read_buffer(read_timeout)
|
67
67
|
return if buf.nil?
|
68
|
+
return {'Error' => "Socket closed"} if buf.empty?
|
68
69
|
parse_package(buf)
|
69
70
|
end
|
70
71
|
|
@@ -83,6 +84,7 @@ module Serfx
|
|
83
84
|
loop do
|
84
85
|
bytes = socket.bytes_available
|
85
86
|
return socket.read(bytes) if bytes > 0
|
87
|
+
return socket.recv_nonblock(bytes) if bytes > 0
|
86
88
|
break unless time_timeout > Time.now
|
87
89
|
sleep 1
|
88
90
|
end
|
@@ -103,10 +105,12 @@ module Serfx
|
|
103
105
|
'Command' => command.to_s.gsub('_', '-'),
|
104
106
|
'Seq' => seq
|
105
107
|
}
|
108
|
+
|
106
109
|
buff = MessagePack::Packer.new
|
107
110
|
buff.write(header)
|
108
111
|
buff.write(body) unless body.nil?
|
109
|
-
|
112
|
+
|
113
|
+
res = socket.write(buff.to_str) unless buff.to_str.empty?
|
110
114
|
@requests[seq] = { header: header, ack?: false }
|
111
115
|
seq
|
112
116
|
end
|
data/test/test_helper.rb
CHANGED
@@ -51,13 +51,27 @@ class DisplayTest < DaFunk::Test.case
|
|
51
51
|
assert_equal 3, $stdout.y
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_kernel_print_small
|
55
|
+
$stdout.fresh
|
56
|
+
assert_equal nil, print("1234")
|
57
|
+
assert_equal 4, $stdout.x
|
58
|
+
assert_equal 0, $stdout.y
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_kernel_puts_small
|
62
|
+
$stdout.fresh
|
63
|
+
assert_equal nil, puts("1234")
|
64
|
+
assert_equal 0, $stdout.x
|
65
|
+
assert_equal 1, $stdout.y
|
66
|
+
end
|
67
|
+
|
54
68
|
def test_kernel_puts_string_20_plus_1
|
55
69
|
$stdout.fresh
|
56
|
-
assert_equal nil,
|
70
|
+
assert_equal nil, print("12345678901234567890")
|
57
71
|
assert_equal 20, $stdout.x
|
58
|
-
assert_equal
|
72
|
+
assert_equal 0, $stdout.y
|
59
73
|
assert_equal nil, puts("1")
|
60
|
-
assert_equal
|
74
|
+
assert_equal 0, $stdout.x
|
61
75
|
assert_equal 2, $stdout.y
|
62
76
|
end
|
63
77
|
|
@@ -71,15 +85,29 @@ class DisplayTest < DaFunk::Test.case
|
|
71
85
|
def test_kernel_puts_string_43
|
72
86
|
$stdout.fresh
|
73
87
|
assert_equal nil, puts("1234567890123456789012345678901234567890123")
|
74
|
-
assert_equal
|
88
|
+
assert_equal 0, $stdout.x
|
75
89
|
assert_equal 3, $stdout.y
|
76
90
|
end
|
77
91
|
|
92
|
+
def test_kernel_print_string_43
|
93
|
+
$stdout.fresh
|
94
|
+
assert_equal nil, print("1234567890123456789012345678901234567890123")
|
95
|
+
assert_equal 1, $stdout.x
|
96
|
+
assert_equal 2, $stdout.y
|
97
|
+
end
|
98
|
+
|
78
99
|
def test_kernel_puts_string_22
|
79
100
|
$stdout.fresh
|
80
101
|
assert_equal nil, puts("1234567890123456789012")
|
81
|
-
assert_equal
|
102
|
+
assert_equal 0, $stdout.x
|
82
103
|
assert_equal 2, $stdout.y
|
83
104
|
end
|
105
|
+
|
106
|
+
def test_kernel_print_string_22
|
107
|
+
$stdout.fresh
|
108
|
+
assert_equal nil, print("1234567890123456789012")
|
109
|
+
assert_equal 1, $stdout.x
|
110
|
+
assert_equal 1, $stdout.y
|
111
|
+
end
|
84
112
|
end
|
85
113
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: da_funk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Scalone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|