luffa 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69f33e552edab40463c13af65f62621b88fb0c53
4
- data.tar.gz: 75bd4f9b398f5a634f0b3310bdbe761ef0a949e3
3
+ metadata.gz: 788f5398ad79dc3be466b7bfacebfebc7ed41845
4
+ data.tar.gz: f01d3aa2b4ab91cf745021cebf9bc2349262b2e7
5
5
  SHA512:
6
- metadata.gz: 9ea630571fee55dafdd6b3c67e5737c296c34beb9876006d0cc8647dbbb32b99a0b682d5f6eda5f1e925ebbf14f3b63172fdf4904f02daeef1d743bcdf18d1d9
7
- data.tar.gz: 95ef9d0b26520fddfd8b6c881dac9e6107bf58e23c4f7bb7b85dd3dd114fb55d1d426b5588b8c9e82fba66f70351cd35985fdb41374db3760b4e32e06f777454
6
+ metadata.gz: f11db976ea3fab737dd67457db0290a1673c85fc561e9d46bbae27331d542e3e3ee7f9744e53fde34c64f1a136c39f2a223fa963c16f79c9dc3a7d6f1175fb9e
7
+ data.tar.gz: b45ed6f7363b9a1d95e789e0508293160da1733bbc846d0f5972d4dbeaca3672beac1f840d1f8584d2c95eca0037b7604f912f24cc8e82a7ef9fdc3e035d921a
@@ -1,4 +1,5 @@
1
1
  require 'retriable'
2
+ require 'open3'
2
3
 
3
4
  module Luffa
4
5
  class IDeviceInstaller
@@ -11,106 +12,148 @@ module Luffa
11
12
  @bundle_id = bundle_id
12
13
  end
13
14
 
14
- def bin_path
15
- @bin_path ||= `which ideviceinstaller`.chomp!
16
- end
17
-
18
15
  def ideviceinstaller_available?
19
16
  path = bin_path
20
17
  path and File.exist? bin_path
21
18
  end
22
19
 
23
- def install(udid, cmd)
24
- case cmd
25
- when :install_internal
26
- ipa
27
- Retriable.retriable do
28
- uninstall udid
29
- end
30
- Retriable.retriable do
31
- install_internal udid
32
- end
33
- when :uninstall
34
- Retriable.retriable do
35
- uninstall udid
20
+ def idevice_id_available?
21
+ path = idevice_id_bin_path
22
+ path and File.exist? path
23
+ end
24
+
25
+ def install(udid, options={})
26
+ unless options.is_a? Hash
27
+ Luffa.log_warn 'API CHANGE: install now takes an options hash as 2nd arg'
28
+ Luffa.log_warn "API CHANGE: ignoring '#{options}'; will use defaults"
29
+ merged_options = DEFAULT_OPTIONS
30
+ else
31
+ merged_options = DEFAULT_OPTIONS.merge(options)
32
+ end
33
+
34
+ uninstall(udid, merged_options)
35
+ install_internal(udid, merged_options)
36
+ end
37
+
38
+ # Can only be called when RunLoop is available.
39
+ def physical_devices_for_testing(xcode_tools)
40
+ # Xcode 6 + iOS 8 - devices on the same network, whether development or
41
+ # not, appear when calling $ xcrun instruments -s devices. For the
42
+ # purposes of testing, we will only try to connect to devices that are
43
+ # connected via USB.
44
+ #
45
+ # Also idevice_id, which ideviceinstaller relies on, will sometimes report
46
+ # devices 2x which will cause ideviceinstaller to fail.
47
+ @physical_devices_for_testing ||= lambda {
48
+ devices = xcode_tools.instruments(:devices)
49
+ if idevice_id_available?
50
+ white_list = `#{idevice_id_bin_path} -l`.strip.split("\n")
51
+ devices.select do | device |
52
+ white_list.include?(device.udid) && white_list.count(device.udid) == 1
36
53
  end
37
54
  else
38
- cmds = [:install_internal, :uninstall]
39
- raise ArgumentError, "expected '#{cmd}' to be one of '#{cmds}'"
40
- end
55
+ devices
56
+ end
57
+ }.call
41
58
  end
42
59
 
43
- def bundle_installed?(udid)
44
- cmd = "#{bin_path} --udid #{udid} --list-apps"
45
- Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?
60
+ private
46
61
 
47
- Open3.popen3(cmd) do |_, stdout, stderr, _|
48
- err = stderr.read.strip
49
- Luffa.log_fail(err) if err && err != ''
62
+ DEFAULT_OPTIONS = { :timeout => 10.0, :tries => 2 }
50
63
 
51
- out = stdout.read.strip
52
- out.strip.split(/\s/).include? bundle_id
53
- end
64
+ def bin_path
65
+ @bin_path ||= `which ideviceinstaller`.chomp!
54
66
  end
55
67
 
56
- def install_internal(udid)
57
- return true if bundle_installed? udid
68
+ def run_command_with_args(args, options={})
69
+ merged_options = DEFAULT_OPTIONS.merge(options)
58
70
 
59
- cmd = "#{bin_path} --udid #{udid} --install #{ipa}"
71
+ cmd = "#{bin_path} #{args.join(' ')}"
60
72
  Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?
61
73
 
