hive-runner-ios 1.0.4 → 1.0.5

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: ce087ae313abd13cd813dbe4daeb1ea5625204fd
4
- data.tar.gz: b47a160b3ffd69983f161f698b6489055f8f235f
3
+ metadata.gz: 724ac50af05ee7cdf94198938276fa1eb6374c31
4
+ data.tar.gz: 8f897659dc07f39f4e071e115c0e7617c06a7d63
5
5
  SHA512:
6
- metadata.gz: 5d05cd92afb44b5705ce03eff687ece524d76af0f0849e9f1fbda7816d947d2083d8c35fe5268ae877675bb4d4f558eff226dc5e34fbaaf23c301a8b63606906
7
- data.tar.gz: c47b32076c5e5593f0763cec1bddefcc37fb6a49ec94ec15489b9b017fd195f981060f210d5289a1ca11ba4565210e46b07badaf55cf64cefea5f0fcdbc2eef7
6
+ metadata.gz: 5b20456eec211381c47d40d46a737c237ead2d3100f49335bc91ba94de5d0891a0d55368d9b501ad0ad90a21511b1ea5929028c572d1c6659c8e8e6a3fa5e646
7
+ data.tar.gz: e43af665ee189763161e30db5b9ee5f31b15e640622edf7da50d9f53473d0b4a6dc743b9c3ad15b26776b66ab75d5dc61182c482194cfad5f655a5571b25517b
@@ -6,97 +6,157 @@ module Hive
6
6
  class Controller
7
7
  class Ios < Controller
8
8
 
9
- def detect
10
- Hive.logger.debug("#{Time.now} Polling hive: #{Hive.id}")
11
- Hive.devicedb('Hive').poll(Hive.id)
12
- Hive.logger.debug("#{Time.now} Finished polling hive: #{Hive.id}")
9
+ def register_with_devicedb
13
10
  devices = DeviceAPI::IOS.devices
11
+ Hive.logger.debug('DDB: No devices attached') if devices.empty?
14
12
 
15
- Hive.logger.debug('No devices attached') if devices.empty?
16
- Hive.logger.debug("#{Time.now} Retrieving hive details")
17
13
  hive_details = Hive.devicedb('Hive').find(Hive.id)
18
- Hive.logger.debug("#{Time.now} Finished retrieving hive details")
19
14
 
20
- unless hive_details.key?('devices')
21
- Hive.logger.debug('Could not connect to DeviceDB at this time')
22
- return []
15
+ attached_devices = []
16
+
17
+ if hive_details.key?('devices')
18
+ @hive_details = hive_details
19
+ else
20
+ hive_details = @hive_details
23
21
  end
24
22
 
25
- unless hive_details['devices'].empty?
26
- hive_details['devices'].select {|a| a['os'] == 'ios'}.each do |device|
27
- registered_device = devices.select { |a| a.serial == device['serial'] }
23
+ if hive_details.is_a? Hash
24
+ hive_details['devices'].select { |a| a['os'] == 'ios'}.each do |device|
25
+ registered_device = devices.select { |a| a.serial == device['serial'] && a.trusted? }
28
26
  if registered_device.empty?
29
27
  # A previously registered device isn't attached
30
- Hive.logger.debug("Removing previously registered device - #{device}")
31
28
  Hive.devicedb('Device').hive_disconnect(device['id'])
32
29
  else
33
- # A previously registered device is attached, poll it
34
- Hive.logger.debug("#{Time.now} Polling attached device - #{device}")
35
30
  Hive.devicedb('Device').poll(device['id'])
36
- Hive.logger.debug("#{Time.now} Finished polling device - #{device}")
37
31
 
38
- populate_queues(device)
39
32
  devices = devices - registered_device
33
+
34
+ begin
35
+ attached_devices <<
36
+ self.create_device(device.merge(
37
+ 'os_version' => registered_device[0].version,
38
+ 'model' => device['device_model'],
39
+ 'device_range' => registered_device[0].device_class,
40
+ 'queues' => device['device_queues'].map{ |d| d['name'] },
41
+ 'queue_prefix' => @config['queue_prefix']
42
+ ))
43
+ rescue => e
44
+ Hive.logger.warn("Error with connected device: #{e.message}")
45
+ end
40
46
  end
41
47
  end
42
- end
43
-
44
- display_untrusted(devices)
45
- display_devices
46
-
47
- if hive_details.key?('devices')
48
- hive_details['devices'].select {|a| a['os'] == 'ios'}.collect do |device|
49
- object = Object
50
- @device_class.split('::').each { |sub| object = object.const_get(sub) }
51
- object.new(@config.merge(device))
48
+ devices.select {|a| a.trusted? }.each do |device|
49
+ register_new_device(device)
52
50
  end
53
51
  else
