nadb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 989bce0af15848488e8f3cf70780e47a910a75fa
4
+ data.tar.gz: 95abe0f884e659b598d5bad3d77b2fe65055b1bd
5
+ SHA512:
6
+ metadata.gz: 6e09ddf1eca0dab4ddcf67b4f56d6c4eafadc3fb9dad2e4dded88726b4e2f883eed168ab6451ccb48c5136942307b954dfe479b55d2563b6ad59867ce1a2e021
7
+ data.tar.gz: b67c7e2c9b6cf7df53d8fb259cb18cc593127ff14271fda0a14592b218fbe2c448d3b42d2229174afe628c040838d7037e40a5368f2ecbfb9452d9e7a67dcba6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nadb.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nadb (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.6)
16
+ nadb!
17
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hamid Palo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Nadb
2
+
3
+ A nicer interface to adb.
4
+
5
+ * ``nadb -n n5`` instead of ``adb -s aja98jfao8ejfao``
6
+ * ``nadb -i 1`` instead of ``adb -s aja98jfao8ejfao``
7
+ * ``nadb --all`` insated of running the adb command on every single device
8
+
9
+ Anything else gets passed along to ``adb`` so you can use it as a straight up replacement.
10
+
11
+ ```
12
+ Usage: nadb [options] command
13
+
14
+ Options:
15
+ --all Run command on all connected devices
16
+ -n, --name NAME Name of device to run from
17
+ -i, --index INDEX The index of the target device in the adb devices output
18
+ -h, --help Display this screen
19
+ ```
20
+
21
+ ## Defining aliases
22
+
23
+ Simply create a ``~/.nadb.config`` file with contents like these:
24
+
25
+ ```
26
+ {
27
+ "aliases": {
28
+ "n5": "serial from adb output"
29
+ }
30
+ }
31
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/nadb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'Nadb'
4
+ n = Nadb::Tool.new
5
+ n.run ARGV
@@ -0,0 +1,3 @@
1
+ module Nadb
2
+ VERSION = "0.0.1"
3
+ end
data/lib/nadb.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'nadb/version'
2
+
3
+ require 'json'
4
+ require 'optparse'
5
+
6
+ module Nadb
7
+ class Tool
8
+ def initialize
9
+ @config = {}
10
+ @options = {}
11
+
12
+ load_config
13
+
14
+ @opt_parse = OptionParser.new do |opts|
15
+ opts.banner = <<eos
16
+ A nicer interface to adb.
17
+ Usage: nadb [options] command
18
+
19
+ Options:
20
+ eos
21
+ @options[:all] = false
22
+ opts.on('--all', 'Run command on all connected devices') { @options[:all] = true }
23
+
24
+ @options[:name] = nil
25
+ opts.on('-n', '--name NAME', 'Name of device to run from') { |name| @options[:name] = name }
26
+
27
+ @options[:index] = nil
28
+ opts.on('-i',
29
+ '--index INDEX',
30
+ OptionParser::DecimalInteger,
31
+ 'The index of the target device in the adb devices output') { |index| @options[:index] = index }
32
+
33
+ opts.on('-h', '--help', 'Display this screen') do
34
+ puts opts
35
+ exit
36
+ end
37
+ end
38
+ end
39
+
40
+ # Load config from the file if any exists
41
+ def load_config
42
+ path = ENV['HOME'] + '/.nadb.config'
43
+ if !File.exists?(path)
44
+ return
45
+ end
46
+
47
+ @config = JSON.parse(File.read(path))
48
+ end
49
+
50
+ def adb_path
51
+ ENV['ANDROID_HOME'] + '/platform-tools/adb'
52
+ end
53
+
54
+ # Construct an adb command
55
+ def construct_adb_command(command, device = nil)
56
+ device_specifier = device.nil? ? "" : " -s #{device}"
57
+ "#{adb_path}#{device_specifier} #{command}"
58
+ end
59
+
60
+ def get_adb_command_output(command)
61
+ full_command = construct_adb_command command
62
+ IO.popen(full_command + ' 2>&1', 'w+')
63
+ end
64
+
65
+ # Run an adb commd on specified device, optionally printing the output
66
+ def run_adb_command(command, device = nil)
67
+ full_command = construct_adb_command command, device
68
+
69
+ puts full_command
70
+ pio = IO.popen(full_command, 'w')
71
+ Process.wait(pio.pid)
72
+ end
73
+
74
+ # Get all currently connected android devices
75
+ def get_connected_devices
76
+ get_adb_command_output('devices')
77
+ .drop(1)
78
+ .map { |line| line.split[0] }
79
+ .reject { |d| d.nil? || d.empty? }
80
+ end
81
+
82
+ # Bakes fresh cookies.
83
+ def run(argv)
84
+ dup_argv = argv.dup
85
+ begin
86
+ @opt_parse.order! dup_argv
87
+ rescue OptionParser::InvalidOption => e
88
+ end
89
+
90
+ command_to_run = dup_argv.join " "
91
+
92
+ # Run on all devices
93
+ if @options[:index]
94
+ devices = get_connected_devices
95
+ device = devices[@options[:index]]
96
+ if device.nil?
97
+ raise "Requested device #{@options[:index]} but only have #{devices.length} devices connected."
98
+ end
99
+
100
+ run_adb_command command_to_run, device
101
+
102
+ return
103
+ end
104
+
105
+ # Run on all connected devices
106
+ if @options[:all]
107
+ devices = get_connected_devices
108
+ devices.each do |device|
109
+ run_adb_command command_to_run, device
110
+ end
111
+ return
112
+ end
113
+
114
+ # Just pass everything to adb as we got it
115
+ passthrough_command = argv.join " "
116
+ run_adb_command passthrough_command
117
+ end
118
+ end
119
+ end
data/nadb.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nadb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nadb"
8
+ spec.version = Nadb::VERSION
9
+ spec.authors = ["Hamid Palo"]
10
+ spec.email = ["hamid.palo@gmail.com"]
11
+ spec.summary = %q{A nicer interface for adb}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
Binary file
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nadb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hamid Palo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - hamid.palo@gmail.com
44
+ executables:
45
+ - nadb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/nadb
55
+ - lib/nadb.rb
56
+ - lib/nadb/version.rb
57
+ - nadb.gemspec
58
+ - pkg/nadb-0.0.1.gem
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A nicer interface for adb
83
+ test_files: []