badb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "highline"
7
+ gem "configliere"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.6.4"
15
+ # gem "rcov", ">= 0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ configliere (0.4.8)
5
+ json
6
+ git (1.2.5)
7
+ highline (1.5.2)
8
+ jeweler (1.6.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ json (1.6.5)
13
+ rake (0.9.2.2)
14
+ shoulda (2.11.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ configliere
22
+ highline
23
+ jeweler (~> 1.6.4)
24
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Zachary Pinter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,74 @@
1
+ # badb: Better Android Debug Bridge
2
+
3
+ The badb project is a wrapper command for adb that helps when working with multiple connected devices.
4
+
5
+ When you attempt to run a command with badb, it first prompts you to choose a device:
6
+
7
+ [zpinter:~]$ badb shell
8
+ 1. 028841C4437OG222
9
+ 2. 3533B6D1DFC242AF
10
+ Choose your adb device: 1
11
+ shell@android:/ $
12
+
13
+ The badb command keeps a history of the last device you chose, so subsequent commands (even in different terminals) will use the same device without prompt:
14
+
15
+ [zpinter:~]$ badb shell
16
+ shell@android:/ $
17
+
18
+ If you want to find out what the current device is, run badb current or badb list:
19
+
20
+ [zpinter:~]$ badb current
21
+ Current device is 028841C4437OG222
22
+
23
+ [zpinter:~]$ badb list
24
+ List of devices:
25
+ 028841C4437OG222 #current
26
+ 3533B6D1DFC242AF
27
+ [zpinter:~]$
28
+
29
+ As you can see, the above list of serials isn't very friendly. So, badb provides an alias command:
30
+
31
+ [zpinter:~]$ badb alias
32
+ Create an alias:
33
+ 1. 028841C4437OG222
34
+ 2. 3533B6D1DFC242AF
35
+ Choose your adb device: 1
36
+ Enter an alias for 028841C4437OG222: LG Tablet
37
+
38
+ [zpinter:~]$ badb alias
39
+ Create an alias:
40
+ 1. 028841C4437OG222 (LG Tablet)
41
+ 2. 3533B6D1DFC242AF
42
+ Choose your adb device: 2
43
+ Enter an alias for 3533B6D1DFC242AF: Nexus S 4G
44
+
45
+ [zpinter:~]$ badb list
46
+ List of devices:
47
+ 028841C4437OG222 (LG Tablet) #current
48
+ 3533B6D1DFC242AF (Nexus S 4G)
49
+ [zpinter:~]$
50
+
51
+ Finally if you want to change your current device, you can use badb choose:
52
+
53
+ [zpinter:~]$ badb choose
54
+ 1. 028841C4437OG222 (LG Tablet)
55
+ 2. 3533B6D1DFC242AF (Nexus S 4G)
56
+ Choose your adb device: 2
57
+ [zpinter:~]$ badb current
58
+ Current device is 3533B6D1DFC242AF (Nexus S 4G)
59
+
60
+ ## Contributing to badb
61
+
62
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
63
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
64
+ * Fork the project
65
+ * Start a feature/bugfix branch
66
+ * Commit and push until you are happy with your contribution
67
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
68
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
69
+
70
+ ## Copyright
71
+
72
+ Copyright (c) 2012 Zachary Pinter. See LICENSE.txt for
73
+ further details.
74
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "badb"
18
+ gem.homepage = "http://github.com/zpinter/badb"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Better Android Debug Bridge}
21
+ gem.description = %Q{Wrapper command for adb that lets you alias devices and prompts you for which device you want to connect to}
22
+ gem.email = "zpinter@gmail.com"
23
+ gem.authors = ["Zachary Pinter"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "badb #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/badb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'badb'
7
+ BADB::Runner.new.run
data/lib/badb.rb ADDED
@@ -0,0 +1,196 @@
1
+ require 'highline/import'
2
+ require 'configliere'
3
+ require 'fileutils'
4
+
5
+ module BADB
6
+ class Runner
7
+
8
+ CONFIG_FILE = File.expand_path("~/.badb_config.yaml")
9
+
10
+ def initialize
11
+ read_settings
12
+ end
13
+
14
+ def read_settings
15
+ Settings.use :config_file
16
+ Settings({
17
+ :device_history => [],
18
+ :aliases => {}
19
+ })
20
+ FileUtils.touch(CONFIG_FILE)
21
+ Settings.read(CONFIG_FILE)
22
+ end
23
+
24
+ def save_settings
25
+ Settings.save!(CONFIG_FILE)
26
+ end
27
+
28
+ def adb_path
29
+ return @adb_path if @adb_path
30
+ @adb_path = `which adb`.strip
31
+ if @adb_path.empty?
32
+ raise "Can't find your adb command. Is your path set\?"
33
+ end
34
+ @adb_path
35
+ end
36
+
37
+ def get_devices
38
+ devices = []
39
+ IO.popen("#{adb_path} devices").each_line do |line|
40
+ line = line.strip
41
+ if line =~ /^(.*)\tdevice$/
42
+ devices << $1
43
+ end
44
+ end
45
+ devices
46
+ end
47
+
48
+ def choose_device(opt={})
49
+ opt = {
50
+ :all => false,
51
+ :save_choice => true
52
+ }.merge(opt)
53
+ devices = get_devices
54
+ devices = filter_latest_device(devices) if !opt[:all]
55
+
56
+ if devices.empty?
57
+ raise "No devices attached"
58
+ elsif devices.size == 1
59
+ yield devices[0] if block_given?
60
+ else
61
+ choose do |menu|
62
+ menu.prompt = "Choose your adb device: "
63
+
64
+ devices.each do |device|
65
+ menu.choice device_label(device) do
66
+ save_choice(device) if opt[:save_choice]
67
+ yield device if block_given?
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def save_choice(device)
75
+ hist = Settings[:device_history]
76
+ hist.delete(device)
77
+ hist << device
78
+ Settings[:device_history] = hist
79
+ save_settings
80
+ end
81
+
82
+ def filter_latest_device(devices)
83
+ hist = Settings[:device_history]
84
+
85
+ latest_history_device = nil
86
+ latest_history_index = -1
87
+
88
+ devices.each do |d|
89
+ index = hist.index(d)
90
+ if index && index > latest_history_index
91
+ latest_history_index = index
92
+ latest_history_device = d
93
+ end
94
+ end
95
+
96
+ return [latest_history_device] if latest_history_device
97
+ devices
98
+ end
99
+
100
+ def current_device
101
+ devices = get_devices
102
+ devices = filter_latest_device(devices)
103
+
104
+ return devices[0] if devices.size == 1
105
+ return nil
106
+ end
107
+
108
+ def show_current_device
109
+ d = current_device
110
+
111
+ if d
112
+ puts "Current device is " + device_label(current_device)
113
+ else
114
+ puts "No current device."
115
+ end
116
+ end
117
+
118
+ def show_help
119
+ puts "badb - Better Android Debug Bridge\n\n"
120
+ puts "Usage:"
121
+ puts "badb choose - choose the current android device to map badb command to, via prompt"
122
+ puts "badb alias - add a friendly name for a specific device, via prompt"
123
+ puts "badb current - the current android device"
124
+ puts "badb list - lists android devices, with aliases, indicating the current one"
125
+ puts "badb help - this message"
126
+ puts "badb adbhelp - the original adb help command"
127
+ end
128
+
129
+ def device_label(device)
130
+ device_alias = Settings[:aliases][device]
131
+
132
+ if device_alias
133
+ "#{device} (#{device_alias})"
134
+ else
135
+ device
136
+ end
137
+ end
138
+
139
+ def create_alias
140
+ puts "Create an alias: "
141
+
142
+ choose_device(:all => true,:save_choice => false) do |device|
143
+ device_alias = ask("Enter an alias for #{device_label(device)}: ")
144
+ Settings[:aliases][device] = device_alias
145
+ save_settings
146
+ end
147
+ end
148
+
149
+ def list_devices
150
+ devices = get_devices
151
+ current = current_device
152
+
153
+ puts "List of devices: "
154
+ devices.each do |d|
155
+
156
+ if d == current_device
157
+ puts device_label(d) + " #current"
158
+ else
159
+ puts device_label(d)
160
+ end
161
+ end
162
+ end
163
+
164
+ def run
165
+ if !ARGV.empty?
166
+ if ARGV[0] == "choose"
167
+ choose_device(:all => true)
168
+ return
169
+ elsif ARGV[0] == "current"
170
+ show_current_device
171
+ return
172
+ elsif ARGV[0] == "alias"
173
+ create_alias
174
+ return
175
+ elsif ARGV[0] == "list"
176
+ list_devices
177
+ return
178
+ elsif ARGV[0] == "help"
179
+ show_help
180
+ return
181
+ elsif ARGV[0] == "adbhelp"
182
+ Kernel.exec(adb_path,"help")
183
+ return
184
+ end
185
+ end
186
+
187
+ choose_device do |device|
188
+ ENV["ANDROID_SERIAL"] = device
189
+ # p [:device, device]
190
+ # p [:cmd, adb_path, ARGV]
191
+ Kernel.exec(adb_path,*ARGV)
192
+ end
193
+ end
194
+ end
195
+ end
196
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'badb'
16
+
17
+ class Test::Unit::TestCase
18
+ end
data/test/test_badb.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBadb < Test::Unit::TestCase
4
+ # should "probably rename this file and start testing for real" do
5
+ # flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ # end
7
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: badb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Zachary Pinter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-02-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: highline
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: configliere
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: jeweler
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.6.4
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ description: Wrapper command for adb that lets you alias devices and prompts you for which device you want to connect to
71
+ email: zpinter@gmail.com
72
+ executables:
73
+ - badb
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - LICENSE.txt
78
+ - README.markdown
79
+ files:
80
+ - .document
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.markdown
85
+ - Rakefile
86
+ - VERSION
87
+ - bin/badb
88
+ - lib/badb.rb
89
+ - test/helper.rb
90
+ - test/test_badb.rb
91
+ homepage: http://github.com/zpinter/badb
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 432773671352207762
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.10
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Better Android Debug Bridge
121
+ test_files: []
122
+