54
- []
52
+ # DeviceDB isn't available, use DeviceAPI instead
53
+ device_info = devices.select { |a| a.trusted? }.map do |device|
54
+ {
55
+ 'id' => device.serial,
56
+ 'serial' => device.serial,
57
+ 'status' => 'idle',
58
+ 'model' => device.model,
59
+ 'brand' => 'Apple',
60
+ 'os_version' => device.version,
61
+ 'queue_prefix' => @config['queue_prefix']
62
+ }
63
+ end
64
+
65
+ attached_devices = device_info.collect do |physical_device|
66
+ self.create_device(physical_device)
67
+ end
55
68
  end
69
+ attached_devices
56
70
  end
57
71
 
58
- def display_untrusted(devices)
59
- untrusted_devices = []
60
- # We will now have a list of devices that haven't previously been added
61
- devices.each do |device|
62
- begin
63
- if !device.trusted?
64
- untrusted_devices << device.serial
65
- next
72
+ def register_with_hivemind
73
+ devices = DeviceAPI::IOS.devices
74
+ Hive.logger.debug('HM: No devices attached') if devices.empty?
75
+
76
+ if not Hive.hive_mind.device_details.has_key? :error
77
+ connected_devices = Hive.hive_mind.device_details['connected_devices'].select{ |d| d['device_type'] == 'Mobile' && d['operating_system_name'] == 'ios' }
78
+
79
+ to_poll = []
80
+ attached_devices = []
81
+ connected_devices.each do |device|
82
+ Hive.logger.debug("HM: Device details: #{device.inspect}")
83
+ registered_device = devices.select { |a| a.serial == device['serial'] && a.trusted? }
84
+ if registered_device.empty?
85
+ Hive.logger.debug("HM: Removing previously registered device - #{device}")
86
+ Hive.hive_mind.disconnect(device['id'])
87
+ else
88
+ Hive.logger.debug("HM: Device #{device} to be polled")
89
+ begin
90
+ attached_devices << self.created_device(device.merge('os_version' => registered_device[0].version))
91
+ to_poll << device['id']
92
+ rescue => e
93
+ Hive.logger.warn("HM: Error with connected device: #{e.message}")
94
+ end
95
+
96
+ devices = devices - registered_device
66
97
  end
98
+ end
67
99
 
68
- register_new_device(device)
100
+ Hive.logger.debug("HM: Polling - #{to_poll}")
101
+ Hive.hive_mind.poll(*to_poll)
102
+
103
+ devices.select{|a| a.trusted? }.each do |device|
104
+ begin
105
+ dev = Hive.hive_mind.register(
106
+ hostname: device.model,
107
+ serial: device.serial,
108
+ macs: [device.wifi_mac_address],
109
+ brand: 'Apple',
110
+ model: device.model,
111
+ device_type: 'Mobile',
112
+ imei: device.imei,
113
+ operating_system_name: 'ios',
114
+ operating_system_version: device.version
115
+ )
116
+ Hive.hive_mind.connect(dev['id'])
117
+ Hive.logger.info("HM: Device registered: #{dev}")
118
+ rescue => e
119
+ Hive.logger.warn("HM: Error with connected device - #{e.message}")
120
+ end
121
+ end
122
+ else
123
+ Hive.logger.info('HM: No Hive Mind connection')
124
+ device_info = devices.select{|a| a.trusted? }.map do |device|
125
+ {
126
+ 'id' => device.serial,
127
+ 'serial' => device.serial,
128
+ 'status' => 'idle',
129
+ 'model' => device.model,
130
+ 'brand' => 'Apple',
131
+ 'os_version' => device.version,
132
+ 'queue_prefix' => @config['queue_prefix']
133
+ }
69
134
  end
70
- end
71
135
 
72
- if !untrusted_devices.empty?
73
- puts Terminal::Table.new headings: ['Untrusted Devices'], rows: [untrusted_devices]
136
+ attached_devices = device_info.collect do |physical_device|
137
+ self.create_device(physical_device)
138
+ end
74
139
  end
140
+
141
+ Hive.logger.info(attached_devices)
142
+ attached_devices
75
143
  end
76
144
 
77
- def display_devices
78
- rows = []
145
+ def detect
146
+ register_with_devicedb
147
+ register_with_hivemind
148
+ end
79
149
 
80
- hive_details = Hive.devicedb('Hive').find(Hive.id)
81
- if hive_details.key?('devices')
82
- unless hive_details['devices'].empty?
83
- rows = hive_details['devices'].map do |device|
84
- [
85
- "#{device['device_brand']} #{device['device_model']}",
86
- device['serial'],
87
- (device['device_queues'].map { |queue| queue['name']}).join("\n"),
88
- device['status']
89
- ]
90
- end
91
- end
92
- end
93
- table = Terminal::Table.new :headings => ['Device', 'Serial', 'Queue Name', 'Status'], :rows => rows
150
+ def display_untrusted
151
+ devices = DeviceAPI::IOS.devices
152
+ untrusted_devices = devices.select { |a| !a.trusted? }
94
153
 
