stf-client-neofreko 0.1.7

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebb281d8ac65af753870dc7cea6bd86be8a3ce3c
4
+ data.tar.gz: b4b9783173755f0e0862656badd9126da0718043
5
+ SHA512:
6
+ metadata.gz: c45ed8a17bdaf36d3edb58aa3454f60328fa32ce96396dafff8e8eab6e1a8fb9ded0bb6ac832582f67fc72d8d1c87ec758648bec162cf833f127673a5462a8d3
7
+ data.tar.gz: 8c95da0681fde2a4168b8ba1eda52a95a8494c4554cc89f846a4e665957acd9d4236b90feb0eeff7f9be12f2d77be3ea99a1ff57d659818cbd1970d371ecc0d6
data/.gitignore ADDED
@@ -0,0 +1,104 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ ### JetBrains template
11
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
12
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
13
+
14
+ # User-specific stuff:
15
+ .idea/workspace.xml
16
+ .idea/tasks.xml
17
+ .idea/dictionaries
18
+ .idea/vcs.xml
19
+ .idea/jsLibraryMappings.xml
20
+
21
+ # Sensitive or high-churn files:
22
+ .idea/dataSources.ids
23
+ .idea/dataSources.xml
24
+ .idea/dataSources.local.xml
25
+ .idea/sqlDataSources.xml
26
+ .idea/dynamic.xml
27
+ .idea/uiDesigner.xml
28
+
29
+ # Gradle:
30
+ .idea/gradle.xml
31
+ .idea/libraries
32
+
33
+ # Mongo Explorer plugin:
34
+ .idea/mongoSettings.xml
35
+
36
+ # RubyMine
37
+ .idea/.rakeTasks
38
+ .idea/misc.xml
39
+ .idea/modules.xml
40
+ .idea/stf-client.iml
41
+
42
+ ## File-based project format:
43
+ *.iws
44
+
45
+ ## Plugin-specific files:
46
+
47
+ # IntelliJ
48
+ /out/
49
+
50
+ # mpeltonen/sbt-idea plugin
51
+ .idea_modules/
52
+
53
+ # JIRA plugin
54
+ atlassian-ide-plugin.xml
55
+
56
+ # Crashlytics plugin (for Android Studio and IntelliJ)
57
+ com_crashlytics_export_strings.xml
58
+ crashlytics.properties
59
+ crashlytics-build.properties
60
+ fabric.properties
61
+ ### Ruby template
62
+ *.gem
63
+ *.rbc
64
+ /.config
65
+ /InstalledFiles
66
+ /spec/examples.txt
67
+ /test/tmp/
68
+ /test/version_tmp/
69
+
70
+ # Used by dotenv library to load environment variables.
71
+ # .env
72
+
73
+ ## Specific to RubyMotion:
74
+ .dat*
75
+ .repl_history
76
+ build/
77
+ *.bridgesupport
78
+ build-iPhoneOS/
79
+ build-iPhoneSimulator/
80
+
81
+ ## Specific to RubyMotion (use of CocoaPods):
82
+ #
83
+ # We recommend against adding the Pods directory to your .gitignore. However
84
+ # you should judge for yourself, the pros and cons are mentioned at:
85
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
86
+ #
87
+ # vendor/Pods/
88
+
89
+ ## Documentation cache and generated files:
90
+ /.yardoc/
91
+ /rdoc/
92
+
93
+ ## Environment normalization:
94
+ /vendor/bundle
95
+ /lib/bundler/man/
96
+
97
+ # for a library or gem, you might want to ignore these files since the code is
98
+ # intended to run in multiple environments; otherwise, check them in:
99
+ # Gemfile.lock
100
+ # .ruby-version
101
+ # .ruby-gemset
102
+
103
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
104
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Anton Malinskiy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Stf::Client
2
+
3
+ Automation client for connecting to [OpenSTF](https://github.com/openstf/stf) devices.
4
+
5
+ Designed with the following scenario in mind:
6
+
7
+ 1. Connect to remote devices
8
+ 2. Do something with the device via adb (Instrumentation Test, adb install, etc)
9
+ 3. Disconnect from device
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'stf-client'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install stf-client
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ NAME
31
+ stf-client - Smartphone Test Lab client
32
+
33
+ SYNOPSIS
34
+ stf-client [global options] command [command options] [arguments...]
35
+
36
+ GLOBAL OPTIONS
37
+ --help - Show this message
38
+ -t, --token=arg - Authorization token, can also be set by environment variable STF_TOKEN (default: none)
39
+ -u, --url=arg - URL to STF, can also be set by environment variable STF_URL (default: none)
40
+ -v, --[no-]verbose - Be verbose
41
+
42
+ COMMANDS
43
+ clean - Frees all devices that are assigned to current user in STF. Doesn't modify local adb
44
+ connect - Search for a device available in STF and attach it to local adb server
45
+ disconnect - Disconnect device(s) from local adb server and remove device(s) from user devices in STF
46
+ help - Shows a list of commands or help for one command
47
+ keys - Show avaliable keys for filtering
48
+ values - Show known values for the filtering key
49
+
50
+ ENVIRONMENT VARIABLES
51
+ STF_TOKEN - Authorization token
52
+ STF_URL - URL to STF
53
+
54
+ COMMAND OPTIONS
55
+ connect
56
+ -f - Filter devices in the form of "key:value". Use stf-client keys to list keys and stf-client values -k <key from prev command> to get list of applicable values
57
+ -d, --adb - Automatically execute adb connect command once device acquired. Default true
58
+ ```
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Malinskiy/stf-client.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ rescue LoadError
6
+ end
7
+
8
+ task :default => :spec
9
+ task :test => :spec
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/bin/stf-client ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stf'
data/lib/stf/client.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'ostruct'
4
+
5
+ require 'stf/version'
6
+ require 'stf/log/log'
7
+ require 'stf/errors'
8
+
9
+ module Stf
10
+ class Client
11
+ include Log
12
+
13
+ def initialize(base_url, token)
14
+ @base_url = base_url
15
+ @token = token
16
+ end
17
+
18
+ def get_devices
19
+ response = execute '/api/v1/devices', Net::HTTP::Get
20
+ return response.devices
21
+ end
22
+
23
+ def get_device(serial)
24
+ response = execute "/api/v1/devices/#{serial}", Net::HTTP::Get
25
+ return response.device
26
+ end
27
+
28
+ def get_user
29
+ response = execute '/api/v1/user', Net::HTTP::Get
30
+ return response.user
31
+ end
32
+
33
+ def get_user_devices
34
+ response = execute '/api/v1/user/devices', Net::HTTP::Get
35
+ return response.devices
36
+ end
37
+
38
+ def add_device(serial)
39
+ response = execute '/api/v1/user/devices', Net::HTTP::Post, {serial: serial}.to_json
40
+ return response.success
41
+ end
42
+
43
+ def remove_device(serial)
44
+ response = execute "/api/v1/user/devices/#{serial}", Net::HTTP::Delete
45
+ return response.success
46
+ end
47
+
48
+ def start_debug(serial)
49
+ response = execute "/api/v1/user/devices/#{serial}/remoteConnect", Net::HTTP::Post
50
+ return response
51
+ end
52
+
53
+ def stop_debug(serial)
54
+ response = execute "/api/v1/user/devices/#{serial}/remoteConnect", Net::HTTP::Delete
55
+ return response.success
56
+ end
57
+
58
+ private
59
+
60
+ def execute(relative_url, type, body='')
61
+ return execute_absolute @base_url + relative_url, type, body
62
+ end
63
+
64
+ def execute_absolute(url, type, body='', limit = 10)
65
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
66
+
67
+ uri = URI.parse(url)
68
+ http = Net::HTTP.new(uri.host, uri.port)
69
+ http.use_ssl = true if uri.scheme == 'https'
70
+ request = type.new(uri, 'Authorization' => "Bearer #{@token}", 'Content-Type' => 'application/json')
71
+ request.body = body
72
+ response = http.request(request)
73
+
74
+ case response
75
+ when Net::HTTPSuccess then
76
+ json = JSON.parse(response.body, object_class: OpenStruct)
77
+
78
+ logger.debug "API returned #{json}"
79
+ when Net::HTTPRedirection then
80
+ location = response['location']
81
+ logger.debug "redirected to #{location}"
82
+ return execute_absolute(location, type, body, limit - 1)
83
+ else
84
+ logger.error "API returned #{response.value}"
85
+ end
86
+
87
+ return json
88
+ end
89
+ end
90
+ end
data/lib/stf/errors.rb ADDED
@@ -0,0 +1,5 @@
1
+ class DeviceNotAvailableError < StandardError
2
+ def message
3
+ 'Device not available'
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'ADB'
2
+
3
+ require 'stf/client'
4
+ require 'stf/log/log'
5
+ require 'stf/errors'
6
+ require 'stf/model/session'
7
+ require 'stf/model/device'
8
+
9
+ class GetKeysInteractor
10
+
11
+ include Log
12
+ include ADB
13
+
14
+ def initialize(stf)
15
+ @stf = stf
16
+ end
17
+
18
+ def execute
19
+ devices = @stf.get_devices
20
+
21
+ if devices.nil? || (devices.is_a?(Array) && devices.empty?)
22
+ logger.info 'No devices connected to STF'
23
+ return []
24
+ end
25
+
26
+ return devices
27
+ .map {|d| Device.new(d)}
28
+ .flat_map {|d| d.getKeys }
29
+ .uniq
30
+ .sort
31
+ end
32
+
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'ADB'
2
+
3
+ require 'stf/client'
4
+ require 'stf/log/log'
5
+ require 'stf/errors'
6
+ require 'stf/model/session'
7
+ require 'stf/model/device'
8
+
9
+ class GetValuesInteractor
10
+
11
+ include Log
12
+ include ADB
13
+
14
+ def initialize(stf)
15
+ @stf = stf
16
+ end
17
+
18
+ def execute(key)
19
+ devices = @stf.get_devices
20
+
21
+ if devices.nil? || (devices.is_a?(Array) && devices.empty?)
22
+ logger.info r 'No devices connected to STF'
23
+ return []
24
+ end
25
+
26
+ return devices
27
+ .map {|d| Device.new(d)}
28
+ .map {|d| d.getValue(key)}
29
+ .uniq
30
+ end
31
+
32
+ end
@@ -0,0 +1,11 @@
1
+ class RemoveAllUserDevicesInteractor
2
+
3
+ def initialize(stf)
4
+ @stf = stf
5
+ end
6
+
7
+ def execute
8
+ devices = @stf.get_user_devices
9
+ devices.each { |d| @stf.remove_device d.serial }
10
+ end
11
+ end
@@ -0,0 +1,105 @@
1
+ require 'ADB'
2
+
3
+ require 'stf/client'
4
+ require 'stf/log/log'
5
+ require 'stf/errors'
6
+ require 'stf/model/session'
7
+
8
+ class StartDebugSessionInteractor
9
+
10
+ include Log
11
+ include ADB
12
+
13
+ def initialize(stf)
14
+ @stf = stf
15
+ end
16
+
17
+ def execute(wanted, all_flag, filter, auto_adb_connect)
18
+ wanted = 1 if wanted.nil?
19
+ wanted = wanted.to_i
20
+
21
+ 1..10.times do
22
+ wanted -= connect(wanted, all_flag, filter, auto_adb_connect)
23
+ return if all_flag || wanted <= 0
24
+ logger.info 'We are still waiting for ' + wanted.to_s + ' device(s). Retrying'
25
+ sleep 5
26
+ end
27
+ end
28
+
29
+ def connect(wanted, all_flag, filter, auto_adb_connect)
30
+ devices = @stf.get_devices
31
+ if devices.nil? || (devices.is_a?(Array) && devices.empty?)
32
+ logger.info 'No devices connected to STF'
33
+ return 0
34
+ end
35
+
36
+ usable_devices = devices
37
+ .map {|d| Device.new(d)}
38
+ .select do |d|
39
+ d.ready == true && d.present == true && d.using == false
40
+ end
41
+
42
+ if usable_devices.empty?
43
+ logger.error 'All devices are being used'
44
+ return 0
45
+ end
46
+
47
+ unless filter.nil?
48
+ key, value = filter.split(':', 2)
49
+
50
+ usable_devices = usable_devices.select do |d|
51
+ d.getValue(key) == value
52
+ end
53
+ end
54
+
55
+ if usable_devices.empty?
56
+ logger.error 'There is no device with criteria ' + filter
57
+ return 0
58
+ end
59
+
60
+ n = 0
61
+ usable_devices.shuffle.each do |d|
62
+ n += 1 if connect_device(d, auto_adb_connect)
63
+ break if !all_flag && n >= wanted
64
+ end
65
+
66
+ n
67
+ end
68
+
69
+ def connect_device(device, auto_adb_connect)
70
+ begin
71
+ return false if device.nil?
72
+
73
+ serial = device.serial
74
+ success = @stf.add_device serial
75
+ if success
76
+ logger.info "Device #{serial} added"
77
+ elsif logger.error "Can't add device #{serial}"
78
+ return false
79
+ end
80
+
81
+ result = @stf.start_debug serial
82
+ unless result.success
83
+ logger.error "Can't start debugging session for device #{serial}"
84
+ @stf.remove_device serial
85
+ return false
86
+ end
87
+
88
+ logger.info "remoteConnectUrl: #{result.remoteConnectUrl}"
89
+
90
+ if auto_adb_connect
91
+ _execute_adb_with 30, "connect #{result.remoteConnectUrl}"
92
+ end
93
+ return true
94
+
95
+ rescue Net::HTTPFatalError
96
+ logger.error 'Failed to start debug session'
97
+ return false
98
+ end
99
+ end
100
+
101
+ def _execute_adb_with(timeout, cmd)
102
+ execute_adb_with timeout, cmd
103
+ end
104
+
105
+ end
@@ -0,0 +1,25 @@
1
+ require 'ADB'
2
+
3
+ require 'stf/client'
4
+ require 'stf/log/log'
5
+ require 'stf/errors'
6
+ require 'stf/interactor/stop_debug_session_interactor'
7
+
8
+ class StopAllDebugSessionsInteractor
9
+ include Log
10
+ include ADB
11
+
12
+ def initialize(stf)
13
+ @stf = stf
14
+ end
15
+
16
+ def execute
17
+ connected_devices = devices()
18
+ remote_devices = @stf.get_user_devices.map { |d| d.remoteConnectUrl }
19
+
20
+ pending_disconnect = connected_devices & remote_devices
21
+ pending_disconnect.each do |d|
22
+ StopDebugSessionInteractor.new(@stf).execute d
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+ require 'ADB'
2
+
3
+ require 'stf/client'
4
+ require 'stf/log/log'
5
+ require 'stf/errors'
6
+
7
+ class StopDebugSessionInteractor
8
+
9
+ include Log
10
+ include ADB
11
+
12
+ def initialize(stf)
13
+ @stf = stf
14
+ end
15
+
16
+ def execute(remoteConnectUrl)
17
+ remote_devices = @stf.get_user_devices
18
+ device = remote_devices.find { |d| d.remoteConnect == true && d.remoteConnectUrl.eql?(remoteConnectUrl) }
19
+
20
+ raise DeviceNotAvailableError if device.nil?
21
+
22
+ execute_adb_with 30, "disconnect #{device.remoteConnectUrl}"
23
+
24
+ success = false
25
+
26
+ 1..10.times do
27
+ success = @stf.stop_debug(device.serial)
28
+ if success == true
29
+ break
30
+ elsif logger.error 'Can\'t stop debug session. Retrying'
31
+ end
32
+ end
33
+
34
+ 1..10.times do
35
+ success = @stf.remove_device(device.serial)
36
+ if success == true
37
+ break
38
+ elsif logger.error 'Can\'t remove device from user devices. Retrying'
39
+ end
40
+ end
41
+
42
+ if success == true
43
+ logger.info "Successfully removed #{remoteConnectUrl}"
44
+ elsif logger.error "Error removing #{remoteConnectUrl}"
45
+ end
46
+
47
+ return success
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ require 'logger'
2
+
3
+ module Log
4
+
5
+ @@logger = Logger.new(STDOUT)
6
+ @@logger.level = Logger::INFO
7
+
8
+ def logger
9
+ @@logger
10
+ end
11
+
12
+ def self.verbose(enable)
13
+ @@logger.level = enable ? Logger::DEBUG : Logger::INFO
14
+ end
15
+
16
+ end
@@ -0,0 +1,38 @@
1
+ class Device < OpenStruct
2
+ def getValue(key)
3
+ getValueFromObject(self, key)
4
+ end
5
+
6
+ def getKeys
7
+ getKeysNextLevel('', self)
8
+ end
9
+
10
+ def getKeysNextLevel(prefix, o)
11
+ return [] if o.nil?
12
+
13
+ o.each_pair.flat_map do |k, v|
14
+ if v.is_a? OpenStruct
15
+ getKeysNextLevel(concat(prefix, k.to_s), v)
16
+ else
17
+ [concat(prefix, k.to_s)]
18
+ end
19
+ end
20
+ end
21
+
22
+ def concat(prefix, key)
23
+ prefix.to_s.empty? ? key : prefix + '.' + key
24
+ end
25
+
26
+
27
+ def getValueFromObject(obj, key)
28
+ keys = key.split('.', 2)
29
+ if keys[1].nil?
30
+ obj[key]
31
+ else
32
+ getValueFromObject(obj[keys[0]], keys[1])
33
+ end
34
+ end
35
+
36
+ private :getValueFromObject,:concat, :getKeysNextLevel
37
+
38
+ end
@@ -0,0 +1,10 @@
1
+ class Session
2
+
3
+ attr_accessor :serial, :url
4
+
5
+ def initialize(serial, url)
6
+ @serial = serial
7
+ @url = url
8
+ end
9
+
10
+ end
@@ -0,0 +1,3 @@
1
+ module Stf
2
+ VERSION = '0.1.7'
3
+ end
@@ -0,0 +1,98 @@
1
+ module Stf
2
+ module CLI
3
+ require 'gli'
4
+ require 'stf/client'
5
+
6
+ require 'stf/interactor/start_debug_session_interactor'
7
+ require 'stf/interactor/stop_debug_session_interactor'
8
+ require 'stf/interactor/stop_all_debug_sessions_interactor'
9
+ require 'stf/interactor/remove_all_user_devices_interactor'
10
+ require 'stf/interactor/get_keys_interactor'
11
+ require 'stf/interactor/get_values_interactor'
12
+
13
+ include GLI::App
14
+ extend self
15
+
16
+ program_desc 'Smartphone Test Lab client'
17
+
18
+ desc 'Be verbose'
19
+ switch [:v, :verbose]
20
+
21
+ desc 'Authorization token, can also be set by environment variable STF_TOKEN'
22
+ flag [:t, :token]
23
+
24
+ desc 'URL to STF, can also be set by environment variable STF_URL'
25
+ flag [:u, :url]
26
+
27
+ pre do |global_options, command, options, args|
28
+
29
+ global_options[:url] = ENV['STF_URL'] if global_options[:url].nil?
30
+ global_options[:token] = ENV['STF_TOKEN'] if global_options[:token].nil?
31
+
32
+ help_now!('STF url is required') if global_options[:url].nil?
33
+ help_now!('Authorization token is required') if global_options[:token].nil?
34
+
35
+ Log::verbose(global_options[:verbose])
36
+
37
+ $stf = Stf::Client.new(global_options[:url], global_options[:token])
38
+ end
39
+
40
+ desc 'Search for a device available in STF and attach it to local adb server'
41
+ command :connect do |c|
42
+ c.switch [:all]
43
+ c.flag [:n, :number]
44
+ c.flag [:f, :filter]
45
+ c.switch :adb, default_value: true, desc: 'automatically execute adb connect'
46
+
47
+ c.action do |global_options, options, args|
48
+ StartDebugSessionInteractor.new($stf).execute(options[:number], options[:all], options[:filter], options[:adb])
49
+ end
50
+ end
51
+
52
+ desc 'Show available keys for filtering'
53
+ command :keys do |c|
54
+ c.action do |global_options, options, args|
55
+ puts GetKeysInteractor.new($stf).execute
56
+ end
57
+ end
58
+
59
+ desc 'Show known values for the filtering key'
60
+ command :values do |c|
61
+ c.flag [:k, :key]
62
+
63
+ c.action do |global_options, options, args|
64
+ if options[:key].nil?
65
+ help_now!('Please specify the key (--key)')
66
+ else
67
+ puts GetValuesInteractor.new($stf).execute(options[:key])
68
+ end
69
+ end
70
+ end
71
+
72
+ desc 'Disconnect device(s) from local adb server and remove device(s) from user devices in STF'
73
+ command :disconnect do |c|
74
+ c.desc '(optional) ADB connection url of the device'
75
+ c.flag [:d, :device]
76
+ c.switch [:all]
77
+
78
+ c.action do |global_options, options, args|
79
+ if options[:device].nil? && options[:all] == true
80
+ StopAllDebugSessionsInteractor.new($stf).execute
81
+ elsif !options[:device].nil? && options[:all] == false
82
+ StopDebugSessionInteractor.new($stf).execute(options[:device])
83
+ elsif help_now!('Please specify disconnect mode (--all or --device)')
84
+ end
85
+ end
86
+ end
87
+
88
+ desc 'Frees all devices that are assigned to current user in STF. Doesn\'t modify local adb'
89
+ command :clean do |c|
90
+ c.action do |global_options, options, args|
91
+ RemoveAllUserDevicesInteractor.new($stf).execute
92
+ end
93
+ end
94
+
95
+ exit run(ARGV)
96
+ end
97
+ end
98
+
data/lib/stf.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stf/view/cli'
4
+
5
+ module Stf
6
+ include Stf::CLI
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stf-client-neofreko'
8
+ spec.version = Stf::VERSION
9
+ spec.authors = ['Akhmad Fathonih']
10
+ spec.email = ['akhmadf@fathonih.com']
11
+ spec.summary = %q{Request devices from Smartphone Test Farm for adb connection - forked from stf-client gem}
12
+ spec.homepage = 'https://github.com/neofreko/stf-client'
13
+ spec.license = 'MIT'
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ['lib']
16
+ spec.executables = ['stf-client']
17
+
18
+ spec.add_runtime_dependency 'gli'
19
+ spec.add_runtime_dependency 'ADB'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.12'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.5'
24
+ spec.add_development_dependency 'webmock', '~> 2.1'
25
+ spec.add_development_dependency 'sinatra', '~> 1.4'
26
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stf-client-neofreko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Akhmad Fathonih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ADB
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
111
+ description:
112
+ email:
113
+ - akhmadf@fathonih.com
114
+ executables:
115
+ - stf-client
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/setup
127
+ - bin/stf-client
128
+ - lib/stf.rb
129
+ - lib/stf/client.rb
130
+ - lib/stf/errors.rb
131
+ - lib/stf/interactor/get_keys_interactor.rb
132
+ - lib/stf/interactor/get_values_interactor.rb
133
+ - lib/stf/interactor/remove_all_user_devices_interactor.rb
134
+ - lib/stf/interactor/start_debug_session_interactor.rb
135
+ - lib/stf/interactor/stop_all_debug_sessions_interactor.rb
136
+ - lib/stf/interactor/stop_debug_session_interactor.rb
137
+ - lib/stf/log/log.rb
138
+ - lib/stf/model/device.rb
139
+ - lib/stf/model/session.rb
140
+ - lib/stf/version.rb
141
+ - lib/stf/view/cli.rb
142
+ - stf-client.gemspec
143
+ homepage: https://github.com/neofreko/stf-client
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.5.1
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Request devices from Smartphone Test Farm for adb connection - forked from
167
+ stf-client gem
168
+ test_files: []