hive-runner-android 1.1.6 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2aae14ef832b9ea895f4bb1029c0b923e65614f8
4
- data.tar.gz: 4ba623a934d783c2ea3d54e04e6f9098ccfc2921
3
+ metadata.gz: 386102f5f6c6fca8095d765453cb5bf8dbb356ab
4
+ data.tar.gz: c0dcd7026a3e84b03ae6ccec86e45a6747170d2f
5
5
  SHA512:
6
- metadata.gz: f50c6fe8a8b917f156e71b3571dafaa657085b27559a46c15d628441523333d3dbc066a69c6dc1d1a7a14567db4b08b21732a45313061152214c3012d5e1d46e
7
- data.tar.gz: 2ce15dc130d09fa7242c5ef590fc24b10a99fee4a2332ed0d669895cc7d70bd7dddaa7de35da79b30f1d5154b090d11df32d64555e5234280592817a507222e8
6
+ metadata.gz: 68a40b5c250516ac13a743d63c47ffe6c8ef2c288ad65d56b918a5bd7aadc32703b3278e511f175d9a40bd5e2f30e3cc89c260c6db58bfcdba166ae25c0d331b
7
+ data.tar.gz: c7be9e055cdab4e07402d0fb6614b8771f04da55d613cbb98e68537589606acda2c9d0b8aadaa00943423ad613e21730dd9306905a7700ac0561ed688cec638e
@@ -8,7 +8,6 @@ module Hive
8
8
 
9
9
  def detect
10
10
  self.detect_hive_mind
11
- self.detect_devicedb
12
11
  end
13
12
 
14
13
  # Register with Hive Mind (New)
@@ -97,111 +96,6 @@ module Hive
97
96
  attached_devices
98
97
  end
99
98
 
100
- # Register with DeviceDB (Old)
101
- def detect_devicedb
102
- devices = DeviceAPI::Android.devices
103
- Hive.logger.debug('No devices attached') if devices.empty?
104
- Hive.logger.debug("#{Time.now} Retrieving hive details")
105
- hive_details = Hive.devicedb('Hive').find(Hive.id)
106
- Hive.logger.debug("#{Time.now} Finished fetching hive details")
107
- attached_devices = []
108
-
109
- if hive_details.key?('devices')
110
- # Update the 'cached' results from DeviceDB
111
- @hive_details = hive_details
112
- else
113
- # DeviceDB isn't available - use the cached version
114
- hive_details = @hive_details
115
- end
116
-
117
- if hive_details.is_a? Hash
118
- # DeviceDB information is available, use it
119
- hive_details['devices'].select {|a| a['os'] == 'android'}.each do |device|
120
- registered_device = devices.select { |a| a.serial == device['serial'] && a.status != :unauthorized && a.status != :no_permissions }
121
- if registered_device.empty?
122
- # A previously registered device isn't attached
123
- Hive.logger.debug("HM) A previously registered device has disappeared: #{device}")
124
- else
125
- # A previously registered device is attached, poll it
126
- Hive.logger.debug("#{Time.now} Polling attached device - #{device}")
127
- Hive.devicedb('Device').poll(device['id'])
128
- Hive.logger.debug("#{Time.now} Finished polling device")
129
-
130
- devices = devices - registered_device
131
- begin
132
- attached_devices <<
133
- self.create_device(device.merge(
134
- 'os_version' => registered_device[0].version,
135
- 'model' => device['device_model'],
136
- 'brand' => device['device_brand'],
137
- 'queues' => device['device_queues'].map{ |d| d['name'] },
138
- 'queue_prefix' => @config['queue_prefix']
139
- ))
140
- rescue DeviceAPI::DeviceNotFound
141
- Hive.logger.info("Device '#{device['serial']}' disconnected during registration")
142
- rescue => e
143
- Hive.logger.warn("Error with connected device: #{e.message}")
144
- end
145
- end
146
- end
147
-
148
- devices.each do |device|
149
- register_new_device(device)
150
- end
151
-
152
- display_devices(hive_details)
153
- else
154
- # DeviceDB isn't available, use DeviceAPI instead
155
-
156
- device_info = devices.select { |a| a.status != :unauthorized && a.status != :no_permissions }.map do |device|
157
- {
158
- 'id' => device.serial,
159
- 'serial' => device.serial,
160
- 'status' => 'idle',
161
- 'model' => device.model,
162
- 'brand' => device.manufacturer,
163
- 'os_version' => device.version,
164
- 'queue_prefix' => @config['queue_prefix']
165
- }
166
- end
167
-
168
- attached_devices = device_info.collect do |physical_device|
169
- self.create_device(physical_device)
170
- end
171
- end
172
- attached_devices
173
- end
174
-
175
- def register_new_device(device)
176
- begin
177
- Hive.logger.info("Adding new Android device: #{device.model}")
178
-
179
- attributes = {
180
- os: 'android',
181
- os_version: device.version,
182
- serial: device.serial,
183
- device_type: 'mobile',
184
- device_model: device.model,
185
- device_brand: device.manufacturer,
186
- device_range: device.range,
187
- hive: Hive.id
188
- }
189
- rescue DeviceAPI::DeviceNotFound
190
- Hive.logger.info("Device '#{device.serial}' disconnected during registration")
191
- rescue DeviceAPI::UnauthorizedDevice
192
- Hive.logger.info("Device '#{device.serial}' is unauthorized")
193
- rescue DeviceAPI::Android::ADBCommandError
194
- # If a device has been disconnected while we're trying to add it, the device_api
195
- # gem will throw an error
196
- Hive.logger.debug('Device disconnected while attempting to add')
197
- rescue => e
198
- Hive.logger.warn("Error with connected device: #{e.message}")
199
- end
200
-
201
- registration = Hive.devicedb('Device').register(attributes)
202
- Hive.devicedb('Device').hive_connect(registration['id'], Hive.id)
203
- end
204
-
205
99
  def display_devices(hive_details)