95
- puts(table)
154
+ return if untrusted_devices.empty?
155
+ puts Terminal::Table.new headings: ['Untrusted devices'], rows: [untrusted_devices]
96
156
  end
97
157
 
98
158
  def register_new_device(device)
99
- Hive.logger.debug("Found iOS device: #{device.model}")
159
+ Hive.logger.debug("Adding new iOS device: #{device.model}")
100
160
 
101
161
  attributes = {
102
162
  os: 'ios',
@@ -135,37 +195,8 @@ module Hive
135
195
  Hive.devicedb('Device').edit(device['id'], values)
136
196
  end
137
197
 
138
- def find_or_create_queue(name)
139
- queue = Hive.devicedb('Queue').find_by_name(name)
140
- return queue.first['id'] unless queue.empty?
141
198
 
142
- create_queue(name, "#{name} queue created by Hive Runner")['id']
143
- end
144
-
145
- def create_queue(name, description)
146
- queue_attributes = {
147
- name: name,
148
- description: description
149
- }
150
-
151
- Hive.devicedb('Queue').register(device_queue: queue_attributes )
152
- end
153
-
154
- def calculate_queue_names(device)
155
-
156
- queues = [
157
- device['device_model'],
158
- device['os'],
159
- "#{device['os']}-#{device['os_version']}",
160
- "#{device['os']}-#{device['os_version']}-#{device['device_model']}",
161
- device['device_type'],
162
- "#{device['os']}-#{device['device_type']}"
163
- ]
164
-
165
- queues << device["features"] unless device["features"].empty?
166
-
167
- queues.flatten
168
- end
169
199
  end
170
200
  end
171
- end
201
+ end
202
+
@@ -3,10 +3,54 @@ require 'hive/device'
3
3
  module Hive
4
4
  class Device
5
5
  class Ios < Device
6
+ attr_accessor :model, :os_version, :device_type
7
+
6
8
  def initialize(config)
7
9
  @identity = config['id']
10
+ @queue_prefix = config['queue_prefix'].to_s == '' ? '' : "#{config['queue_prefix']}-"
11
+ @model = config['model'].downcase.gsub(/\s/, '_')
12
+ @device_range = config['device_range'].downcase
13
+ @os_version = config['os_version']
14
+
15
+ new_queues = calculate_queue_names
16
+ new_queues = new_queues | config['queues'] if config.has_key?('queues')
17
+
18
+ devicedb_ids = new_queues.map { |queue| find_or_create_queue(queue) }
19
+ Hive.devicedb('Device').edit(@identity, { device_queue_ids: devicedb_ids })
20
+ config['queues'] = new_queues
8
21
  super
9
22
  end
23
+
24
+ def calculate_queue_names
25
+ [
26
+ "#{@queue_prefix}#{self.model}",
27
+ "#{@queue_prefix}ios",
28
+ "#{@queue_prefix}ios-#{self.os_version}",
29
+ "#{@queue_prefix}ios-#{self.os_version}-#{self.model}",
30
+ "#{@queue_prefix}#{@device_range}",
31
+ "#{@queue_prefix}#{@device_range}-#{self.os_version}"
32
+ ]
33
+ end
34
+
35
+ private
36
+
37
+ def find_or_create_queue(name)
38
+
39
+ queue = Hive.devicedb('Queue').find_by_name(name)
40
+ return queue.first['id'] unless queue.empty? || queue.is_a?(Hash)
41
+
42
+ queue = create_queue(name, "#{name} queue created by Hive Runner")
43
+ queue['id'] unless queue.empty?
44
+ end
45
+
46
+ def create_queue(name, description)
47
+ queue_attributes = {
48
+ name: name,
49
+ description: description
50
+ }
51
+
52
+ Hive.devicedb('Queue').register(device_queue: queue_attributes )
53
+ end
10
54
  end
11
55
  end
12
56
  end
@@ -66,9 +66,9 @@ module Hive
66
66
  app_path = file_system.home_path + '/build/' + 'build.ipa'
67
67
 
68
68
  file_system.fetch_build(job.build, app_path)
69
- entitlements = DeviceAPI::IOS::Signing.enable_get_tasks(app_path)
70
- DeviceAPI::IOS::Signing.sign_app(@options['signing_identity'], entitlements: entitlements, app: app_path)
71
- app_info = DeviceAPI::IOS::Plistutil.get_bundle_id_from_app(app_path)
69
+ entitlements = FruityBuilder::Signing.enable_get_tasks(app_path)
70
+ FruityBuilder::Signing.sign_app(@options['signing_identity'], entitlements: entitlements, app: app_path)
71
+ app_info = FruityBuilder::Plistutil.get_bundle_id_from_app(app_path)
72
72
  app_bundle = app_info['CFBundleIdentifier']
73
73
  device.install(app_path)
74
74
  script.set_env 'BUNDLE_ID', app_bundle
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-runner-ios
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
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-02-10 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hive-runner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: device_api-ios
15
29
  requirement: !ruby/object:Gem::Requirement