62
- Open3.popen3(cmd) do |_, _, stderr, _|
63
- err = stderr.read.strip
64
- Luffa.log_fail(err) if err && err != ''
74
+ exit_status = nil
75
+ out = nil
76
+ pid = nil
77
+ err = nil
78
+
79
+ tries = merged_options[:tries]
80
+ timeout = merged_options[:timeout]
81
+
82
+ on = [Timeout::Error, RuntimeError]
83
+ on_retry = Proc.new do |_, try, elapsed_time, next_interval|
84
+ # Retriable 2.0
85
+ if elapsed_time && next_interval
86
+ Luffa.log_info "LLDB: attempt #{try} failed in '#{elapsed_time}'; will retry in '#{next_interval}'"
87
+ else
88
+ Luffa.log_info "LLDB: attempt #{try} failed; will retry"
89
+ end
65
90
  end
66
91
 
67
- unless bundle_installed? udid
68
- raise "could not install '#{ipa}' on '#{udid}' with '#{bundle_id}'"
92
+ Retriable.retriable({tries: tries, on: on, on_retry: on_retry} ) do
93
+ Timeout.timeout(timeout, TimeoutError) do
94
+ Open3.popen3(bin_path, *args) do |_, stdout, stderr, process_status|
95
+ err = stderr.read.strip
96
+ if err && err != ''
97
+ unless err[/iTunesMetadata.plist/,0] || err[/SC_Info/,0]
98
+ Luffa.log_fail(err)
99
+ end
100
+ end
101
+ out = stdout.read.strip
102
+ pid = process_status.pid
103
+ exit_status = process_status.value.exitstatus
104
+ end
105
+ end
106
+
107
+ if exit_status != 0
108
+ raise RuntimeError, "Could not execute #{args.join(' ')}"
109
+ end
69
110
  end
70
- true
111
+ {
112
+ :out => out,
113
+ :err => err,
114
+ :pid => pid,
115
+ :exit_status => exit_status
116
+ }
71
117
  end
72
118
 
73
- def uninstall(udid)
74
- return true unless bundle_installed? udid
119
+ def bundle_installed?(udid, options={})
120
+ merged_options = DEFAULT_OPTIONS.merge(options)
75
121
 
76
- cmd = "#{bin_path} -udid #{udid} --uninstall #{bundle_id}"
77
- Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?
122
+ args = ['--udid', udid, '--list-apps']
78
123
 
79
- Open3.popen3(cmd) do |_, _, stderr, _|
80
- err = stderr.read.strip
81
- Luffa.log_fail(err) if err && err != ''
82
- end
124
+ hash = run_command_with_args(args, merged_options)
125
+ out = hash[:out]
126
+ out.split(/\s/).include? bundle_id
127
+ end
128
+
129
+ def install_internal(udid, options={})
130
+ merged_options = DEFAULT_OPTIONS.merge(options)
83
131
 
84
- if bundle_installed? udid
85
- raise "could not uninstall '#{bundle_id}' on '#{udid}'"
132
+ return true if bundle_installed?(udid, merged_options)
133
+ args = ['--udid', udid, '--install', ipa]
134
+ run_command_with_args(args, merged_options)
135
+
136
+ unless bundle_installed?(udid, merged_options)
137
+ raise "could not install '#{ipa}' on '#{udid}' with '#{bundle_id}'"
86
138
  end
87
139
  true
88
140
  end
89
141
 
90
- def idevice_id_bin_path
91
- @idevice_id_bin_path ||= `which idevice_id`.chomp!
92
- end
142
+ def uninstall(udid, options={})
143
+ merged_options = DEFAULT_OPTIONS.merge(options)
93
144
 
94
- def idevice_id_available?
95
- path = idevice_id_bin_path
96
- path and File.exist? path
97
- end
145
+ return true unless bundle_installed?(udid, merged_options)
146
+ args = ['--udid', udid, '--uninstall', bundle_id]
147
+ run_command_with_args(args)
98
148
 
99
- def physical_devices_for_testing(xcode_tools)
100
- # Xcode 6 + iOS 8 - devices on the same network, whether development or
101
- # not, appear when calling $ xcrun instruments -s devices. For the
102
- # purposes of testing, we will only try to connect to devices that are
103
- # connected via USB.
104
- @physical_devices_for_testing ||= lambda {
105
- devices = xcode_tools.instruments(:devices)
106
- if idevice_id_available?
107
- white_list = `#{idevice_id_bin_path} -l`.strip.split("\n")
108
- devices.select { | device | white_list.include?(device.udid) }
109
- else
110
- devices
111
- end
112
- }.call
149
+ if bundle_installed?(udid, merged_options)
150
+ raise "Could not uninstall '#{bundle_id}' on '#{udid}'"
151
+ end
152
+ true
113
153
  end
114
154
 
155
+ def idevice_id_bin_path
156
+ @idevice_id_bin_path ||= `which idevice_id`.chomp!
157
+ end
115
158
  end
116
159
  end
@@ -1,5 +1,5 @@
1
1
  module Luffa
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
 
4
4
  # A model of a software release version that can be used to compare two versions.
5
5
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luffa
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
  - Jonas Maturana Larsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-03-30 00:00:00.000000000 Z
14
+ date: 2015-04-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: awesome_print