206
100
  rows = []
207
101
  if hive_details.key?('devices')
@@ -11,50 +11,8 @@ module Hive
11
11
  @model = config['model'].downcase.gsub(/\s/, '_')
12
12
  @brand = config['brand'].downcase.gsub(/\s/, '_')
13
13
  @os_version = config['os_version']
14
-
15
- # TODO The setting of config['queues'] can be removed when DeviceDB
16
- # is no longer being used
17
- new_queues = calculate_queue_names
18
- new_queues = new_queues | config['queues'] if config.has_key?('queues')
19
-
20
- devicedb_ids = new_queues.map { |queue| find_or_create_queue(queue) }
21
- Hive.devicedb('Device').edit(@identity, { device_queue_ids: devicedb_ids })
22
- config['queues'] = new_queues
23
-
24
14
  super
25
15
  end
26
-
27
- # Uses either DeviceAPI or DeviceDB to generate queue names for a device
28
- # TODO Remove when DeviceDB is not being used any more
29
- def calculate_queue_names
30
- [
31
- "#{@queue_prefix}#{self.model}",
32
- "#{@queue_prefix}#{self.brand}",
33
- "#{@queue_prefix}android",
34
- "#{@queue_prefix}android-#{self.os_version}",
35
- "#{@queue_prefix}android-#{self.os_version}-#{self.model}"
36
- ]
37
- end
38
-
39
- private
40
-
41
- def find_or_create_queue(name)
42
- queue = Hive.devicedb('Queue').find_by_name(name)
43
-
44
- return queue.first['id'] unless queue.empty? || queue.is_a?(Hash)
45
-
46
- queue = create_queue(name, "#{name} queue created by Hive Runner")
47
- queue['id'] unless queue.empty?
48
- end
49
-
50
- def create_queue(name, description)
51
- queue_attributes = {
52
- name: name,
53
- description: description
54
- }
55
-
56
- Hive.devicedb('Queue').register(device_queue: queue_attributes)
57
- end
58
16
  end
59
17
  end
60
18
  end
@@ -20,17 +20,18 @@ module Hive
20
20
  attr_accessor :device
21
21
 
22
22
  def initialize(device)
23
+ @serial = device['serial']
23
24
  @queue_prefix = device['queue_prefix'].to_s == '' ? '' : "#{device['queue_prefix']}-"
24
25
  @model = device['model'].downcase.gsub(/\s/, '_')
25
26
  @brand = device['brand'].downcase.gsub(/\s/, '_')
26
27
  @os_version = device['os_version']
27
28
  @worker_ports = PortReserver.new
28
29
  begin
29
- device.merge!({"device_api" => DeviceAPI::Android.device(device['serial'])})
30
+ device.merge!({"device_api" => DeviceAPI::Android.device(@serial)})
30
31
  rescue DeviceAPI::DeviceNotFound
31
- Hive.logger.info("Device '#{device['serial']}' disconnected during initialization")
32
+ Hive.logger.info("Device '#{@serial}' disconnected during initialization")
32
33
  rescue DeviceAPI::UnauthorizedDevice
33
- Hive.logger.info("Device '#{device['serial']}' is unauthorized")
34
+ Hive.logger.info("Device '#{@serial}' is unauthorized")
34
35
  rescue DeviceAPI::Android::ADBCommandError
35
36
  Hive.logger.info("Device disconnected during worker initialization")
36
37
  rescue => e
@@ -85,30 +86,13 @@ module Hive
85
86
  set_device_status('idle')
86
87
  end
87
88
 
88
- def device_status
89
- # TODO Get from Hive Mind
90
- details = Hive.devicedb('Device').find(@options['id'])
91
- if details.key?('status')
92
- @state = details['status']
93
- else
94
- @state
95
- end
96
- end
89
+ #def device_status
90
+ # # TODO Get from Hive Mind
91
+ #end
97
92
 
98
- def set_device_status(status)
99
- # TODO Report to Hive Mind
100
- @state = status
101
- begin
102
- details = Hive.devicedb('Device').poll(@options['id'], status)
103
- if details.key?('status')
104
- details['status']
105
- else
106
- @state
107
- end
108
- rescue
109
- @state
110
- end
111
- end
93
+ #def set_device_status(status)
94
+ # # TODO Report to Hive Mind
95
+ #end
112
96
 
113
97
  def autogenerated_queues
114
98
  @log.info("Autogenerating queues")
@@ -123,7 +107,7 @@ module Hive
123
107
 
124
108
  def hive_mind_device_identifiers
125
109
  {
126
- serial: @device_id,
110
+ serial: @serial,
127
111
  device_type: 'Mobile'
128
112
  }
129
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-runner-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: device_api-android
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.5
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.5
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: terminal-table
43
43
  requirement: !ruby/object:Gem::Requirement