emu_ctl 0.0.2 → 0.0.3
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/README.md +2 -0
- data/bin/emu_ctl +29 -17
- data/emu_ctl.gemspec +8 -7
- data/lib/emu_ctl.rb +1 -1
- data/lib/emu_ctl/adb.rb +32 -8
- data/lib/emu_ctl/{emulator.rb → ctl.rb} +9 -5
- data/lib/emu_ctl/model.rb +16 -0
- data/lib/emu_ctl/version.rb +1 -1
- data/spec/emulator_spec.rb +11 -11
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b59cd6a2d27d2888a8ed1fc00997ebda567301d8
|
4
|
+
data.tar.gz: 24e5c4b60bdffff52828952ee7151c445e118a9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ebf8e2a355c0f1528e062456aee7c79dc5684e700d3ee559bb2813a4a8abee08383ecc8be6c09b5164dda589ee3577d2f05420ce7b29170c96ff0bbcda42e75
|
7
|
+
data.tar.gz: 98f73d1cdab2b88533bbce99bdbda05b456928540ce16abe7020378e2cb59d6957599e1d38b12e6562410e3c9455f38636cc2a2b49712821f2b0c1e671cdf994
|
data/README.md
CHANGED
data/bin/emu_ctl
CHANGED
@@ -13,55 +13,67 @@ usage = "
|
|
13
13
|
Usage:
|
14
14
|
#{File.basename($0)} list prints all available emulators
|
15
15
|
#{File.basename($0)} running shows all running emulators
|
16
|
-
#{File.basename($0)} kill
|
16
|
+
#{File.basename($0)} kill (ID|all) kills the emulator with ID (see `running`) or all runnig emulators
|
17
17
|
#{File.basename($0)} launch ID runs the emulator with ID,
|
18
18
|
ID is an integer form the output of `list`
|
19
19
|
#{File.basename($0)} targets shows all possible targets and skins, will only display targets with abi
|
20
20
|
#{File.basename($0)} new ID SKIN creates a new avd with API level according to ID and skin SKIN
|
21
21
|
check `targets` for possible values (depends on installed sdk packages)
|
22
22
|
Only works for targets with default abi
|
23
|
-
#{File.basename($0)} rm ID deletes avd with ID returned in list
|
23
|
+
#{File.basename($0)} rm ID deletes avd with ID returned in list
|
24
|
+
#{File.basename($0)} force-kill sends `kill -9` to all running emulator processes, BE CAREFUL"
|
24
25
|
|
25
26
|
# command line args
|
26
27
|
if ARGV.empty?
|
27
28
|
puts "You need to specify an action"
|
28
29
|
puts "#{usage}"
|
29
|
-
exit
|
30
|
+
exit 2
|
30
31
|
end
|
31
32
|
|
32
33
|
action = ARGV.shift
|
33
34
|
case action
|
34
35
|
when 'kill'
|
35
|
-
|
36
|
+
arg = ARGV.shift
|
37
|
+
raise 'you need to specify which emulator to kill' if arg.nil?
|
38
|
+
running = emus = EmuCtl::ADB.devices
|
39
|
+
targets = arg == 'all' ? running : [ running[arg.to_i] ]
|
40
|
+
puts "trying to kill emulators: \n\t#{targets.join('\n\t')}"
|
41
|
+
targets.each{ |t| EmuCtl::ADB.kill_emu(t.qualifier)}
|
42
|
+
puts "done killing"
|
43
|
+
when 'force-kill'
|
44
|
+
warn "dont' use `force-kill` if you don't have to, it might coase android to leave some trash in /tmp/android-[user]/"
|
45
|
+
pids = EmuCtl::Ctl.running_pids
|
36
46
|
puts "found running emulators with pid: #{pids}"
|
37
|
-
EmuCtl::
|
47
|
+
EmuCtl::Ctl.kill_pids(pids)
|
38
48
|
puts "killed all emulators"
|
39
49
|
when 'list'
|
40
|
-
|
41
|
-
puts
|
50
|
+
avds = EmuCtl::Ctl.list
|
51
|
+
puts avds.map{ |o| "#{avds.index(o)} - #{o.to_s}" }.join("\n")
|
42
52
|
when 'launch'
|
43
53
|
raise "you need to specify the emulator id\n#{usage}" if ARGV.empty?
|
44
54
|
index = ARGV.shift.to_i
|
45
|
-
|
46
|
-
EmuCtl::
|
55
|
+
avd = EmuCtl::Ctl.list[index]
|
56
|
+
EmuCtl::Ctl.start(avd)
|
47
57
|
when 'targets'
|
48
|
-
targets = EmuCtl::
|
58
|
+
targets = EmuCtl::Ctl.list_targets
|
49
59
|
puts targets.map{ |o| "#{targets.index(o)} - #{o.to_s}" }.join("\n")
|
50
60
|
when 'new'
|
51
61
|
target_index = ARGV.shift.to_i
|
52
62
|
skin = ARGV.shift
|
53
63
|
raise "you need to specify target and skin" if target_index.nil? || skin.nil?
|
54
|
-
target = EmuCtl::
|
64
|
+
target = EmuCtl::Ctl.list_targets[target_index]
|
55
65
|
puts "creating new avd from #{target.id} with skin #{skin}"
|
56
|
-
EmuCtl::
|
66
|
+
EmuCtl::Ctl.create(target, skin)
|
57
67
|
when 'running'
|
58
|
-
|
68
|
+
emus = EmuCtl::ADB.devices
|
69
|
+
puts emus.map{ |o| "#{emus.index(o)} - #{o.to_s}" }.join("\n")
|
59
70
|
when 'rm'
|
60
71
|
emu_index = ARGV.shift
|
61
72
|
raise 'you need to specify the emulator id' if emu_index.nil?
|
62
|
-
|
63
|
-
puts "deleting: #{
|
64
|
-
EmuCtl::
|
73
|
+
avd = EmuCtl::Ctl.list[Integer(emu_index)]
|
74
|
+
puts "deleting: #{avd}"
|
75
|
+
EmuCtl::Ctl.delete(avd)
|
65
76
|
else
|
66
|
-
|
77
|
+
puts "unknown action #{action}\n#{usage}"
|
67
78
|
end
|
79
|
+
exit 0
|
data/emu_ctl.gemspec
CHANGED
@@ -4,13 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require "emu_ctl/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
s.platform
|
10
|
-
s.authors
|
11
|
-
s.email
|
12
|
-
s.homepage
|
13
|
-
s.summary
|
7
|
+
s.name = "emu_ctl"
|
8
|
+
s.version = EmuCtl::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Nemo Oudeis"]
|
11
|
+
s.email = ["nemo@oudeis.eu"]
|
12
|
+
s.homepage = "https://github.com/NemoOudeis/EmulatorControl"
|
13
|
+
s.summary = %q{command line tool to easily control android emulators}
|
14
|
+
s.license = 'MIT'
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/emu_ctl.rb
CHANGED
data/lib/emu_ctl/adb.rb
CHANGED
@@ -1,20 +1,44 @@
|
|
1
1
|
module EmuCtl
|
2
2
|
class ADB
|
3
|
+
def self.cli_opt(emu_qual)
|
4
|
+
"#{"-s #{emu_qual}" unless emu_qual.nil?}"
|
5
|
+
end
|
6
|
+
|
3
7
|
def self.devices
|
4
|
-
_, stdout, _ = Open3.popen3('adb devices')
|
8
|
+
_, stdout, _ = Open3.popen3('adb devices -l')
|
5
9
|
lines = []
|
6
|
-
stdout.each_line { |l| lines.push(l) }
|
7
|
-
lines.
|
10
|
+
stdout.each_line { |l| lines.push(l) if l.include?('emulator') }
|
11
|
+
lines.map{ |em| /(emulator-\d+)/.match(em)[1] }.map{ |qual| emu_info(qual) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.emu_info(emu_qual=nil)
|
15
|
+
_, stdout, _ = Open3.popen3("adb #{cli_opt(emu_qual)} shell getprop")
|
16
|
+
pattern = /\[.+\]: \[(.+)\]/
|
17
|
+
api_lvl, os_version, sdk = nil, nil, nil
|
18
|
+
stdout.each_line do |l|
|
19
|
+
api_lvl = pattern.match(l)[1] if l.include?('ro.build.version.sdk')
|
20
|
+
os_version = pattern.match(l)[1] if l.include?('ro.build.version.release')
|
21
|
+
sdk = pattern.match(l)[1] if l.include?('ro.product.name')
|
22
|
+
end
|
23
|
+
return Emulator.new(emu_qual, api_lvl, os_version, sdk)
|
8
24
|
end
|
9
25
|
|
10
|
-
def self.boot_complete?
|
11
|
-
|
26
|
+
def self.boot_complete?(emu_qual=nil)
|
27
|
+
cmd = "adb #{cli_opt(emu_qual)} shell getprop dev.bootcomplete"
|
28
|
+
_, stdout, stderr = Open3.popen3(cmd)
|
12
29
|
return stderr.gets.nil?
|
13
30
|
end
|
14
31
|
|
15
|
-
def self.unlock_emulator
|
16
|
-
|
17
|
-
system
|
32
|
+
def self.unlock_emulator(emu_qual=nil)
|
33
|
+
tag = cli_opt(emu_qual)
|
34
|
+
system "adb #{tag} shell input keyevent 82"
|
35
|
+
system "adb #{tag} shell input keyevent 4"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.kill_emu(emu_qual)
|
39
|
+
cmd = "adb #{cli_opt(emu_qual)} emu kill"
|
40
|
+
puts cmd
|
41
|
+
Open3.popen3(cmd)
|
18
42
|
end
|
19
43
|
end
|
20
44
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module EmuCtl
|
2
|
-
class
|
2
|
+
class Ctl
|
3
3
|
@@EMU_TIMEOUT = 180
|
4
4
|
|
5
5
|
def self.start(emu)
|
6
6
|
raise 'invalid name: nil' if emu.name.nil?
|
7
7
|
puts "starting emulator: #{emu}"
|
8
|
-
|
9
|
-
|
8
|
+
cmd = "emulator -no-boot-anim -avd #{emu.name} -no-snapshot-load -no-snapshot-save -no-audio -no-window -verbose &"
|
9
|
+
puts "#{cmd}"
|
10
|
+
system "#{cmd}"
|
10
11
|
starting_up = true
|
11
12
|
|
12
13
|
start = Time.now
|
14
|
+
|
13
15
|
until ADB.boot_complete?
|
14
16
|
sleep 2
|
15
17
|
ellapsed = Time.now - start
|
@@ -55,14 +57,16 @@ module EmuCtl
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def self.running_pids
|
60
|
+
warn 'deprecated: controlling emulators via pids is a bad idea'
|
58
61
|
_, stdout, _ = Open3.popen3("pgrep 'emulator'")
|
59
62
|
pids = []
|
60
63
|
stdout.each_line { |l| pids.push(l.strip) }
|
61
64
|
pids
|
62
65
|
end
|
63
66
|
|
64
|
-
def self.
|
65
|
-
|
67
|
+
def self.kill_pids(pids)
|
68
|
+
warn 'deprecated: controlling emulators via pids is a bad idea'
|
69
|
+
pids.each { |pid| system "kill -9 #{pid}" }
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
data/lib/emu_ctl/model.rb
CHANGED
@@ -38,4 +38,20 @@ module EmuCtl
|
|
38
38
|
"#{@name}"
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
class Emulator
|
43
|
+
attr_accessor(:qualifier, :api_lvl, :os_name, :sdk)
|
44
|
+
|
45
|
+
def initialize(qual, api_lvl, os_name, sdk)
|
46
|
+
@qualifier = qual
|
47
|
+
@api_lvl = api_lvl
|
48
|
+
@os_name = os_name
|
49
|
+
@sdk = sdk
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
"#{qualifier}: Running #{os_name} on API Level #{api_lvl} with sdk #{sdk}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
41
57
|
end
|
data/lib/emu_ctl/version.rb
CHANGED
data/spec/emulator_spec.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
require "emu_ctl"
|
2
2
|
|
3
|
-
RSpec.describe EmuCtl::
|
3
|
+
RSpec.describe EmuCtl::Ctl do
|
4
4
|
describe 'lists' do
|
5
5
|
it 'looks up existings avds' do
|
6
|
-
expect(EmuCtl::
|
6
|
+
expect(EmuCtl::Ctl.list).to_not be_nil
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'looks up available targets' do
|
10
|
-
expect(EmuCtl::
|
10
|
+
expect(EmuCtl::Ctl.list_targets).to_not be_nil
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'emulator creation and deletion' do
|
15
15
|
it 'creates new emulator' do
|
16
|
-
old_list = EmuCtl::
|
16
|
+
old_list = EmuCtl::Ctl.list
|
17
17
|
# only targets with default abi
|
18
|
-
target = EmuCtl::
|
18
|
+
target = EmuCtl::Ctl.list_targets.select{|t| t.abi.include?('default')}.last
|
19
19
|
puts "creating emulator for target #{target.name} and skin #{target.skins[0]}"
|
20
20
|
|
21
|
-
EmuCtl::
|
22
|
-
expect(EmuCtl::
|
21
|
+
EmuCtl::Ctl.create(target, target.skins[0])
|
22
|
+
expect(EmuCtl::Ctl.list.count).to eq(old_list.count + 1)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'deletes emulators' do
|
26
|
-
old_list = EmuCtl::
|
26
|
+
old_list = EmuCtl::Ctl.list
|
27
27
|
emu = old_list.last
|
28
28
|
puts "deleting emulator #{emu}"
|
29
|
-
EmuCtl::
|
30
|
-
expect(EmuCtl::
|
29
|
+
EmuCtl::Ctl.delete(emu)
|
30
|
+
expect(EmuCtl::Ctl.list.count).to eq(old_list.count - 1)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'looks up available targets' do
|
34
|
-
expect(EmuCtl::
|
34
|
+
expect(EmuCtl::Ctl.list_targets).to_not be_nil
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emu_ctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nemo Oudeis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- emu_ctl.gemspec
|
87
87
|
- lib/emu_ctl.rb
|
88
88
|
- lib/emu_ctl/adb.rb
|
89
|
-
- lib/emu_ctl/
|
89
|
+
- lib/emu_ctl/ctl.rb
|
90
90
|
- lib/emu_ctl/model.rb
|
91
91
|
- lib/emu_ctl/version.rb
|
92
92
|
- spec/adb_spec.rb
|
@@ -94,7 +94,8 @@ files:
|
|
94
94
|
- spec/model_spec.rb
|
95
95
|
- spec/spec_helper.rb
|
96
96
|
homepage: https://github.com/NemoOudeis/EmulatorControl
|
97
|
-
licenses:
|
97
|
+
licenses:
|
98
|
+
- MIT
|
98
99
|
metadata: {}
|
99
100
|
post_install_message: |2+
|
100
101
|
|